From 175c6b8a75e31ba6cedab99e06c70acc69611fe7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 14 Feb 2025 08:23:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Fix=20an=20issue=20?= =?UTF-8?q?that=20break=20the=20workflow=20when=20there=20is=20nothing=20t?= =?UTF-8?q?o=20commit=20in=20`BuildDocs`=20=20(#137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request updates the reusable workflow files to handle docs generation without errors. Improvements to reusable workflows (CI.yml and workflow.yml) : * In "BuildDocs": * Added `continue-on-error: true` and changed the shell to `pwsh` for the "Commit all changes" step. Also added commands to temporarily rename the `.gitignore` file during the commit process. ## Type of change - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/workflows/CI.yml | 8 ++++++++ .github/workflows/workflow.yml | 8 ++++++++ tests/srcTestRepo/src/functions/public/completers.ps1 | 8 ++++++++ .../src/functions/public/Test-PSModuleTest.ps1 | 4 +--- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/srcTestRepo/src/functions/public/completers.ps1 diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 29cde5cc..c881f7da 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -260,10 +260,18 @@ jobs: Version: ${{ inputs.Version }} - name: Commit all changes + continue-on-error: true + shell: pwsh run: | + # Rename the gitignore file to .gitignore.bak + Rename-Item -Path '.gitignore' -NewName '.gitignore.bak' -Force + git add . git commit -m 'Update documentation' + # Restore the gitignore file + Rename-Item -Path '.gitignore.bak' -NewName '.gitignore' -Force + - name: Lint documentation uses: super-linter/super-linter/slim@latest env: diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 410439a8..24be9dff 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -267,10 +267,18 @@ jobs: Version: ${{ inputs.Version }} - name: Commit all changes + continue-on-error: true + shell: pwsh run: | + # Rename the gitignore file to .gitignore.bak + Rename-Item -Path '.gitignore' -NewName '.gitignore.bak' -Force + git add . git commit -m 'Update documentation' + # Restore the gitignore file + Rename-Item -Path '.gitignore.bak' -NewName '.gitignore' -Force + - name: Lint documentation uses: super-linter/super-linter/slim@latest env: diff --git a/tests/srcTestRepo/src/functions/public/completers.ps1 b/tests/srcTestRepo/src/functions/public/completers.ps1 new file mode 100644 index 00000000..6b1adbb7 --- /dev/null +++ b/tests/srcTestRepo/src/functions/public/completers.ps1 @@ -0,0 +1,8 @@ +Register-ArgumentCompleter -CommandName New-PSModuleTest -ParameterName Name -ScriptBlock { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + $null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters + + 'Alice', 'Bob', 'Charlie' | Where-Object { $_ -like "$wordToComplete*" } | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } +} diff --git a/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 index 4056e2f6..26be2b9b 100644 --- a/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 +++ b/tests/srcWithManifestTestRepo/src/functions/public/Test-PSModuleTest.ps1 @@ -1,5 +1,4 @@ -#SkipTest:Verbose:Just want to test that a function can have multiple skips. -function Test-PSModuleTest { +function Test-PSModuleTest { <# .SYNOPSIS Performs tests on a module. @@ -16,5 +15,4 @@ function Test-PSModuleTest { [string] $Name ) Write-Output "Hello, $Name!" - Write-Verbose 'Verbose message' -Verbose } From 44ceccb6176843860baf0cbea80e6bacf557ad47 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 14 Feb 2025 10:16:18 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=AA=B2=20[Fix]:=20Fix=20placement=20o?= =?UTF-8?q?f=20docs=20after=20copy=20(#138)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This pull request includes improvements to the `CI.yml` and `workflow.yml` reusable workflows. * Modified the `Copy-Item` command to include all files in the source directory by appending `/*` to the path. * Added a `try-catch` block around the `git add` and `git commit` commands to handle cases where there are no changes to commit, preventing errors. ## Type of change - [ ] 📖 [Docs] - [x] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas --- .github/workflows/CI.yml | 11 ++++++++--- .github/workflows/workflow.yml | 18 +++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c881f7da..db8e7728 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -266,8 +266,13 @@ jobs: # Rename the gitignore file to .gitignore.bak Rename-Item -Path '.gitignore' -NewName '.gitignore.bak' -Force - git add . - git commit -m 'Update documentation' + try { + # Add all changes to the repository + git add . + git commit -m 'Update documentation' + } catch { + Write-Host "No changes to commit" + } # Restore the gitignore file Rename-Item -Path '.gitignore.bak' -NewName '.gitignore' -Force @@ -307,7 +312,7 @@ jobs: Version: ${{ inputs.Version }} Script: | New-Item -Path "$env:GITHUB_WORKSPACE/${{ inputs.SiteOutputPath }}/docs/Functions" -ItemType Directory -Force - Copy-Item -Path "$env:GITHUB_WORKSPACE/${{ inputs.DocsOutputPath }}" -Destination "$env:GITHUB_WORKSPACE/${{ inputs.SiteOutputPath }}/docs/Functions" -Recurse -Force + Copy-Item -Path "$env:GITHUB_WORKSPACE/${{ inputs.DocsOutputPath }}/*" -Destination "$env:GITHUB_WORKSPACE/${{ inputs.SiteOutputPath }}/docs/Functions" -Recurse -Force $moduleName = [string]::IsNullOrEmpty('${{ inputs.Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ inputs.Name }}' $ModuleSourcePath = Join-Path $PWD -ChildPath '${{ inputs.Path }}' $SiteOutputPath = Join-Path $PWD -ChildPath '${{ inputs.SiteOutputPath }}' diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 24be9dff..3cbf404f 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -273,8 +273,13 @@ jobs: # Rename the gitignore file to .gitignore.bak Rename-Item -Path '.gitignore' -NewName '.gitignore.bak' -Force - git add . - git commit -m 'Update documentation' + try { + # Add all changes to the repository + git add . + git commit -m 'Update documentation' + } catch { + Write-Host "No changes to commit" + } # Restore the gitignore file Rename-Item -Path '.gitignore.bak' -NewName '.gitignore' -Force @@ -314,20 +319,19 @@ jobs: Version: ${{ inputs.Version }} Script: | New-Item -Path "$env:GITHUB_WORKSPACE/${{ inputs.SiteOutputPath }}/docs/Functions" -ItemType Directory -Force - Copy-Item -Path "$env:GITHUB_WORKSPACE/${{ inputs.DocsOutputPath }}" -Destination "$env:GITHUB_WORKSPACE/${{ inputs.SiteOutputPath }}/docs/Functions" -Recurse -Force + Copy-Item -Path "$env:GITHUB_WORKSPACE/${{ inputs.DocsOutputPath }}/*" -Destination "$env:GITHUB_WORKSPACE/${{ inputs.SiteOutputPath }}/docs/Functions" -Recurse -Force $moduleName = [string]::IsNullOrEmpty('${{ inputs.Name }}') ? $env:GITHUB_REPOSITORY_NAME : '${{ inputs.Name }}' $ModuleSourcePath = Join-Path $PWD -ChildPath '${{ inputs.Path }}' $SiteOutputPath = Join-Path $PWD -ChildPath '${{ inputs.SiteOutputPath }}' - LogGroup "Get folderstructure" { - Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Sort-Object + LogGroup "Get folder structure" { + Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Sort-Object | Format-List } $functionDocsFolder = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Functions' | Get-Item Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object { $fileName = $_.Name - $hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash - LogGroup " - [$fileName] - [$hash]" { + LogGroup " - $fileName" { Show-FileContent -Path $_ } }