From 55907605ad528e1d639b7629127d7a45d7de4d39 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 16 Feb 2025 22:02:05 +0100 Subject: [PATCH 01/44] Rename action and enhance documentation build process --- action.yml | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index a890336..12c0760 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: Build-PSModuleDocumentation (by PSModule) +name: Document-PSModule (by PSModule) description: Build documentation for a PowerShell module. author: PSModule branding: @@ -54,7 +54,7 @@ runs: name: ${{ inputs.ModuleArtifactName }} path: ${{ inputs.ModulesOutputPath }} - - name: Run Build-PSModuleDocumentation + - name: Document-PSModule uses: PSModule/GitHub-Script@v1 env: GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} @@ -77,3 +77,126 @@ runs: path: ${{ inputs.DocsOutputPath }} if-no-files-found: error retention-days: 1 + + - 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 + + 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 + + - name: Lint documentation + uses: super-linter/super-linter/slim@latest + env: + FILTER_REGEX_INCLUDE: ${{ inputs.DocsOutputPath }} + DEFAULT_BRANCH: main + DEFAULT_WORKSPACE: ${{ github.workspace }} + ENABLE_GITHUB_ACTIONS_GROUP_TITLE: true + GITHUB_TOKEN: ${{ github.token }} + RUN_LOCAL: true + VALIDATE_ALL_CODEBASE: true + VALIDATE_JSON_PRETTIER: false + VALIDATE_MARKDOWN_PRETTIER: false + VALIDATE_YAML_PRETTIER: false + VALIDATE_GITLEAKS: false + + - uses: actions/configure-pages@v5 + + - name: Install mkdoks-material + shell: pwsh + run: | + pip install mkdocs-material + pip install mkdocs-git-authors-plugin + pip install mkdocs-git-revision-date-localized-plugin + pip install mkdocs-git-committers-plugin-2 + + - name: Structure site + uses: PSModule/GitHub-Script@v1 + with: + Debug: ${{ inputs.Debug }} + Prerelease: ${{ inputs.Prerelease }} + Verbose: ${{ inputs.Verbose }} + 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 + $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 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 + LogGroup " - $fileName" { + Show-FileContent -Path $_ + } + } + + LogGroup 'Build docs - Process about topics' { + $aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About' + $aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force + $aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' } + Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru | + Rename-Item -NewName { $_.Name -replace '.txt', '.md' } + } + + LogGroup 'Build docs - Copy icon to assets' { + $assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets' + $null = New-Item -Path $assetsFolderPath -ItemType Directory -Force + $rootPath = Split-Path -Path $ModuleSourcePath -Parent + $iconPath = Join-Path -Path $rootPath -ChildPath 'icon\icon.png' + Copy-Item -Path $iconPath -Destination $assetsFolderPath -Force -Verbose + } + + LogGroup 'Build docs - Copy readme.md' { + $rootPath = Split-Path -Path $ModuleSourcePath -Parent + $readmePath = Join-Path -Path $rootPath -ChildPath 'README.md' + $readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md' + Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose + } + + LogGroup 'Build docs - Create mkdocs.yml' { + $rootPath = Split-Path -Path $ModuleSourcePath -Parent + # This should be moved to an action so that we can use a default one, and not have to copy it from the repo. + $mkdocsSourcePath = Join-Path -Path $rootPath -ChildPath 'mkdocs.yml' + $mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml' + $mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw + $mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName) + $mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER) + $mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force + Show-FileContent -Path $mkdocsTargetPath + } + + - name: Debug File system + shell: pwsh + run: | + Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse | Select-Object -ExpandProperty FullName | Sort-Object + + - name: Build mkdocs-material project + working-directory: ${{ inputs.SiteOutputPath }} + shell: pwsh + run: | + LogGroup 'Build docs - mkdocs build - content' { + Show-FileContent -Path mkdocs.yml + } + + LogGroup 'Build docs - mkdocs build' { + mkdocs build --config-file mkdocs.yml --site-dir ${{ github.workspace }}/_site + } + + - uses: actions/upload-pages-artifact@v3 From 140d9dd1505f8a7caa64446a1abd1ed248625688 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 16 Feb 2025 22:09:00 +0100 Subject: [PATCH 02/44] Enhance action.yml by adding DocsOutputPath and SiteOutputPath inputs --- action.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 12c0760..0dfaadf 100644 --- a/action.yml +++ b/action.yml @@ -17,18 +17,22 @@ inputs: description: Path to the folder where the built modules are outputted. required: false default: outputs/modules - DocsOutputPath: - description: Path to the folder where the built docs are outputted. - required: false - default: outputs/docs ModuleArtifactName: description: Name of the module artifact to upload. required: false default: module + DocsOutputPath: + description: Path to the folder where the built docs are outputted. + required: false + default: outputs/docs DocsArtifactName: description: Name of the docs artifact to upload. required: false default: docs + SiteOutputPath: + description: Path to the folder where the built site is outputted. + required: false + default: outputs/site Debug: description: Enable debug output. required: false From 486091a7127e0e70e052ce36d4cf9c27284bf89d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 16 Feb 2025 22:32:39 +0100 Subject: [PATCH 03/44] Add JSCPD validation option to action.yml --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 0dfaadf..8327a91 100644 --- a/action.yml +++ b/action.yml @@ -113,6 +113,7 @@ runs: VALIDATE_JSON_PRETTIER: false VALIDATE_MARKDOWN_PRETTIER: false VALIDATE_YAML_PRETTIER: false + VALIDATE_JSCPD: false VALIDATE_GITLEAKS: false - uses: actions/configure-pages@v5 From d9e3d1c8ed81e7482e7d1ece370a1e5b906aaeb1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 16 Feb 2025 22:37:17 +0100 Subject: [PATCH 04/44] Refactor action.yml by removing unused inputs and streamlining the documentation build process --- action.yml | 140 ----------------------------------------------------- 1 file changed, 140 deletions(-) diff --git a/action.yml b/action.yml index 8327a91..52a1ca9 100644 --- a/action.yml +++ b/action.yml @@ -25,14 +25,6 @@ inputs: description: Path to the folder where the built docs are outputted. required: false default: outputs/docs - DocsArtifactName: - description: Name of the docs artifact to upload. - required: false - default: docs - SiteOutputPath: - description: Path to the folder where the built site is outputted. - required: false - default: outputs/site Debug: description: Enable debug output. required: false @@ -73,135 +65,3 @@ runs: Script: | # Build-PSModuleDocumentation ${{ github.action_path }}\scripts\main.ps1 - - - name: Upload docs artifact - uses: actions/upload-artifact@v4 - with: - name: ${{ inputs.DocsArtifactName }} - path: ${{ inputs.DocsOutputPath }} - if-no-files-found: error - retention-days: 1 - - - 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 - - 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 - - - name: Lint documentation - uses: super-linter/super-linter/slim@latest - env: - FILTER_REGEX_INCLUDE: ${{ inputs.DocsOutputPath }} - DEFAULT_BRANCH: main - DEFAULT_WORKSPACE: ${{ github.workspace }} - ENABLE_GITHUB_ACTIONS_GROUP_TITLE: true - GITHUB_TOKEN: ${{ github.token }} - RUN_LOCAL: true - VALIDATE_ALL_CODEBASE: true - VALIDATE_JSON_PRETTIER: false - VALIDATE_MARKDOWN_PRETTIER: false - VALIDATE_YAML_PRETTIER: false - VALIDATE_JSCPD: false - VALIDATE_GITLEAKS: false - - - uses: actions/configure-pages@v5 - - - name: Install mkdoks-material - shell: pwsh - run: | - pip install mkdocs-material - pip install mkdocs-git-authors-plugin - pip install mkdocs-git-revision-date-localized-plugin - pip install mkdocs-git-committers-plugin-2 - - - name: Structure site - uses: PSModule/GitHub-Script@v1 - with: - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - 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 - $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 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 - LogGroup " - $fileName" { - Show-FileContent -Path $_ - } - } - - LogGroup 'Build docs - Process about topics' { - $aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About' - $aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force - $aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' } - Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru | - Rename-Item -NewName { $_.Name -replace '.txt', '.md' } - } - - LogGroup 'Build docs - Copy icon to assets' { - $assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets' - $null = New-Item -Path $assetsFolderPath -ItemType Directory -Force - $rootPath = Split-Path -Path $ModuleSourcePath -Parent - $iconPath = Join-Path -Path $rootPath -ChildPath 'icon\icon.png' - Copy-Item -Path $iconPath -Destination $assetsFolderPath -Force -Verbose - } - - LogGroup 'Build docs - Copy readme.md' { - $rootPath = Split-Path -Path $ModuleSourcePath -Parent - $readmePath = Join-Path -Path $rootPath -ChildPath 'README.md' - $readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md' - Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose - } - - LogGroup 'Build docs - Create mkdocs.yml' { - $rootPath = Split-Path -Path $ModuleSourcePath -Parent - # This should be moved to an action so that we can use a default one, and not have to copy it from the repo. - $mkdocsSourcePath = Join-Path -Path $rootPath -ChildPath 'mkdocs.yml' - $mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml' - $mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw - $mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName) - $mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER) - $mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force - Show-FileContent -Path $mkdocsTargetPath - } - - - name: Debug File system - shell: pwsh - run: | - Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse | Select-Object -ExpandProperty FullName | Sort-Object - - - name: Build mkdocs-material project - working-directory: ${{ inputs.SiteOutputPath }} - shell: pwsh - run: | - LogGroup 'Build docs - mkdocs build - content' { - Show-FileContent -Path mkdocs.yml - } - - LogGroup 'Build docs - mkdocs build' { - mkdocs build --config-file mkdocs.yml --site-dir ${{ github.workspace }}/_site - } - - - uses: actions/upload-pages-artifact@v3 From ede26e40bb78e0ca4fce7652feb279fc19954954 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 16 Feb 2025 22:44:57 +0100 Subject: [PATCH 05/44] Refactor action.yml by removing the ModuleArtifactName input and related steps to simplify the workflow --- action.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/action.yml b/action.yml index 52a1ca9..95c8cea 100644 --- a/action.yml +++ b/action.yml @@ -17,10 +17,6 @@ inputs: description: Path to the folder where the built modules are outputted. required: false default: outputs/modules - ModuleArtifactName: - description: Name of the module artifact to upload. - required: false - default: module DocsOutputPath: description: Path to the folder where the built docs are outputted. required: false @@ -44,12 +40,6 @@ inputs: runs: using: composite steps: - - name: Download module artifact - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.ModuleArtifactName }} - path: ${{ inputs.ModulesOutputPath }} - - name: Document-PSModule uses: PSModule/GitHub-Script@v1 env: From 5fe14db33cdb64730dca5d76ddc7fc262e2a01fb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 20 Feb 2025 09:58:57 +0100 Subject: [PATCH 06/44] Refactor module import and removal logic in PowerShell scripts to improve clarity and maintainability --- .../helpers/Build-PSModuleDocumentation.ps1 | 7 ++++- scripts/helpers/Import-PSModule.ps1 | 8 ++---- scripts/helpers/Remove-PSModule.ps1 | 28 +++++++++++++++++++ .../helpers/Resolve-PSModuleDependency.ps1 | 4 ++- 4 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 scripts/helpers/Remove-PSModule.ps1 diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index cc0bb90..aa9c89c 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -53,10 +53,15 @@ LogGroup 'Build docs - Generate markdown help' { Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) - $ModuleName | Remove-Module -Force -ErrorAction SilentlyContinue Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName Write-Host ($ModuleName | Get-Module) $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { + $fileName = $_.Name + LogGroup " - [$fileName]" { + Show-FileContent -Path $_ + } + } } LogGroup 'Build docs - Fix markdown code blocks' { diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 index f7a2e9b..75c049a 100644 --- a/scripts/helpers/Import-PSModule.ps1 +++ b/scripts/helpers/Import-PSModule.ps1 @@ -33,11 +33,7 @@ $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose Write-Host "Manifest file path: [$($manifestFile.FullName)]" -Verbose - $existingModule = Get-Module -Name $ModuleName -ListAvailable - $existingModule | Remove-Module -Force -Verbose - $existingModule.RequiredModules | ForEach-Object { $_ | Remove-Module -Force -Verbose -ErrorAction SilentlyContinue } - $existingModule.NestedModules | ForEach-Object { $_ | Remove-Module -Force -Verbose -ErrorAction SilentlyContinue } - # Get-InstalledPSResource | Where-Object Name -EQ $ModuleName | Uninstall-PSResource -SkipDependencyCheck -Verbose:$false + Remove-PSModule -Name $ModuleName Resolve-PSModuleDependency -ManifestFilePath $manifestFile Import-Module -Name $ModuleName -RequiredVersion '999.0.0' @@ -45,7 +41,7 @@ $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize Write-Host 'List commands' - Write-Host (Get-Command -Module $moduleName | Format-Table -AutoSize | Out-String) + Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) if ($ModuleName -notin $availableModules.Name) { throw 'Module not found' diff --git a/scripts/helpers/Remove-PSModule.ps1 b/scripts/helpers/Remove-PSModule.ps1 new file mode 100644 index 0000000..91e62a3 --- /dev/null +++ b/scripts/helpers/Remove-PSModule.ps1 @@ -0,0 +1,28 @@ +filter Remove-PSModule { + <# + .SYNOPSIS + Removes and uninstalls a PowerShell module. + + + .EXAMPLE + Remove-PSModule -ModuleName 'Utilities' + + Removes a module 'Utilities' from the session then from the system. + #> + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidUsingWriteHost', '', Scope = 'Function', + Justification = 'Want to just write to the console, not the pipeline.' + )] + [CmdletBinding(SupportsShouldProcess)] + param( + # Name of the module. + [Parameter(Mandatory, ValueFromPipeline)] + [string] $Name + ) + + if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { + Write-Host "Removing module [$Name]" + Get-Module -Name $Name -ListAvailable | Remove-Module -Force + Get-InstalledPSResource -Name $Name | Uninstall-PSResource -SkipDependencyCheck + } +} diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 14721f8..8b2fb30 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -49,9 +49,11 @@ $installParams.Force = $true $installParams.Verbose = $false - Write-Host "[$($installParams.Name)] - Installing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' + Write-Host "[$($installParams.Name)] - Uninstalling module" + Remove-PSModule -Name $installParams.Name + Write-Host "[$($installParams.Name)] - Installing module" Retry -Count 5 -Delay 10 { Install-Module @installParams -AllowPrerelease:$false } From abcaf678566cca05e68a016852cd25f320ab54eb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:06:44 +0100 Subject: [PATCH 07/44] Add initial implementation of PSModule with supporting files and configurations --- .github/workflows/Action-Test.yml | 6 ++---- action.yml | 10 ---------- .../outputs/modules/PSModuleTest/PSModuleTest.psd1 | 0 .../outputs/modules/PSModuleTest/PSModuleTest.psm1 | 0 .../modules/PSModuleTest/assemblies/LsonLib.dll | Bin .../outputs/modules/PSModuleTest/data/Config.psd1 | 0 .../outputs/modules/PSModuleTest/data/Settings.psd1 | 0 .../PSModuleTest/formats/CultureInfo.Format.ps1xml | 0 .../PSModuleTest/formats/Mygciview.Format.ps1xml | 0 .../modules/PSModuleTest/modules/OtherPSModule.psm1 | 0 .../outputs/modules/PSModuleTest/scripts/loader.ps1 | 0 .../PSModuleTest/types/DirectoryInfo.Types.ps1xml | 0 .../PSModuleTest/types/FileInfo.Types.ps1xml | 0 tests/{ => srcTestRepo}/src/assemblies/LsonLib.dll | Bin .../src/classes/private/SecretWriter.ps1 | 0 tests/{ => srcTestRepo}/src/classes/public/Book.ps1 | 0 tests/{ => srcTestRepo}/src/data/Config.psd1 | 0 tests/{ => srcTestRepo}/src/data/Settings.psd1 | 0 tests/{ => srcTestRepo}/src/finally.ps1 | 0 .../src/formats/CultureInfo.Format.ps1xml | 0 .../src/formats/Mygciview.Format.ps1xml | 0 .../src/functions/private/Get-InternalPSModule.ps1 | 0 .../src/functions/private/Set-InternalPSModule.ps1 | 0 .../functions/public/PSModule/Get-PSModuleTest.ps1 | 0 .../functions/public/PSModule/New-PSModuleTest.ps1 | 0 .../src/functions/public/PSModule/PSModule.md | 0 .../public/SomethingElse/Set-PSModuleTest.ps1 | 0 .../functions/public/SomethingElse/SomethingElse.md | 0 .../src/functions/public/Test-PSModuleTest.ps1 | 0 tests/{ => srcTestRepo}/src/header.ps1 | 0 tests/{ => srcTestRepo}/src/init/initializer.ps1 | 0 .../src/modules/OtherPSModule.psm1 | 0 tests/{ => srcTestRepo}/src/scripts/loader.ps1 | 0 .../src/types/DirectoryInfo.Types.ps1xml | 0 .../src/types/FileInfo.Types.ps1xml | 0 .../src/variables/private/PrivateVariables.ps1 | 0 .../src/variables/public/Moons.ps1 | 0 .../src/variables/public/Planets.ps1 | 0 .../src/variables/public/SolarSystems.ps1 | 0 39 files changed, 2 insertions(+), 14 deletions(-) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/PSModuleTest.psd1 (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/PSModuleTest.psm1 (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/assemblies/LsonLib.dll (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/data/Config.psd1 (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/data/Settings.psd1 (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/scripts/loader.ps1 (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/src/assemblies/LsonLib.dll (100%) rename tests/{ => srcTestRepo}/src/classes/private/SecretWriter.ps1 (100%) rename tests/{ => srcTestRepo}/src/classes/public/Book.ps1 (100%) rename tests/{ => srcTestRepo}/src/data/Config.psd1 (100%) rename tests/{ => srcTestRepo}/src/data/Settings.psd1 (100%) rename tests/{ => srcTestRepo}/src/finally.ps1 (100%) rename tests/{ => srcTestRepo}/src/formats/CultureInfo.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/src/formats/Mygciview.Format.ps1xml (100%) rename tests/{ => srcTestRepo}/src/functions/private/Get-InternalPSModule.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/private/Set-InternalPSModule.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/public/PSModule/Get-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/public/PSModule/New-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/public/PSModule/PSModule.md (100%) rename tests/{ => srcTestRepo}/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/functions/public/SomethingElse/SomethingElse.md (100%) rename tests/{ => srcTestRepo}/src/functions/public/Test-PSModuleTest.ps1 (100%) rename tests/{ => srcTestRepo}/src/header.ps1 (100%) rename tests/{ => srcTestRepo}/src/init/initializer.ps1 (100%) rename tests/{ => srcTestRepo}/src/modules/OtherPSModule.psm1 (100%) rename tests/{ => srcTestRepo}/src/scripts/loader.ps1 (100%) rename tests/{ => srcTestRepo}/src/types/DirectoryInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/src/types/FileInfo.Types.ps1xml (100%) rename tests/{ => srcTestRepo}/src/variables/private/PrivateVariables.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/Moons.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/Planets.ps1 (100%) rename tests/{ => srcTestRepo}/src/variables/public/SolarSystems.ps1 (100%) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index ae765ba..ba23c83 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -32,7 +32,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: module - path: tests/outputs/modules + path: tests/srcTestRepo/outputs/module if-no-files-found: error retention-days: 1 @@ -40,6 +40,4 @@ jobs: uses: ./ with: Name: PSModuleTest - Path: tests/src - ModulesOutputPath: tests/outputs/modules - DocsOutputPath: tests/outputs/docs + Path: tests/srcTestRepo diff --git a/action.yml b/action.yml index 95c8cea..7b4fdea 100644 --- a/action.yml +++ b/action.yml @@ -13,14 +13,6 @@ inputs: description: Path to the folder where the modules are located. required: false default: src - ModulesOutputPath: - description: Path to the folder where the built modules are outputted. - required: false - default: outputs/modules - DocsOutputPath: - description: Path to the folder where the built docs are outputted. - required: false - default: outputs/docs Debug: description: Enable debug output. required: false @@ -45,8 +37,6 @@ runs: env: GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }} - GITHUB_ACTION_INPUT_ModulesOutputPath: ${{ inputs.ModulesOutputPath }} - GITHUB_ACTION_INPUT_DocsOutputPath: ${{ inputs.DocsOutputPath }} with: Debug: ${{ inputs.Debug }} Prerelease: ${{ inputs.Prerelease }} diff --git a/tests/outputs/modules/PSModuleTest/PSModuleTest.psd1 b/tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/PSModuleTest.psd1 rename to tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 diff --git a/tests/outputs/modules/PSModuleTest/PSModuleTest.psm1 b/tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/PSModuleTest.psm1 rename to tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 diff --git a/tests/outputs/modules/PSModuleTest/assemblies/LsonLib.dll b/tests/srcTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll similarity index 100% rename from tests/outputs/modules/PSModuleTest/assemblies/LsonLib.dll rename to tests/srcTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll diff --git a/tests/outputs/modules/PSModuleTest/data/Config.psd1 b/tests/srcTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/data/Config.psd1 rename to tests/srcTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 diff --git a/tests/outputs/modules/PSModuleTest/data/Settings.psd1 b/tests/srcTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/data/Settings.psd1 rename to tests/srcTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 diff --git a/tests/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml b/tests/srcTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml rename to tests/srcTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml diff --git a/tests/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml b/tests/srcTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml rename to tests/srcTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml diff --git a/tests/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 b/tests/srcTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 rename to tests/srcTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 diff --git a/tests/outputs/modules/PSModuleTest/scripts/loader.ps1 b/tests/srcTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 similarity index 100% rename from tests/outputs/modules/PSModuleTest/scripts/loader.ps1 rename to tests/srcTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 diff --git a/tests/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml b/tests/srcTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml rename to tests/srcTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml diff --git a/tests/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml b/tests/srcTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml rename to tests/srcTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml diff --git a/tests/src/assemblies/LsonLib.dll b/tests/srcTestRepo/src/assemblies/LsonLib.dll similarity index 100% rename from tests/src/assemblies/LsonLib.dll rename to tests/srcTestRepo/src/assemblies/LsonLib.dll diff --git a/tests/src/classes/private/SecretWriter.ps1 b/tests/srcTestRepo/src/classes/private/SecretWriter.ps1 similarity index 100% rename from tests/src/classes/private/SecretWriter.ps1 rename to tests/srcTestRepo/src/classes/private/SecretWriter.ps1 diff --git a/tests/src/classes/public/Book.ps1 b/tests/srcTestRepo/src/classes/public/Book.ps1 similarity index 100% rename from tests/src/classes/public/Book.ps1 rename to tests/srcTestRepo/src/classes/public/Book.ps1 diff --git a/tests/src/data/Config.psd1 b/tests/srcTestRepo/src/data/Config.psd1 similarity index 100% rename from tests/src/data/Config.psd1 rename to tests/srcTestRepo/src/data/Config.psd1 diff --git a/tests/src/data/Settings.psd1 b/tests/srcTestRepo/src/data/Settings.psd1 similarity index 100% rename from tests/src/data/Settings.psd1 rename to tests/srcTestRepo/src/data/Settings.psd1 diff --git a/tests/src/finally.ps1 b/tests/srcTestRepo/src/finally.ps1 similarity index 100% rename from tests/src/finally.ps1 rename to tests/srcTestRepo/src/finally.ps1 diff --git a/tests/src/formats/CultureInfo.Format.ps1xml b/tests/srcTestRepo/src/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/src/formats/CultureInfo.Format.ps1xml rename to tests/srcTestRepo/src/formats/CultureInfo.Format.ps1xml diff --git a/tests/src/formats/Mygciview.Format.ps1xml b/tests/srcTestRepo/src/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/src/formats/Mygciview.Format.ps1xml rename to tests/srcTestRepo/src/formats/Mygciview.Format.ps1xml diff --git a/tests/src/functions/private/Get-InternalPSModule.ps1 b/tests/srcTestRepo/src/functions/private/Get-InternalPSModule.ps1 similarity index 100% rename from tests/src/functions/private/Get-InternalPSModule.ps1 rename to tests/srcTestRepo/src/functions/private/Get-InternalPSModule.ps1 diff --git a/tests/src/functions/private/Set-InternalPSModule.ps1 b/tests/srcTestRepo/src/functions/private/Set-InternalPSModule.ps1 similarity index 100% rename from tests/src/functions/private/Set-InternalPSModule.ps1 rename to tests/srcTestRepo/src/functions/private/Set-InternalPSModule.ps1 diff --git a/tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/PSModule/Get-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/PSModule/Get-PSModuleTest.ps1 diff --git a/tests/src/functions/public/PSModule/New-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/PSModule/New-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/PSModule/New-PSModuleTest.ps1 diff --git a/tests/src/functions/public/PSModule/PSModule.md b/tests/srcTestRepo/src/functions/public/PSModule/PSModule.md similarity index 100% rename from tests/src/functions/public/PSModule/PSModule.md rename to tests/srcTestRepo/src/functions/public/PSModule/PSModule.md diff --git a/tests/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 diff --git a/tests/src/functions/public/SomethingElse/SomethingElse.md b/tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md similarity index 100% rename from tests/src/functions/public/SomethingElse/SomethingElse.md rename to tests/srcTestRepo/src/functions/public/SomethingElse/SomethingElse.md diff --git a/tests/src/functions/public/Test-PSModuleTest.ps1 b/tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 similarity index 100% rename from tests/src/functions/public/Test-PSModuleTest.ps1 rename to tests/srcTestRepo/src/functions/public/Test-PSModuleTest.ps1 diff --git a/tests/src/header.ps1 b/tests/srcTestRepo/src/header.ps1 similarity index 100% rename from tests/src/header.ps1 rename to tests/srcTestRepo/src/header.ps1 diff --git a/tests/src/init/initializer.ps1 b/tests/srcTestRepo/src/init/initializer.ps1 similarity index 100% rename from tests/src/init/initializer.ps1 rename to tests/srcTestRepo/src/init/initializer.ps1 diff --git a/tests/src/modules/OtherPSModule.psm1 b/tests/srcTestRepo/src/modules/OtherPSModule.psm1 similarity index 100% rename from tests/src/modules/OtherPSModule.psm1 rename to tests/srcTestRepo/src/modules/OtherPSModule.psm1 diff --git a/tests/src/scripts/loader.ps1 b/tests/srcTestRepo/src/scripts/loader.ps1 similarity index 100% rename from tests/src/scripts/loader.ps1 rename to tests/srcTestRepo/src/scripts/loader.ps1 diff --git a/tests/src/types/DirectoryInfo.Types.ps1xml b/tests/srcTestRepo/src/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/src/types/DirectoryInfo.Types.ps1xml rename to tests/srcTestRepo/src/types/DirectoryInfo.Types.ps1xml diff --git a/tests/src/types/FileInfo.Types.ps1xml b/tests/srcTestRepo/src/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/src/types/FileInfo.Types.ps1xml rename to tests/srcTestRepo/src/types/FileInfo.Types.ps1xml diff --git a/tests/src/variables/private/PrivateVariables.ps1 b/tests/srcTestRepo/src/variables/private/PrivateVariables.ps1 similarity index 100% rename from tests/src/variables/private/PrivateVariables.ps1 rename to tests/srcTestRepo/src/variables/private/PrivateVariables.ps1 diff --git a/tests/src/variables/public/Moons.ps1 b/tests/srcTestRepo/src/variables/public/Moons.ps1 similarity index 100% rename from tests/src/variables/public/Moons.ps1 rename to tests/srcTestRepo/src/variables/public/Moons.ps1 diff --git a/tests/src/variables/public/Planets.ps1 b/tests/srcTestRepo/src/variables/public/Planets.ps1 similarity index 100% rename from tests/src/variables/public/Planets.ps1 rename to tests/srcTestRepo/src/variables/public/Planets.ps1 diff --git a/tests/src/variables/public/SolarSystems.ps1 b/tests/srcTestRepo/src/variables/public/SolarSystems.ps1 similarity index 100% rename from tests/src/variables/public/SolarSystems.ps1 rename to tests/srcTestRepo/src/variables/public/SolarSystems.ps1 From 511d28869d3c56456a5fd58d3f3d58d0eac42e6c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:11:13 +0100 Subject: [PATCH 08/44] Add configuration and type definition files for PSModuleTest; remove obsolete files --- .../PSModuleTest/PSModuleTest.psd1 | 0 .../PSModuleTest/PSModuleTest.psm1 | 0 .../PSModuleTest/assemblies/LsonLib.dll | Bin .../PSModuleTest/data/Config.psd1 | 0 .../PSModuleTest/data/Settings.psd1 | 0 .../PSModuleTest/formats/CultureInfo.Format.ps1xml | 0 .../PSModuleTest/formats/Mygciview.Format.ps1xml | 0 .../PSModuleTest/modules/OtherPSModule.psm1 | 0 .../PSModuleTest/scripts/loader.ps1 | 0 .../PSModuleTest/types/DirectoryInfo.Types.ps1xml | 0 .../PSModuleTest/types/FileInfo.Types.ps1xml | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/PSModuleTest.psd1 (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/PSModuleTest.psm1 (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/assemblies/LsonLib.dll (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/data/Config.psd1 (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/data/Settings.psd1 (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/formats/CultureInfo.Format.ps1xml (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/formats/Mygciview.Format.ps1xml (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/modules/OtherPSModule.psm1 (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/scripts/loader.ps1 (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/types/DirectoryInfo.Types.ps1xml (100%) rename tests/srcTestRepo/outputs/{modules => module}/PSModuleTest/types/FileInfo.Types.ps1xml (100%) diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 b/tests/srcTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psd1 rename to tests/srcTestRepo/outputs/module/PSModuleTest/PSModuleTest.psd1 diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 b/tests/srcTestRepo/outputs/module/PSModuleTest/PSModuleTest.psm1 similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/PSModuleTest.psm1 rename to tests/srcTestRepo/outputs/module/PSModuleTest/PSModuleTest.psm1 diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll b/tests/srcTestRepo/outputs/module/PSModuleTest/assemblies/LsonLib.dll similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/assemblies/LsonLib.dll rename to tests/srcTestRepo/outputs/module/PSModuleTest/assemblies/LsonLib.dll diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 b/tests/srcTestRepo/outputs/module/PSModuleTest/data/Config.psd1 similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/data/Config.psd1 rename to tests/srcTestRepo/outputs/module/PSModuleTest/data/Config.psd1 diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 b/tests/srcTestRepo/outputs/module/PSModuleTest/data/Settings.psd1 similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/data/Settings.psd1 rename to tests/srcTestRepo/outputs/module/PSModuleTest/data/Settings.psd1 diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml b/tests/srcTestRepo/outputs/module/PSModuleTest/formats/CultureInfo.Format.ps1xml similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/formats/CultureInfo.Format.ps1xml rename to tests/srcTestRepo/outputs/module/PSModuleTest/formats/CultureInfo.Format.ps1xml diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml b/tests/srcTestRepo/outputs/module/PSModuleTest/formats/Mygciview.Format.ps1xml similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/formats/Mygciview.Format.ps1xml rename to tests/srcTestRepo/outputs/module/PSModuleTest/formats/Mygciview.Format.ps1xml diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 b/tests/srcTestRepo/outputs/module/PSModuleTest/modules/OtherPSModule.psm1 similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/modules/OtherPSModule.psm1 rename to tests/srcTestRepo/outputs/module/PSModuleTest/modules/OtherPSModule.psm1 diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 b/tests/srcTestRepo/outputs/module/PSModuleTest/scripts/loader.ps1 similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/scripts/loader.ps1 rename to tests/srcTestRepo/outputs/module/PSModuleTest/scripts/loader.ps1 diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml b/tests/srcTestRepo/outputs/module/PSModuleTest/types/DirectoryInfo.Types.ps1xml similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/types/DirectoryInfo.Types.ps1xml rename to tests/srcTestRepo/outputs/module/PSModuleTest/types/DirectoryInfo.Types.ps1xml diff --git a/tests/srcTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml b/tests/srcTestRepo/outputs/module/PSModuleTest/types/FileInfo.Types.ps1xml similarity index 100% rename from tests/srcTestRepo/outputs/modules/PSModuleTest/types/FileInfo.Types.ps1xml rename to tests/srcTestRepo/outputs/module/PSModuleTest/types/FileInfo.Types.ps1xml From ebc8549d3b9543b9e39705ed5b49f8de272171e8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:14:30 +0100 Subject: [PATCH 09/44] Refactor main.ps1 to streamline module source and output path definitions for improved clarity --- scripts/main.ps1 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 37d9e92..e2ea1e7 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -19,18 +19,14 @@ LogGroup 'Loading inputs' { $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name Write-Host "Module name: [$moduleName]" - $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path/$moduleName - if (-not (Test-Path -Path $moduleSourceFolderPath)) { - $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path - } - Write-Host "Source module path: [$moduleSourceFolderPath]" + $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path/src if (-not (Test-Path -Path $moduleSourceFolderPath)) { throw "Module path [$moduleSourceFolderPath] does not exist." } - $modulesOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_ModulesOutputPath - Write-Host "Modules output path: [$modulesOutputFolderPath]" - $docsOutputFolderPath = Join-Path $env:GITHUB_WORKSPACE $env:GITHUB_ACTION_INPUT_DocsOutputPath + $modulesOutputFolderPath = Join-Path $env:GITHUB_ACTION_INPUT_Path -ChildPath 'outputs/module' + Write-Host "Module output path: [$modulesOutputFolderPath]" + $docsOutputFolderPath = Join-Path $env:GITHUB_ACTION_INPUT_Path -ChildPath 'outputs/docs' Write-Host "Docs output path: [$docsOutputFolderPath]" } From 62cfad3ee479a1f1c99794c308ce892ba5c8874a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:20:13 +0100 Subject: [PATCH 10/44] Refactor main.ps1 to use Resolve-Path for module source and output folder paths for improved reliability --- scripts/main.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index e2ea1e7..4d27377 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -19,14 +19,14 @@ LogGroup 'Loading inputs' { $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name Write-Host "Module name: [$moduleName]" - $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path/src + $moduleSourceFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/src" | Select-Object -ExpandProperty Path if (-not (Test-Path -Path $moduleSourceFolderPath)) { throw "Module path [$moduleSourceFolderPath] does not exist." } - $modulesOutputFolderPath = Join-Path $env:GITHUB_ACTION_INPUT_Path -ChildPath 'outputs/module' + $modulesOutputFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/outputs/module" | Select-Object -ExpandProperty Path Write-Host "Module output path: [$modulesOutputFolderPath]" - $docsOutputFolderPath = Join-Path $env:GITHUB_ACTION_INPUT_Path -ChildPath 'outputs/docs' + $docsOutputFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/outputs/docs" | Select-Object -ExpandProperty Path Write-Host "Docs output path: [$docsOutputFolderPath]" } From 6ead2178ae227c09d40a41ef2bd7750a5c5f155b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:27:33 +0100 Subject: [PATCH 11/44] Refactor main.ps1 to use Join-Path for constructing folder paths, enhancing readability and maintainability --- scripts/main.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 4d27377..b0203f3 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -19,14 +19,14 @@ LogGroup 'Loading inputs' { $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name Write-Host "Module name: [$moduleName]" - $moduleSourceFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/src" | Select-Object -ExpandProperty Path + $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'src' if (-not (Test-Path -Path $moduleSourceFolderPath)) { throw "Module path [$moduleSourceFolderPath] does not exist." } - $modulesOutputFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/outputs/module" | Select-Object -ExpandProperty Path + $modulesOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/module' Write-Host "Module output path: [$modulesOutputFolderPath]" - $docsOutputFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/outputs/docs" | Select-Object -ExpandProperty Path + $docsOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/docs' Write-Host "Docs output path: [$docsOutputFolderPath]" } From 593f698ef676d0cd031f019a1ff3a271aed7db08 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:30:59 +0100 Subject: [PATCH 12/44] Fix Remove-PSModule.ps1 to use Get-PSResource instead of Get-InstalledPSResource for improved accuracy in module removal --- scripts/helpers/Remove-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Remove-PSModule.ps1 b/scripts/helpers/Remove-PSModule.ps1 index 91e62a3..fcbce61 100644 --- a/scripts/helpers/Remove-PSModule.ps1 +++ b/scripts/helpers/Remove-PSModule.ps1 @@ -23,6 +23,6 @@ if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { Write-Host "Removing module [$Name]" Get-Module -Name $Name -ListAvailable | Remove-Module -Force - Get-InstalledPSResource -Name $Name | Uninstall-PSResource -SkipDependencyCheck + Get-PSResource -Name $Name | Uninstall-PSResource -SkipDependencyCheck } } From 71cb0720ec9b0d8493c8336ba9c7458250721b65 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 13:40:18 +0100 Subject: [PATCH 13/44] Enhance Remove-PSModule.ps1 to improve module and command removal process with detailed logging and accurate uninstallation --- scripts/helpers/Remove-PSModule.ps1 | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/helpers/Remove-PSModule.ps1 b/scripts/helpers/Remove-PSModule.ps1 index fcbce61..749765e 100644 --- a/scripts/helpers/Remove-PSModule.ps1 +++ b/scripts/helpers/Remove-PSModule.ps1 @@ -21,8 +21,25 @@ ) if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { - Write-Host "Removing module [$Name]" - Get-Module -Name $Name -ListAvailable | Remove-Module -Force - Get-PSResource -Name $Name | Uninstall-PSResource -SkipDependencyCheck + Write-Host "[$Name] - Remove module" + $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } + Write-Host " - Found [$($importedModule.Count)] modules to remove" + foreach ($module in $importedModule) { + Write-Host " - Removing module [$($module.Name)]" + $module | Remove-Module -Force + } + $commands = Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } + Write-Host " - Found [$($commands.Count)] commands to remove" + foreach ($command in $commands) { + Write-Host " - Removing command [$($command.Name)]" + $command | Remove-Item -Force + } + $installedModule = Get-InstalledPSResource | Where-Object { $_.Name -eq $Name } + Write-Host " - Found [$($installedModule.Count)] installed modules to remove" + foreach ($module in $installedModule) { + Write-Host " - Uninstalling module [$($module.Name)]" + $module | Uninstall-PSResource -SkipDependencyCheck + } + Get-Command -Module $Name | Format-Table -AutoSize } } From dfc63755d638a486143098e2c7989694ca7e2235 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 14:33:07 +0100 Subject: [PATCH 14/44] Update action.yml and main.ps1 to clarify module path input and enhance path resolution for improved reliability --- action.yml | 4 ++-- scripts/main.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 7b4fdea..093441d 100644 --- a/action.yml +++ b/action.yml @@ -10,9 +10,9 @@ inputs: description: Name of the module to process. required: false Path: - description: Path to the folder where the modules are located. + description: The path to the root of the repo. required: false - default: src + default: ${{ github.workspace }} Debug: description: Enable debug output. required: false diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b0203f3..c127da8 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -19,7 +19,7 @@ LogGroup 'Loading inputs' { $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name Write-Host "Module name: [$moduleName]" - $moduleSourceFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'src' + $moduleSourceFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/src" if (-not (Test-Path -Path $moduleSourceFolderPath)) { throw "Module path [$moduleSourceFolderPath] does not exist." } From 9fbde3198571abd445bb9670fedfdc15a805a459 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Mon, 24 Feb 2025 16:48:19 +0100 Subject: [PATCH 15/44] Add logging for module source and output paths in main.ps1 for better visibility --- scripts/main.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index c127da8..30e9f15 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -23,6 +23,7 @@ LogGroup 'Loading inputs' { if (-not (Test-Path -Path $moduleSourceFolderPath)) { throw "Module path [$moduleSourceFolderPath] does not exist." } + Write-Host "Module source path: [$moduleSourceFolderPath]" $modulesOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/module' Write-Host "Module output path: [$modulesOutputFolderPath]" From 87bc22e32820bb25df32df37b471173d565ad3d0 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 22:43:00 +0100 Subject: [PATCH 16/44] Refactor scripts to improve readability and maintainability; add Add-PSModulePath and Show-FileContent functions --- .github/workflows/Action-Test.yml | 3 - scripts/helpers/Add-PSModulePath.ps1 | 29 ++++ .../helpers/Build-PSModuleDocumentation.ps1 | 155 ++++++++---------- scripts/helpers/Import-PSModule.ps1 | 34 ++-- scripts/helpers/Remove-PSModule.ps1 | 1 - .../helpers/Resolve-PSModuleDependency.ps1 | 58 ++++--- scripts/helpers/Show-FileContent.ps1 | 32 ++++ scripts/main.ps1 | 37 ++--- 8 files changed, 200 insertions(+), 149 deletions(-) create mode 100644 scripts/helpers/Add-PSModulePath.ps1 create mode 100644 scripts/helpers/Show-FileContent.ps1 diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index ba23c83..810f8c3 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -25,9 +25,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Upload module artifact uses: actions/upload-artifact@v4 with: diff --git a/scripts/helpers/Add-PSModulePath.ps1 b/scripts/helpers/Add-PSModulePath.ps1 new file mode 100644 index 0000000..f5abf04 --- /dev/null +++ b/scripts/helpers/Add-PSModulePath.ps1 @@ -0,0 +1,29 @@ +function Add-PSModulePath { + <# + .SYNOPSIS + Adds a path to the PSModulePath environment variable. + + .DESCRIPTION + Adds a path to the PSModulePath environment variable. + For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. + + .EXAMPLE + Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' + + Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. + #> + [CmdletBinding()] + param( + # Path to the folder where the module source code is located. + [Parameter(Mandatory)] + [string] $Path + ) + $PSModulePathSeparator = [System.IO.Path]::PathSeparator + + $env:PSModulePath += "$PSModulePathSeparator$Path" + + Write-Verbose 'PSModulePath:' + $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { + Write-Verbose " - [$_]" + } +} diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index aa9c89c..950615a 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -7,16 +7,10 @@ Builds a module. #> [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSReviewUnusedParameter', '', Scope = 'Function', - Justification = 'LogGroup - Scoping affects the variables line of sight.' - )] [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' )] - #Requires -Modules GitHub - #Requires -Modules Utilities param( # Name of the module. [Parameter(Mandatory)] @@ -35,100 +29,93 @@ [string] $DocsOutputFolderPath ) - LogGroup "Documenting module [$ModuleName]" { - Write-Host "Source path: [$ModuleSourceFolderPath]" - if (-not (Test-Path -Path $ModuleSourceFolderPath)) { - Write-Error "Source folder not found at [$ModuleSourceFolderPath]" - exit 1 - } - $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath - Write-Host "Module source folder: [$moduleSourceFolder]" + Write-Host "::group::Documenting module [$ModuleName]" + Write-Host "Source path: [$ModuleSourceFolderPath]" + if (-not (Test-Path -Path $ModuleSourceFolderPath)) { + Write-Error "Source folder not found at [$ModuleSourceFolderPath]" + exit 1 + } + $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath + Write-Host "Module source folder: [$moduleSourceFolder]" - $moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force - Write-Host "Module output folder: [$moduleOutputFolder]" + $moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force + Write-Host "Module output folder: [$moduleOutputFolder]" - $docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force - Write-Host "Docs output folder: [$docsOutputFolder]" - } + $docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force + Write-Host "Docs output folder: [$docsOutputFolder]" - LogGroup 'Build docs - Generate markdown help' { - Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) - Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName - Write-Host ($ModuleName | Get-Module) - $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { - $fileName = $_.Name - LogGroup " - [$fileName]" { - Show-FileContent -Path $_ - } - } + Write-Host '::group::Build docs - Generate markdown help' + Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) + Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName + Write-Host ($ModuleName | Get-Module) + $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { + $fileName = $_.Name + Write-Host "::group:: - [$fileName]" + Show-FileContent -Path $_ } - LogGroup 'Build docs - Fix markdown code blocks' { - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { - $content = Get-Content -Path $_.FullName - $fixedOpening = $false - $newContent = @() - foreach ($line in $content) { - if ($line -match '^```$' -and -not $fixedOpening) { - $line = $line -replace '^```$', '```powershell' - $fixedOpening = $true - } elseif ($line -match '^```.+$') { - $fixedOpening = $true - } elseif ($line -match '^```$') { - $fixedOpening = $false - } - $newContent += $line + Write-Host '::group::Build docs - Fix markdown code blocks' + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { + $content = Get-Content -Path $_.FullName + $fixedOpening = $false + $newContent = @() + foreach ($line in $content) { + if ($line -match '^```$' -and -not $fixedOpening) { + $line = $line -replace '^```$', '```powershell' + $fixedOpening = $true + } elseif ($line -match '^```.+$') { + $fixedOpening = $true + } elseif ($line -match '^```$') { + $fixedOpening = $false } - $newContent | Set-Content -Path $_.FullName + $newContent += $line } + $newContent | Set-Content -Path $_.FullName } - LogGroup 'Build docs - Fix markdown escape characters' { - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { - $content = Get-Content -Path $_.FullName -Raw - $content = $content -replace '\\`', '`' - $content = $content -replace '\\\[', '[' - $content = $content -replace '\\\]', ']' - $content = $content -replace '\\\<', '<' - $content = $content -replace '\\\>', '>' - $content = $content -replace '\\\\', '\' - $content | Set-Content -Path $_.FullName - } + Write-Host '::group::Build docs - Fix markdown escape characters' + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { + $content = Get-Content -Path $_.FullName -Raw + $content = $content -replace '\\`', '`' + $content = $content -replace '\\\[', '[' + $content = $content -replace '\\\]', ']' + $content = $content -replace '\\\<', '<' + $content = $content -replace '\\\>', '>' + $content = $content -replace '\\\\', '\' + $content | Set-Content -Path $_.FullName } - LogGroup 'Build docs - Structure markdown files to match source files' { - $PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item - Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { - $file = $_ - Write-Host "Processing: $file" + Write-Host '::group::Build docs - Structure markdown files to match source files' + $PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item + Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { + $file = $_ + Write-Host "Processing: $file" - # find the source code file that matches the markdown file - $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } - Write-Host "Found script path: $scriptPath" - $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') - Write-Host "Doc file path: $docsFilePath" - $docsFolderPath = Split-Path -Path $docsFilePath -Parent - New-Item -Path $docsFolderPath -ItemType Directory -Force - Move-Item -Path $file.FullName -Destination $docsFilePath -Force - } - # Get the MD files that are in the public functions folder and move them to the same place in the docs folder - Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { - $file = $_ - Write-Host "Processing: $file" - $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) - Write-Host "Doc file path: $docsFilePath" - $docsFolderPath = Split-Path -Path $docsFilePath -Parent - New-Item -Path $docsFolderPath -ItemType Directory -Force - Move-Item -Path $file.FullName -Destination $docsFilePath -Force - } + # find the source code file that matches the markdown file + $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } + Write-Host "Found script path: $scriptPath" + $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') + Write-Host "Doc file path: $docsFilePath" + $docsFolderPath = Split-Path -Path $docsFilePath -Parent + New-Item -Path $docsFolderPath -ItemType Directory -Force + Move-Item -Path $file.FullName -Destination $docsFilePath -Force + } + # Get the MD files that are in the public functions folder and move them to the same place in the docs folder + Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { + $file = $_ + Write-Host "Processing: $file" + $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) + Write-Host "Doc file path: $docsFilePath" + $docsFolderPath = Split-Path -Path $docsFilePath -Parent + New-Item -Path $docsFolderPath -ItemType Directory -Force + Move-Item -Path $file.FullName -Destination $docsFilePath -Force } Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { $fileName = $_.Name $hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash - LogGroup " - [$fileName] - [$hash]" { - Show-FileContent -Path $_ - } + Write-Host "::group:: - [$fileName] - [$hash]" + Show-FileContent -Path $_ } } diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 index 75c049a..a86977a 100644 --- a/scripts/helpers/Import-PSModule.ps1 +++ b/scripts/helpers/Import-PSModule.ps1 @@ -7,12 +7,11 @@ Imports a build PS module. .EXAMPLE - Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $ModuleName + Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $moduleName - Imports a module located at $ModuleFolderPath with the name $ModuleName. + Imports a module located at $ModuleFolderPath with the name $moduleName. #> [CmdletBinding()] - #Requires -Modules Utilities [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' @@ -20,30 +19,29 @@ param( # Path to the folder where the module source code is located. [Parameter(Mandatory)] - [string] $Path, - - # Name of the module. - [Parameter(Mandatory)] - [string] $ModuleName + [string] $Path ) $moduleName = Split-Path -Path $Path -Leaf - $manifestFileName = "$moduleName.psd1" - $manifestFilePath = Join-Path -Path $Path $manifestFileName - $manifestFile = Get-ModuleManifest -Path $manifestFilePath -As FileInfo -Verbose + $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" + + Write-Host " - Manifest file path: [$manifestFilePath]" + Remove-PSModule -Name $moduleName + Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath + + Write-Host ' - List installed modules' + Get-InstalledPSResource | Format-Table -AutoSize - Write-Host "Manifest file path: [$($manifestFile.FullName)]" -Verbose - Remove-PSModule -Name $ModuleName - Resolve-PSModuleDependency -ManifestFilePath $manifestFile - Import-Module -Name $ModuleName -RequiredVersion '999.0.0' + Write-Host " - Importing module [$moduleName] v999" + Import-Module -Name $moduleName -RequiredVersion '999.0.0' - Write-Host 'List loaded modules' + Write-Host ' - List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize - Write-Host 'List commands' + Write-Host ' - List commands' Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) - if ($ModuleName -notin $availableModules.Name) { + if ($moduleName -notin $availableModules.Name) { throw 'Module not found' } } diff --git a/scripts/helpers/Remove-PSModule.ps1 b/scripts/helpers/Remove-PSModule.ps1 index 749765e..fe51e84 100644 --- a/scripts/helpers/Remove-PSModule.ps1 +++ b/scripts/helpers/Remove-PSModule.ps1 @@ -3,7 +3,6 @@ .SYNOPSIS Removes and uninstalls a PowerShell module. - .EXAMPLE Remove-PSModule -ModuleName 'Utilities' diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 8b2fb30..4275080 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -1,28 +1,26 @@ function Resolve-PSModuleDependency { <# - .SYNOPSIS - Resolve dependencies for a module based on the manifest file. + .SYNOPSIS + Resolve dependencies for a module based on the manifest file. - .DESCRIPTION - Resolve dependencies for a module based on the manifest file, following PSModuleInfo structure + .DESCRIPTION + Resolve dependencies for a module based on the manifest file, following PSModuleInfo structure - .EXAMPLE - Resolve-PSModuleDependency -Path 'C:\MyModule\MyModule.psd1' + .EXAMPLE + Resolve-PSModuleDependency -Path 'C:\MyModule\MyModule.psd1' - Installs all modules defined in the manifest file, following PSModuleInfo structure. + Installs all modules defined in the manifest file, following PSModuleInfo structure. - .NOTES - Should later be adapted to support both pre-reqs, and dependencies. - Should later be adapted to take 4 parameters sets: specific version ("requiredVersion" | "GUID"), latest version ModuleVersion, - and latest version within a range MinimumVersion - MaximumVersion. + .NOTES + Should later be adapted to support both pre-reqs, and dependencies. + Should later be adapted to take 4 parameters sets: specific version ("requiredVersion" | "GUID"), latest version ModuleVersion, + and latest version within a range MinimumVersion - MaximumVersion. #> - [Alias('Resolve-PSModuleDependencies')] - [CmdletBinding()] - #Requires -Modules Retry [Diagnostics.CodeAnalysis.SuppressMessageAttribute( 'PSAvoidUsingWriteHost', '', Scope = 'Function', Justification = 'Want to just write to the console, not the pipeline.' )] + [CmdletBinding()] param( # The path to the manifest file. [Parameter(Mandatory)] @@ -32,8 +30,8 @@ Write-Host 'Resolving dependencies' $manifest = Import-PowerShellDataFile -Path $ManifestFilePath - Write-Host "Reading [$ManifestFilePath]" - Write-Host "Found [$($manifest.RequiredModules.Count)] modules to install" + Write-Host " - Reading [$ManifestFilePath]" + Write-Host " - Found [$($manifest.RequiredModules.Count)] modules to install" foreach ($requiredModule in $manifest.RequiredModules) { $installParams = @{} @@ -51,19 +49,33 @@ $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Write-Host "[$($installParams.Name)] - Uninstalling module" + Write-Host " - [$($installParams.Name)] - Uninstalling module" Remove-PSModule -Name $installParams.Name - Write-Host "[$($installParams.Name)] - Installing module" - Retry -Count 5 -Delay 10 { - Install-Module @installParams -AllowPrerelease:$false + Write-Host " - [$($installParams.Name)] - Installing module" + $Count = 5 + $Delay = 10 + for ($i = 0; $i -lt $Count; $i++) { + try { + Install-Module @installParams + break + } catch { + Write-Warning 'The command:' + Write-Warning $Run.ToString() + Write-Warning "failed with error: $_" + if ($i -eq $Count - 1) { + throw + } + Write-Warning "Retrying in $Delay seconds..." + Start-Sleep -Seconds $Delay + } } $VerbosePreference = $VerbosePreferenceOriginal - Write-Host "[$($installParams.Name)] - Importing module" + Write-Host " - [$($installParams.Name)] - Importing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' Import-Module @installParams $VerbosePreference = $VerbosePreferenceOriginal - Write-Host "[$($installParams.Name)] - Done" + Write-Host " - [$($installParams.Name)] - Done" } - Write-Host 'Resolving dependencies - Done' + Write-Host ' - Resolving dependencies - Done' } diff --git a/scripts/helpers/Show-FileContent.ps1 b/scripts/helpers/Show-FileContent.ps1 new file mode 100644 index 0000000..6ad6295 --- /dev/null +++ b/scripts/helpers/Show-FileContent.ps1 @@ -0,0 +1,32 @@ +function Show-FileContent { + <# + .SYNOPSIS + Prints the content of a file with line numbers in front of each line. + + .DESCRIPTION + Prints the content of a file with line numbers in front of each line. + + .EXAMPLE + $Path = 'C:\Utilities\Show-FileContent.ps1' + Show-FileContent -Path $Path + + Shows the content of the file with line numbers in front of each line. + #> + [CmdletBinding()] + param ( + # The path to the file to show the content of. + [Parameter(Mandatory)] + [string] $Path + ) + + $content = Get-Content -Path $Path + $lineNumber = 1 + $columnSize = $content.Count.ToString().Length + # Foreach line print the line number in front of the line with [ ] around it. + # The linenumber should dynamically adjust to the number of digits with the length of the file. + foreach ($line in $content) { + $lineNumberFormatted = $lineNumber.ToString().PadLeft($columnSize) + Write-Host "[$lineNumberFormatted] $line" + $lineNumber++ + } +} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 30e9f15..1ed491f 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,31 +5,28 @@ [CmdletBinding()] param() -#Requires -Modules Utilities - $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative -LogGroup "Loading helper scripts from [$path]" { - Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object { - Write-Host "$_" - . $_ - } +Write-Host "::group::Loading helper scripts from [$path]" +Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object { + Write-Host "$_" + . $_ } -LogGroup 'Loading inputs' { - $moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name - Write-Host "Module name: [$moduleName]" - - $moduleSourceFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/src" - if (-not (Test-Path -Path $moduleSourceFolderPath)) { - throw "Module path [$moduleSourceFolderPath] does not exist." - } - Write-Host "Module source path: [$moduleSourceFolderPath]" +Write-Host '::group::Loading inputs' +$env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' +$moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name +Write-Host "Module name: [$moduleName]" - $modulesOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/module' - Write-Host "Module output path: [$modulesOutputFolderPath]" - $docsOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/docs' - Write-Host "Docs output path: [$docsOutputFolderPath]" +$moduleSourceFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/src" +if (-not (Test-Path -Path $moduleSourceFolderPath)) { + throw "Module path [$moduleSourceFolderPath] does not exist." } +Write-Host "Module source path: [$moduleSourceFolderPath]" + +$modulesOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/module' +Write-Host "Module output path: [$modulesOutputFolderPath]" +$docsOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/docs' +Write-Host "Docs output path: [$docsOutputFolderPath]" $params = @{ ModuleName = $moduleName From 2c0a96773f6837698b15e03a44295c04b52c0be7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 22:47:23 +0100 Subject: [PATCH 17/44] Refactor action.yml and Build-PSModuleDocumentation.ps1 to streamline execution and improve module import process --- action.yml | 12 ++++-------- scripts/helpers/Build-PSModuleDocumentation.ps1 | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 093441d..1469c27 100644 --- a/action.yml +++ b/action.yml @@ -37,11 +37,7 @@ runs: env: GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }} - with: - Debug: ${{ inputs.Debug }} - Prerelease: ${{ inputs.Prerelease }} - Verbose: ${{ inputs.Verbose }} - Version: ${{ inputs.Version }} - Script: | - # Build-PSModuleDocumentation - ${{ github.action_path }}\scripts\main.ps1 + shell: pwsh + run: | + # Build-PSModuleDocumentation + ${{ github.action_path }}\scripts\main.ps1 diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index 950615a..dbc6534 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -46,7 +46,7 @@ Write-Host '::group::Build docs - Generate markdown help' Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) - Import-PSModule -Path $ModuleOutputFolder -ModuleName $ModuleName + Import-PSModule -Path $ModuleOutputFolder Write-Host ($ModuleName | Get-Module) $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { From da8dadb436be1a602c881c15213a5118ed9338ce Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 22:50:48 +0100 Subject: [PATCH 18/44] Remove dependency on PSModule/GitHub-Script in action.yml to simplify execution --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index 1469c27..39150a8 100644 --- a/action.yml +++ b/action.yml @@ -33,7 +33,6 @@ runs: using: composite steps: - name: Document-PSModule - uses: PSModule/GitHub-Script@v1 env: GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }} From d682b9358c23462c4f88d8856db1991bf24944bc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:03:28 +0100 Subject: [PATCH 19/44] Enhance error handling in Remove-PSModule.ps1 by adding -ErrorAction SilentlyContinue to Get-InstalledPSResource --- scripts/helpers/Remove-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Remove-PSModule.ps1 b/scripts/helpers/Remove-PSModule.ps1 index fe51e84..84bdd05 100644 --- a/scripts/helpers/Remove-PSModule.ps1 +++ b/scripts/helpers/Remove-PSModule.ps1 @@ -33,7 +33,7 @@ Write-Host " - Removing command [$($command.Name)]" $command | Remove-Item -Force } - $installedModule = Get-InstalledPSResource | Where-Object { $_.Name -eq $Name } + $installedModule = Get-InstalledPSResource -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $Name } Write-Host " - Found [$($installedModule.Count)] installed modules to remove" foreach ($module in $installedModule) { Write-Host " - Uninstalling module [$($module.Name)]" From ab4de46fb3f3e0dbcbcd8756c7a2658b2d2f0942 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:14:13 +0100 Subject: [PATCH 20/44] Remove Add-PSModulePath and Remove-PSModule functions to simplify module management --- scripts/helpers/Add-PSModulePath.ps1 | 29 ------------ .../helpers/Build-PSModuleDocumentation.ps1 | 1 - scripts/helpers/Import-PSModule.ps1 | 3 +- scripts/helpers/Remove-PSModule.ps1 | 44 ------------------- .../helpers/Resolve-PSModuleDependency.ps1 | 2 - 5 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 scripts/helpers/Add-PSModulePath.ps1 delete mode 100644 scripts/helpers/Remove-PSModule.ps1 diff --git a/scripts/helpers/Add-PSModulePath.ps1 b/scripts/helpers/Add-PSModulePath.ps1 deleted file mode 100644 index f5abf04..0000000 --- a/scripts/helpers/Add-PSModulePath.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -function Add-PSModulePath { - <# - .SYNOPSIS - Adds a path to the PSModulePath environment variable. - - .DESCRIPTION - Adds a path to the PSModulePath environment variable. - For Linux and macOS, the path delimiter is ':' and for Windows it is ';'. - - .EXAMPLE - Add-PSModulePath -Path 'C:\Users\user\Documents\WindowsPowerShell\Modules' - - Adds the path 'C:\Users\user\Documents\WindowsPowerShell\Modules' to the PSModulePath environment variable. - #> - [CmdletBinding()] - param( - # Path to the folder where the module source code is located. - [Parameter(Mandatory)] - [string] $Path - ) - $PSModulePathSeparator = [System.IO.Path]::PathSeparator - - $env:PSModulePath += "$PSModulePathSeparator$Path" - - Write-Verbose 'PSModulePath:' - $env:PSModulePath.Split($PSModulePathSeparator) | ForEach-Object { - Write-Verbose " - [$_]" - } -} diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index dbc6534..f5dfffb 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -45,7 +45,6 @@ Write-Host "Docs output folder: [$docsOutputFolder]" Write-Host '::group::Build docs - Generate markdown help' - Add-PSModulePath -Path (Split-Path -Path $ModuleOutputFolder -Parent) Import-PSModule -Path $ModuleOutputFolder Write-Host ($ModuleName | Get-Module) $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 index a86977a..0e176be 100644 --- a/scripts/helpers/Import-PSModule.ps1 +++ b/scripts/helpers/Import-PSModule.ps1 @@ -26,14 +26,13 @@ $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" Write-Host " - Manifest file path: [$manifestFilePath]" - Remove-PSModule -Name $moduleName Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath Write-Host ' - List installed modules' Get-InstalledPSResource | Format-Table -AutoSize Write-Host " - Importing module [$moduleName] v999" - Import-Module -Name $moduleName -RequiredVersion '999.0.0' + Import-Module $Path Write-Host ' - List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false diff --git a/scripts/helpers/Remove-PSModule.ps1 b/scripts/helpers/Remove-PSModule.ps1 deleted file mode 100644 index 84bdd05..0000000 --- a/scripts/helpers/Remove-PSModule.ps1 +++ /dev/null @@ -1,44 +0,0 @@ -filter Remove-PSModule { - <# - .SYNOPSIS - Removes and uninstalls a PowerShell module. - - .EXAMPLE - Remove-PSModule -ModuleName 'Utilities' - - Removes a module 'Utilities' from the session then from the system. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - [CmdletBinding(SupportsShouldProcess)] - param( - # Name of the module. - [Parameter(Mandatory, ValueFromPipeline)] - [string] $Name - ) - - if ($PSCmdlet.ShouldProcess('Target', "Remove module [$Name]")) { - Write-Host "[$Name] - Remove module" - $importedModule = Get-Module -ListAvailable | Where-Object { $_.Name -eq $Name } - Write-Host " - Found [$($importedModule.Count)] modules to remove" - foreach ($module in $importedModule) { - Write-Host " - Removing module [$($module.Name)]" - $module | Remove-Module -Force - } - $commands = Get-ChildItem -Path Function: | Where-Object { $_.Source -eq $Name } - Write-Host " - Found [$($commands.Count)] commands to remove" - foreach ($command in $commands) { - Write-Host " - Removing command [$($command.Name)]" - $command | Remove-Item -Force - } - $installedModule = Get-InstalledPSResource -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $Name } - Write-Host " - Found [$($installedModule.Count)] installed modules to remove" - foreach ($module in $installedModule) { - Write-Host " - Uninstalling module [$($module.Name)]" - $module | Uninstall-PSResource -SkipDependencyCheck - } - Get-Command -Module $Name | Format-Table -AutoSize - } -} diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 4275080..5a1c52c 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -49,8 +49,6 @@ $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Write-Host " - [$($installParams.Name)] - Uninstalling module" - Remove-PSModule -Name $installParams.Name Write-Host " - [$($installParams.Name)] - Installing module" $Count = 5 $Delay = 10 From fc58cca71ee95bc12a8dcb4d7f188463ec641178 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:27:36 +0100 Subject: [PATCH 21/44] Refactor Resolve-PSModuleDependency to support Install-PSResource and improve version handling --- .../helpers/Resolve-PSModuleDependency.ps1 | 83 ++++++++++++++----- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 5a1c52c..4ff5aa2 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -1,15 +1,17 @@ function Resolve-PSModuleDependency { <# .SYNOPSIS - Resolve dependencies for a module based on the manifest file. + Resolves module dependencies from a manifest file using Install-PSResource. .DESCRIPTION - Resolve dependencies for a module based on the manifest file, following PSModuleInfo structure + Reads a module manifest (PSD1) and for each required module converts the old + Install-Module parameters (MinimumVersion, MaximumVersion, RequiredVersion) + into a single NuGet version range string for Install-PSResource's –Version parameter. + (Note: If RequiredVersion is set, that value takes precedence.) .EXAMPLE - Resolve-PSModuleDependency -Path 'C:\MyModule\MyModule.psd1' - - Installs all modules defined in the manifest file, following PSModuleInfo structure. + Resolve-PSModuleDependency -ManifestFilePath 'C:\MyModule\MyModule.psd1' + Installs all modules defined in the manifest file, following PSModuleInfo structure. .NOTES Should later be adapted to support both pre-reqs, and dependencies. @@ -27,47 +29,82 @@ [string] $ManifestFilePath ) + # Helper: Converts the legacy version parameters into a NuGet version range. + function Convert-VersionSpec { + param( + [string]$MinimumVersion, + [string]$MaximumVersion, + [string]$RequiredVersion + ) + if ($RequiredVersion) { + # Exact match – note that for an exact version, using bracket notation + # helps ensure that Install-PSResource looks for that version only. + return "[$RequiredVersion]" + } elseif ($MinimumVersion -and $MaximumVersion) { + # Both bounds provided; note that this makes both ends inclusive. + return "[$MinimumVersion,$MaximumVersion]" + } elseif ($MinimumVersion) { + # Only a minimum is provided. + # Using the notation “[1.0.0.0, ]” ensures a minimum-inclusive search. + return "[$MinimumVersion, ]" + } elseif ($MaximumVersion) { + # Only a maximum is provided; here we use an open lower bound. + return "(, $MaximumVersion]" + } else { + return $null + } + } + Write-Host 'Resolving dependencies' $manifest = Import-PowerShellDataFile -Path $ManifestFilePath Write-Host " - Reading [$ManifestFilePath]" - Write-Host " - Found [$($manifest.RequiredModules.Count)] modules to install" + Write-Host " - Found [$($manifest.RequiredModules.Count)] module(s) to install" foreach ($requiredModule in $manifest.RequiredModules) { - $installParams = @{} + $installParams = @{ + Force = $true + Verbose = $false + } if ($requiredModule -is [string]) { $installParams.Name = $requiredModule } else { $installParams.Name = $requiredModule.ModuleName - $installParams.MinimumVersion = $requiredModule.ModuleVersion - $installParams.RequiredVersion = $requiredModule.RequiredVersion - $installParams.MaximumVersion = $requiredModule.MaximumVersion + + # Convert legacy version parameters into the new –Version spec. + $versionSpec = Convert-VersionSpec ` + -MinimumVersion $requiredModule.ModuleVersion ` + -MaximumVersion $requiredModule.MaximumVersion ` + -RequiredVersion $requiredModule.RequiredVersion + + if ($versionSpec) { + $installParams.Version = $versionSpec + } } - $installParams.Force = $true - $installParams.Verbose = $false + Write-Host " - [$($installParams.Name)] - Installing module with version spec: $($installParams.Version)" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Write-Host " - [$($installParams.Name)] - Installing module" - $Count = 5 - $Delay = 10 - for ($i = 0; $i -lt $Count; $i++) { + + # Basic retry logic in case of transient errors. + $retryCount = 5 + $retryDelay = 10 + for ($i = 0; $i -lt $retryCount; $i++) { try { - Install-Module @installParams + Install-PSResource @installParams break } catch { - Write-Warning 'The command:' - Write-Warning $Run.ToString() - Write-Warning "failed with error: $_" - if ($i -eq $Count - 1) { + Write-Warning "Installation of $($installParams.Name) failed with error: $_" + if ($i -eq $retryCount - 1) { throw } - Write-Warning "Retrying in $Delay seconds..." - Start-Sleep -Seconds $Delay + Write-Warning "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay } } $VerbosePreference = $VerbosePreferenceOriginal + Write-Host " - [$($installParams.Name)] - Importing module" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' From dccdd8f810e0cda80b57709fdff906a5bd76a32c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:29:38 +0100 Subject: [PATCH 22/44] Refactor Resolve-PSModuleDependency to simplify installation parameters --- scripts/helpers/Resolve-PSModuleDependency.ps1 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 4ff5aa2..0cbd1dc 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -62,10 +62,7 @@ Write-Host " - Found [$($manifest.RequiredModules.Count)] module(s) to install" foreach ($requiredModule in $manifest.RequiredModules) { - $installParams = @{ - Force = $true - Verbose = $false - } + $installParams = @{} if ($requiredModule -is [string]) { $installParams.Name = $requiredModule From 48672a6be00c28c950fc70dc129c16b0eb35a866 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:30:52 +0100 Subject: [PATCH 23/44] Add TrustRepository parameter to installation parameters in Resolve-PSModuleDependency --- scripts/helpers/Resolve-PSModuleDependency.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 0cbd1dc..f5a5901 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -62,7 +62,9 @@ Write-Host " - Found [$($manifest.RequiredModules.Count)] module(s) to install" foreach ($requiredModule in $manifest.RequiredModules) { - $installParams = @{} + $installParams = @{ + TrustRepository = $true + } if ($requiredModule -is [string]) { $installParams.Name = $requiredModule From f811cca93a9ead0247a4f4ec32abbad23961f76b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:39:25 +0100 Subject: [PATCH 24/44] Refactor Resolve-PSModuleDependency to enhance version handling and improve parameter usage for Install-PSResource --- .../helpers/Resolve-PSModuleDependency.ps1 | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index f5a5901..3dfe964 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -29,7 +29,7 @@ [string] $ManifestFilePath ) - # Helper: Converts the legacy version parameters into a NuGet version range. + # Helper: Convert legacy version parameters into a NuGet version range string. function Convert-VersionSpec { param( [string]$MinimumVersion, @@ -37,18 +37,16 @@ [string]$RequiredVersion ) if ($RequiredVersion) { - # Exact match – note that for an exact version, using bracket notation - # helps ensure that Install-PSResource looks for that version only. + # Use exact match in bracket notation. return "[$RequiredVersion]" } elseif ($MinimumVersion -and $MaximumVersion) { - # Both bounds provided; note that this makes both ends inclusive. + # Both bounds provided; both are inclusive. return "[$MinimumVersion,$MaximumVersion]" } elseif ($MinimumVersion) { - # Only a minimum is provided. - # Using the notation “[1.0.0.0, ]” ensures a minimum-inclusive search. + # Only a minimum is provided. Use a minimum-inclusive range. return "[$MinimumVersion, ]" } elseif ($MaximumVersion) { - # Only a maximum is provided; here we use an open lower bound. + # Only a maximum is provided; lower bound open. return "(, $MaximumVersion]" } else { return $null @@ -56,45 +54,61 @@ } Write-Host 'Resolving dependencies' - $manifest = Import-PowerShellDataFile -Path $ManifestFilePath Write-Host " - Reading [$ManifestFilePath]" Write-Host " - Found [$($manifest.RequiredModules.Count)] module(s) to install" foreach ($requiredModule in $manifest.RequiredModules) { - $installParams = @{ + # Build parameters for Install-PSResource (new version spec). + $psResourceParams = @{ TrustRepository = $true } + # Build parameters for Import-Module (legacy version spec). + $importParams = @{ + Force = $true + Verbose = $false + } if ($requiredModule -is [string]) { - $installParams.Name = $requiredModule + $psResourceParams.Name = $requiredModule + $importParams.Name = $requiredModule } else { - $installParams.Name = $requiredModule.ModuleName + $psResourceParams.Name = $requiredModule.ModuleName + $importParams.Name = $requiredModule.ModuleName - # Convert legacy version parameters into the new –Version spec. + # Convert legacy version info for Install-PSResource. $versionSpec = Convert-VersionSpec ` -MinimumVersion $requiredModule.ModuleVersion ` -MaximumVersion $requiredModule.MaximumVersion ` -RequiredVersion $requiredModule.RequiredVersion if ($versionSpec) { - $installParams.Version = $versionSpec + $psResourceParams.Version = $versionSpec + } + + # For Import-Module, keep the original version parameters. + if ($requiredModule.ModuleVersion) { + $importParams.MinimumVersion = $requiredModule.ModuleVersion + } + if ($requiredModule.RequiredVersion) { + $importParams.RequiredVersion = $requiredModule.RequiredVersion + } + if ($requiredModule.MaximumVersion) { + $importParams.MaximumVersion = $requiredModule.MaximumVersion } } - Write-Host " - [$($installParams.Name)] - Installing module with version spec: $($installParams.Version)" + Write-Host " - [$($psResourceParams.Name)] - Installing module with Install-PSResource using version spec: $($psResourceParams.Version)" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - - # Basic retry logic in case of transient errors. $retryCount = 5 $retryDelay = 10 for ($i = 0; $i -lt $retryCount; $i++) { try { - Install-PSResource @installParams + Install-PSResource @psResourceParams break } catch { - Write-Warning "Installation of $($installParams.Name) failed with error: $_" + Write-Warning "Installation of $($psResourceParams.Name) failed with error: $_" if ($i -eq $retryCount - 1) { throw } @@ -104,12 +118,12 @@ } $VerbosePreference = $VerbosePreferenceOriginal - Write-Host " - [$($installParams.Name)] - Importing module" + Write-Host " - [$($importParams.Name)] - Importing module with legacy version spec" $VerbosePreferenceOriginal = $VerbosePreference $VerbosePreference = 'SilentlyContinue' - Import-Module @installParams + Import-Module @importParams $VerbosePreference = $VerbosePreferenceOriginal - Write-Host " - [$($installParams.Name)] - Done" + Write-Host " - [$($importParams.Name)] - Done" } Write-Host ' - Resolving dependencies - Done' } From 7daac2e879edd50c40566419e6cab125b4c24485 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:42:17 +0100 Subject: [PATCH 25/44] Refactor Import-PSModule to validate module existence using imported commands --- scripts/helpers/Import-PSModule.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 index 0e176be..3d384cd 100644 --- a/scripts/helpers/Import-PSModule.ps1 +++ b/scripts/helpers/Import-PSModule.ps1 @@ -38,9 +38,10 @@ $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize Write-Host ' - List commands' + $commands = Get-Command -Module $moduleName -ListImported Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) - if ($moduleName -notin $availableModules.Name) { + if ($moduleName -notin $commands.Source) { throw 'Module not found' } } From bd73f91e5503313921e1a6aee173fb5f48fc0e02 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 26 Feb 2025 23:45:07 +0100 Subject: [PATCH 26/44] Add installation and import of modules from platyPS with TrustRepository parameter --- scripts/main.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 1ed491f..dfecf62 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,6 +5,11 @@ [CmdletBinding()] param() +'platyPS' | ForEach-Object { + Install-PSResource -Name $_ -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery + Import-Module -Name $_ +} + $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative Write-Host "::group::Loading helper scripts from [$path]" Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | ForEach-Object { From d2759336cbf04f15228440df9e53c36b8eecea5b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 21:42:39 +0100 Subject: [PATCH 27/44] Refactor action.yml and main.ps1 to remove Path input and add WorkingDirectory input; implement Convert-VersionSpec function for version range handling. --- action.yml | 12 +-- scripts/helpers/Convert-VersionSpec.ps1 | 98 +++++++++++++++++++ .../helpers/Resolve-PSModuleDependency.ps1 | 24 ----- scripts/main.ps1 | 9 +- 4 files changed, 107 insertions(+), 36 deletions(-) create mode 100644 scripts/helpers/Convert-VersionSpec.ps1 diff --git a/action.yml b/action.yml index 39150a8..849e008 100644 --- a/action.yml +++ b/action.yml @@ -9,10 +9,6 @@ inputs: Name: description: Name of the module to process. required: false - Path: - description: The path to the root of the repo. - required: false - default: ${{ github.workspace }} Debug: description: Enable debug output. required: false @@ -28,6 +24,10 @@ inputs: description: Allow prerelease versions if available. required: false default: 'false' + WorkingDirectory: + description: The working directory where the script will run from. + required: false + default: ${{ github.workspace }} runs: using: composite @@ -35,8 +35,8 @@ runs: - name: Document-PSModule env: GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} - GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }} shell: pwsh + working-directory: ${{ inputs.WorkingDirectory }} run: | # Build-PSModuleDocumentation - ${{ github.action_path }}\scripts\main.ps1 + ${{ github.action_path }}/scripts/main.ps1 diff --git a/scripts/helpers/Convert-VersionSpec.ps1 b/scripts/helpers/Convert-VersionSpec.ps1 new file mode 100644 index 0000000..14357a8 --- /dev/null +++ b/scripts/helpers/Convert-VersionSpec.ps1 @@ -0,0 +1,98 @@ +function Convert-VersionSpec { + <# + .SYNOPSIS + Converts legacy version parameters into a NuGet version range string. + + .DESCRIPTION + This function takes minimum, maximum, or required version parameters + and constructs a NuGet-compatible version range string. + + - If `RequiredVersion` is specified, the output is an exact match range. + - If both `MinimumVersion` and `MaximumVersion` are provided, + an inclusive range is returned. + - If only `MinimumVersion` is provided, it returns a minimum-inclusive range. + - If only `MaximumVersion` is provided, it returns an upper-bound range. + - If no parameters are provided, `$null` is returned. + + .EXAMPLE + Convert-VersionSpec -MinimumVersion "1.0.0" -MaximumVersion "2.0.0" + + Output: + ```powershell + [1.0.0,2.0.0] + ``` + + Returns an inclusive version range from 1.0.0 to 2.0.0. + + .EXAMPLE + Convert-VersionSpec -RequiredVersion "1.5.0" + + Output: + ```powershell + [1.5.0] + ``` + + Returns an exact match for version 1.5.0. + + .EXAMPLE + Convert-VersionSpec -MinimumVersion "1.0.0" + + Output: + ```powershell + [1.0.0, ] + ``` + + Returns a minimum-inclusive version range starting at 1.0.0. + + .EXAMPLE + Convert-VersionSpec -MaximumVersion "2.0.0" + + Output: + ```powershell + (, 2.0.0] + ``` + + Returns an upper-bound range up to version 2.0.0. + + .OUTPUTS + string + + .NOTES + The NuGet version range string based on the provided parameters. + The returned string follows NuGet versioning syntax. + + .LINK + https://psmodule.io/Convert/Functions/Convert-VersionSpec + #> + [OutputType([string])] + [CmdletBinding()] + param( + # The minimum version for the range. If specified alone, the range is open-ended upwards. + [Parameter()] + [string] $MinimumVersion, + + # The maximum version for the range. If specified alone, the range is open-ended downwards. + [Parameter()] + [string] $MaximumVersion, + + # Specifies an exact required version. If set, an exact version range is returned. + [Parameter()] + [string] $RequiredVersion + ) + + if ($RequiredVersion) { + # Use exact match in bracket notation. + return "[$RequiredVersion]" + } elseif ($MinimumVersion -and $MaximumVersion) { + # Both bounds provided; both are inclusive. + return "[$MinimumVersion,$MaximumVersion]" + } elseif ($MinimumVersion) { + # Only a minimum is provided. Use a minimum-inclusive range. + return "[$MinimumVersion, ]" + } elseif ($MaximumVersion) { + # Only a maximum is provided; lower bound open. + return "(, $MaximumVersion]" + } else { + return $null + } +} diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 index 3dfe964..edb3c29 100644 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ b/scripts/helpers/Resolve-PSModuleDependency.ps1 @@ -29,30 +29,6 @@ [string] $ManifestFilePath ) - # Helper: Convert legacy version parameters into a NuGet version range string. - function Convert-VersionSpec { - param( - [string]$MinimumVersion, - [string]$MaximumVersion, - [string]$RequiredVersion - ) - if ($RequiredVersion) { - # Use exact match in bracket notation. - return "[$RequiredVersion]" - } elseif ($MinimumVersion -and $MaximumVersion) { - # Both bounds provided; both are inclusive. - return "[$MinimumVersion,$MaximumVersion]" - } elseif ($MinimumVersion) { - # Only a minimum is provided. Use a minimum-inclusive range. - return "[$MinimumVersion, ]" - } elseif ($MaximumVersion) { - # Only a maximum is provided; lower bound open. - return "(, $MaximumVersion]" - } else { - return $null - } - } - Write-Host 'Resolving dependencies' $manifest = Import-PowerShellDataFile -Path $ManifestFilePath Write-Host " - Reading [$ManifestFilePath]" diff --git a/scripts/main.ps1 b/scripts/main.ps1 index dfecf62..3c68ecc 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -22,15 +22,12 @@ $env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' $moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name Write-Host "Module name: [$moduleName]" -$moduleSourceFolderPath = Resolve-Path -Path "$env:GITHUB_ACTION_INPUT_Path/src" -if (-not (Test-Path -Path $moduleSourceFolderPath)) { - throw "Module path [$moduleSourceFolderPath] does not exist." -} +$moduleSourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path Write-Host "Module source path: [$moduleSourceFolderPath]" -$modulesOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/module' +$modulesOutputFolderPath = New-Item -Path 'outputs/module' -Force Write-Host "Module output path: [$modulesOutputFolderPath]" -$docsOutputFolderPath = Join-Path -Path $env:GITHUB_ACTION_INPUT_Path 'outputs/docs' +$docsOutputFolderPath = New-Item -Path 'outputs/docs' -Force Write-Host "Docs output path: [$docsOutputFolderPath]" $params = @{ From 7ab55c483846929432c62c8630e109cb92b3b866 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 21:46:13 +0100 Subject: [PATCH 28/44] Update Action-Test.yml to replace Path input with WorkingDirectory for improved clarity --- .github/workflows/Action-Test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 810f8c3..8597323 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -37,4 +37,4 @@ jobs: uses: ./ with: Name: PSModuleTest - Path: tests/srcTestRepo + WorkingDirectory: tests/srcTestRepo From 924f8bfd32d1c8ff02d308a9fcd8a7fa47f10fb5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 21:48:54 +0100 Subject: [PATCH 29/44] Refactor main.ps1 to use Resolve-Path for output folder paths, improving path resolution consistency --- scripts/main.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 3c68ecc..a27f070 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -25,9 +25,9 @@ Write-Host "Module name: [$moduleName]" $moduleSourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path Write-Host "Module source path: [$moduleSourceFolderPath]" -$modulesOutputFolderPath = New-Item -Path 'outputs/module' -Force +$modulesOutputFolderPath = Resolve-Path -Path 'outputs/module' | Select-Object -ExpandProperty Path Write-Host "Module output path: [$modulesOutputFolderPath]" -$docsOutputFolderPath = New-Item -Path 'outputs/docs' -Force +$docsOutputFolderPath = Resolve-Path -Path 'outputs/docs' | Select-Object -ExpandProperty Path Write-Host "Docs output path: [$docsOutputFolderPath]" $params = @{ From f93eb7c95b0b97f72f55b57646789377f4c102d9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 28 Feb 2025 21:51:22 +0100 Subject: [PATCH 30/44] Refactor main.ps1 to replace Resolve-Path with Join-Path for output folder paths, enhancing path handling consistency --- scripts/main.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a27f070..3496286 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -25,9 +25,9 @@ Write-Host "Module name: [$moduleName]" $moduleSourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path Write-Host "Module source path: [$moduleSourceFolderPath]" -$modulesOutputFolderPath = Resolve-Path -Path 'outputs/module' | Select-Object -ExpandProperty Path +$modulesOutputFolderPath = Join-Path -Path . -ChildPath 'outputs/module' Write-Host "Module output path: [$modulesOutputFolderPath]" -$docsOutputFolderPath = Resolve-Path -Path 'outputs/docs' | Select-Object -ExpandProperty Path +$docsOutputFolderPath = Join-Path -Path . -ChildPath 'outputs/docs' Write-Host "Docs output path: [$docsOutputFolderPath]" $params = @{ From 982e70c5448a65cfd3afd3bd31f68664120ac6f7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 11:32:48 +0100 Subject: [PATCH 31/44] Update action.yml and Import-PSModule.ps1 to enhance output formatting; set shell in action.yml and ensure output is string formatted in Import-PSModule.ps1 --- action.yml | 2 +- scripts/helpers/Import-PSModule.ps1 | 4 ++-- scripts/main.ps1 | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 849e008..5481e4f 100644 --- a/action.yml +++ b/action.yml @@ -33,9 +33,9 @@ runs: using: composite steps: - name: Document-PSModule + shell: pwsh env: GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }} - shell: pwsh working-directory: ${{ inputs.WorkingDirectory }} run: | # Build-PSModuleDocumentation diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 index 3d384cd..547bc00 100644 --- a/scripts/helpers/Import-PSModule.ps1 +++ b/scripts/helpers/Import-PSModule.ps1 @@ -29,14 +29,14 @@ Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath Write-Host ' - List installed modules' - Get-InstalledPSResource | Format-Table -AutoSize + Get-InstalledPSResource | Format-Table -AutoSize | Out-String Write-Host " - Importing module [$moduleName] v999" Import-Module $Path Write-Host ' - List loaded modules' $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false - $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize + $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize | Out-String Write-Host ' - List commands' $commands = Get-Command -Module $moduleName -ListImported Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 3496286..a89c206 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -5,6 +5,8 @@ [CmdletBinding()] param() +$PSStyle.OutputRendering = 'Ansi' + 'platyPS' | ForEach-Object { Install-PSResource -Name $_ -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery Import-Module -Name $_ From 5df55a71896f1432296e30ce634d14a94b0467f6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 11:40:15 +0100 Subject: [PATCH 32/44] Refactor Build-PSModuleDocumentation.ps1 and main.ps1 to enhance output clarity; replace Write-Host with formatted output for module details and paths. --- .../helpers/Build-PSModuleDocumentation.ps1 | 22 +++++++++---------- scripts/main.ps1 | 8 ++----- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index f5dfffb..fa03a4b 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -30,21 +30,22 @@ ) Write-Host "::group::Documenting module [$ModuleName]" - Write-Host "Source path: [$ModuleSourceFolderPath]" + [pscustomobject]@{ + ModuleName = $ModuleName + ModuleSourceFolderPath = $ModuleSourceFolderPath + ModulesOutputFolderPath = $ModulesOutputFolderPath + DocsOutputFolderPath = $DocsOutputFolderPath + } | Format-List | Out-String + if (-not (Test-Path -Path $ModuleSourceFolderPath)) { Write-Error "Source folder not found at [$ModuleSourceFolderPath]" exit 1 } $moduleSourceFolder = Get-Item -Path $ModuleSourceFolderPath - Write-Host "Module source folder: [$moduleSourceFolder]" - $moduleOutputFolder = New-Item -Path $ModulesOutputFolderPath -Name $ModuleName -ItemType Directory -Force - Write-Host "Module output folder: [$moduleOutputFolder]" - $docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force - Write-Host "Docs output folder: [$docsOutputFolder]" - Write-Host '::group::Build docs - Generate markdown help' + Write-Host '::group::Build docs - Generate markdown help - Raw' Import-PSModule -Path $ModuleOutputFolder Write-Host ($ModuleName | Get-Module) $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose @@ -97,7 +98,7 @@ $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') Write-Host "Doc file path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent - New-Item -Path $docsFolderPath -ItemType Directory -Force + $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force } # Get the MD files that are in the public functions folder and move them to the same place in the docs folder @@ -107,14 +108,13 @@ $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) Write-Host "Doc file path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent - New-Item -Path $docsFolderPath -ItemType Directory -Force + $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force } Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { $fileName = $_.Name - $hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash - Write-Host "::group:: - [$fileName] - [$hash]" + Write-Host "::group:: - [$fileName]" Show-FileContent -Path $_ } } diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a89c206..19eb61c 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -22,15 +22,9 @@ Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | Resolve-Path -Relative | Fo Write-Host '::group::Loading inputs' $env:GITHUB_REPOSITORY_NAME = $env:GITHUB_REPOSITORY -replace '.+/' $moduleName = [string]::IsNullOrEmpty($env:GITHUB_ACTION_INPUT_Name) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name -Write-Host "Module name: [$moduleName]" - $moduleSourceFolderPath = Resolve-Path -Path 'src' | Select-Object -ExpandProperty Path -Write-Host "Module source path: [$moduleSourceFolderPath]" - $modulesOutputFolderPath = Join-Path -Path . -ChildPath 'outputs/module' -Write-Host "Module output path: [$modulesOutputFolderPath]" $docsOutputFolderPath = Join-Path -Path . -ChildPath 'outputs/docs' -Write-Host "Docs output path: [$docsOutputFolderPath]" $params = @{ ModuleName = $moduleName @@ -39,4 +33,6 @@ $params = @{ DocsOutputFolderPath = $docsOutputFolderPath } +[pscustomobject]$params | Format-List | Out-String + Build-PSModuleDocumentation @params From 98f0b8be0eb3bae62e3ead26c8510b4d9c6524e4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 11:43:55 +0100 Subject: [PATCH 33/44] Refactor Build-PSModuleDocumentation.ps1 to improve output clarity; replace Write-Host with formatted output for file paths and processing details. --- scripts/helpers/Build-PSModuleDocumentation.ps1 | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index fa03a4b..32de59e 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -90,13 +90,15 @@ $PublicFunctionsFolder = Join-Path $ModuleSourceFolder.FullName 'functions\public' | Get-Item Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { $file = $_ - Write-Host "Processing: $file" + $relPath = [System.IO.Path]::GetRelativePath($DocsOutputFolder.FullName, $file.FullName) + Write-Host " - $relPath" + Write-Host " Path: $file" # find the source code file that matches the markdown file $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } - Write-Host "Found script path: $scriptPath" + Write-Host " PS1 path: $scriptPath" $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') - Write-Host "Doc file path: $docsFilePath" + Write-Host " MD path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force @@ -104,9 +106,12 @@ # Get the MD files that are in the public functions folder and move them to the same place in the docs folder Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { $file = $_ - Write-Host "Processing: $file" + $relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName) + Write-Host " - $relPath" + Write-Host " Path: $file" + $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) - Write-Host "Doc file path: $docsFilePath" + Write-Host " MD path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force From d7a1d5dc06eea9c3329d1ffb257884bc7f6ae5cb Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 11:48:50 +0100 Subject: [PATCH 34/44] Refactor Build-PSModuleDocumentation.ps1 to enhance output formatting; adjust spacing in Write-Host messages for improved readability. --- scripts/helpers/Build-PSModuleDocumentation.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index 32de59e..05ae70d 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -96,14 +96,15 @@ # find the source code file that matches the markdown file $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } - Write-Host " PS1 path: $scriptPath" + Write-Host " PS1 path: $scriptPath" $docsFilePath = ($scriptPath.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName).Replace('.ps1', '.md') - Write-Host " MD path: $docsFilePath" + Write-Host " MD path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force } - # Get the MD files that are in the public functions folder and move them to the same place in the docs folder + + Write-Host '::group::Build docs - Move markdown files from source files to docs' Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object { $file = $_ $relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName) @@ -111,12 +112,13 @@ Write-Host " Path: $file" $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) - Write-Host " MD path: $docsFilePath" + Write-Host " MD path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force } + Write-Host '────────────────────────────────────────────────────────────────────────────────' Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { $fileName = $_.Name Write-Host "::group:: - [$fileName]" From c4f38a83c521af216360bb68b4066182efe06acd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 11:49:33 +0100 Subject: [PATCH 35/44] Refactor Build-PSModuleDocumentation.ps1 to improve output formatting; adjust spacing in Write-Host messages for better alignment. --- scripts/helpers/Build-PSModuleDocumentation.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index 05ae70d..67643b2 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -92,7 +92,7 @@ $file = $_ $relPath = [System.IO.Path]::GetRelativePath($DocsOutputFolder.FullName, $file.FullName) Write-Host " - $relPath" - Write-Host " Path: $file" + Write-Host " Path: $file" # find the source code file that matches the markdown file $scriptPath = Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force | Where-Object { $_.Name -eq ($file.BaseName + '.ps1') } @@ -109,10 +109,10 @@ $file = $_ $relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName) Write-Host " - $relPath" - Write-Host " Path: $file" + Write-Host " Path: $file" $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) - Write-Host " MD path: $docsFilePath" + Write-Host " MD path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force From 5b70ce52eececff99677474f81ee995d83d92b18 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 11:51:03 +0100 Subject: [PATCH 36/44] Refactor Build-PSModuleDocumentation.ps1 to improve output formatting; adjust spacing in Write-Host messages for better alignment. --- scripts/helpers/Build-PSModuleDocumentation.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index 67643b2..da46069 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -109,10 +109,10 @@ $file = $_ $relPath = [System.IO.Path]::GetRelativePath($PublicFunctionsFolder.FullName, $file.FullName) Write-Host " - $relPath" - Write-Host " Path: $file" + Write-Host " Path: $file" $docsFilePath = ($file.FullName).Replace($PublicFunctionsFolder.FullName, $DocsOutputFolder.FullName) - Write-Host " MD path: $docsFilePath" + Write-Host " MD path: $docsFilePath" $docsFolderPath = Split-Path -Path $docsFilePath -Parent $null = New-Item -Path $docsFolderPath -ItemType Directory -Force Move-Item -Path $file.FullName -Destination $docsFilePath -Force From 4ea8c071f69af0a297326c6adfd5ddc8460d4d2c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 2 Mar 2025 12:34:56 +0100 Subject: [PATCH 37/44] Refactor Import-PSModule.ps1 to remove Write-Host for command output; streamline command listing for improved clarity. --- scripts/helpers/Import-PSModule.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 index 547bc00..76224cd 100644 --- a/scripts/helpers/Import-PSModule.ps1 +++ b/scripts/helpers/Import-PSModule.ps1 @@ -39,7 +39,7 @@ $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize | Out-String Write-Host ' - List commands' $commands = Get-Command -Module $moduleName -ListImported - Write-Host (Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String) + Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String if ($moduleName -notin $commands.Source) { throw 'Module not found' From 26567f0653544624cc875c5859d8b9fa2ce93e65 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 19:01:24 +0100 Subject: [PATCH 38/44] Add Install-PSModuleHelpers step and remove deprecated helper scripts for improved module management --- action.yml | 3 + scripts/helpers/Convert-VersionSpec.ps1 | 98 ---------------- scripts/helpers/Import-PSModule.ps1 | 47 -------- .../helpers/Resolve-PSModuleDependency.ps1 | 105 ------------------ scripts/helpers/Show-FileContent.ps1 | 32 ------ 5 files changed, 3 insertions(+), 282 deletions(-) delete mode 100644 scripts/helpers/Convert-VersionSpec.ps1 delete mode 100644 scripts/helpers/Import-PSModule.ps1 delete mode 100644 scripts/helpers/Resolve-PSModuleDependency.ps1 delete mode 100644 scripts/helpers/Show-FileContent.ps1 diff --git a/action.yml b/action.yml index 5481e4f..a9f2f9f 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,9 @@ inputs: runs: using: composite steps: + - name: Install-PSModuleHelpers + uses: PSModule/Install-PSModuleHelpers@v1 + - name: Document-PSModule shell: pwsh env: diff --git a/scripts/helpers/Convert-VersionSpec.ps1 b/scripts/helpers/Convert-VersionSpec.ps1 deleted file mode 100644 index 14357a8..0000000 --- a/scripts/helpers/Convert-VersionSpec.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -function Convert-VersionSpec { - <# - .SYNOPSIS - Converts legacy version parameters into a NuGet version range string. - - .DESCRIPTION - This function takes minimum, maximum, or required version parameters - and constructs a NuGet-compatible version range string. - - - If `RequiredVersion` is specified, the output is an exact match range. - - If both `MinimumVersion` and `MaximumVersion` are provided, - an inclusive range is returned. - - If only `MinimumVersion` is provided, it returns a minimum-inclusive range. - - If only `MaximumVersion` is provided, it returns an upper-bound range. - - If no parameters are provided, `$null` is returned. - - .EXAMPLE - Convert-VersionSpec -MinimumVersion "1.0.0" -MaximumVersion "2.0.0" - - Output: - ```powershell - [1.0.0,2.0.0] - ``` - - Returns an inclusive version range from 1.0.0 to 2.0.0. - - .EXAMPLE - Convert-VersionSpec -RequiredVersion "1.5.0" - - Output: - ```powershell - [1.5.0] - ``` - - Returns an exact match for version 1.5.0. - - .EXAMPLE - Convert-VersionSpec -MinimumVersion "1.0.0" - - Output: - ```powershell - [1.0.0, ] - ``` - - Returns a minimum-inclusive version range starting at 1.0.0. - - .EXAMPLE - Convert-VersionSpec -MaximumVersion "2.0.0" - - Output: - ```powershell - (, 2.0.0] - ``` - - Returns an upper-bound range up to version 2.0.0. - - .OUTPUTS - string - - .NOTES - The NuGet version range string based on the provided parameters. - The returned string follows NuGet versioning syntax. - - .LINK - https://psmodule.io/Convert/Functions/Convert-VersionSpec - #> - [OutputType([string])] - [CmdletBinding()] - param( - # The minimum version for the range. If specified alone, the range is open-ended upwards. - [Parameter()] - [string] $MinimumVersion, - - # The maximum version for the range. If specified alone, the range is open-ended downwards. - [Parameter()] - [string] $MaximumVersion, - - # Specifies an exact required version. If set, an exact version range is returned. - [Parameter()] - [string] $RequiredVersion - ) - - if ($RequiredVersion) { - # Use exact match in bracket notation. - return "[$RequiredVersion]" - } elseif ($MinimumVersion -and $MaximumVersion) { - # Both bounds provided; both are inclusive. - return "[$MinimumVersion,$MaximumVersion]" - } elseif ($MinimumVersion) { - # Only a minimum is provided. Use a minimum-inclusive range. - return "[$MinimumVersion, ]" - } elseif ($MaximumVersion) { - # Only a maximum is provided; lower bound open. - return "(, $MaximumVersion]" - } else { - return $null - } -} diff --git a/scripts/helpers/Import-PSModule.ps1 b/scripts/helpers/Import-PSModule.ps1 deleted file mode 100644 index 76224cd..0000000 --- a/scripts/helpers/Import-PSModule.ps1 +++ /dev/null @@ -1,47 +0,0 @@ -function Import-PSModule { - <# - .SYNOPSIS - Imports a build PS module. - - .DESCRIPTION - Imports a build PS module. - - .EXAMPLE - Import-PSModule -SourceFolderPath $ModuleFolderPath -ModuleName $moduleName - - Imports a module located at $ModuleFolderPath with the name $moduleName. - #> - [CmdletBinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - param( - # Path to the folder where the module source code is located. - [Parameter(Mandatory)] - [string] $Path - ) - - $moduleName = Split-Path -Path $Path -Leaf - $manifestFilePath = Join-Path -Path $Path "$moduleName.psd1" - - Write-Host " - Manifest file path: [$manifestFilePath]" - Resolve-PSModuleDependency -ManifestFilePath $manifestFilePath - - Write-Host ' - List installed modules' - Get-InstalledPSResource | Format-Table -AutoSize | Out-String - - Write-Host " - Importing module [$moduleName] v999" - Import-Module $Path - - Write-Host ' - List loaded modules' - $availableModules = Get-Module -ListAvailable -Refresh -Verbose:$false - $availableModules | Select-Object Name, Version, Path | Sort-Object Name | Format-Table -AutoSize | Out-String - Write-Host ' - List commands' - $commands = Get-Command -Module $moduleName -ListImported - Get-Command -Module $moduleName -ListImported | Format-Table -AutoSize | Out-String - - if ($moduleName -notin $commands.Source) { - throw 'Module not found' - } -} diff --git a/scripts/helpers/Resolve-PSModuleDependency.ps1 b/scripts/helpers/Resolve-PSModuleDependency.ps1 deleted file mode 100644 index edb3c29..0000000 --- a/scripts/helpers/Resolve-PSModuleDependency.ps1 +++ /dev/null @@ -1,105 +0,0 @@ -function Resolve-PSModuleDependency { - <# - .SYNOPSIS - Resolves module dependencies from a manifest file using Install-PSResource. - - .DESCRIPTION - Reads a module manifest (PSD1) and for each required module converts the old - Install-Module parameters (MinimumVersion, MaximumVersion, RequiredVersion) - into a single NuGet version range string for Install-PSResource's –Version parameter. - (Note: If RequiredVersion is set, that value takes precedence.) - - .EXAMPLE - Resolve-PSModuleDependency -ManifestFilePath 'C:\MyModule\MyModule.psd1' - Installs all modules defined in the manifest file, following PSModuleInfo structure. - - .NOTES - Should later be adapted to support both pre-reqs, and dependencies. - Should later be adapted to take 4 parameters sets: specific version ("requiredVersion" | "GUID"), latest version ModuleVersion, - and latest version within a range MinimumVersion - MaximumVersion. - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSAvoidUsingWriteHost', '', Scope = 'Function', - Justification = 'Want to just write to the console, not the pipeline.' - )] - [CmdletBinding()] - param( - # The path to the manifest file. - [Parameter(Mandatory)] - [string] $ManifestFilePath - ) - - Write-Host 'Resolving dependencies' - $manifest = Import-PowerShellDataFile -Path $ManifestFilePath - Write-Host " - Reading [$ManifestFilePath]" - Write-Host " - Found [$($manifest.RequiredModules.Count)] module(s) to install" - - foreach ($requiredModule in $manifest.RequiredModules) { - # Build parameters for Install-PSResource (new version spec). - $psResourceParams = @{ - TrustRepository = $true - } - # Build parameters for Import-Module (legacy version spec). - $importParams = @{ - Force = $true - Verbose = $false - } - - if ($requiredModule -is [string]) { - $psResourceParams.Name = $requiredModule - $importParams.Name = $requiredModule - } else { - $psResourceParams.Name = $requiredModule.ModuleName - $importParams.Name = $requiredModule.ModuleName - - # Convert legacy version info for Install-PSResource. - $versionSpec = Convert-VersionSpec ` - -MinimumVersion $requiredModule.ModuleVersion ` - -MaximumVersion $requiredModule.MaximumVersion ` - -RequiredVersion $requiredModule.RequiredVersion - - if ($versionSpec) { - $psResourceParams.Version = $versionSpec - } - - # For Import-Module, keep the original version parameters. - if ($requiredModule.ModuleVersion) { - $importParams.MinimumVersion = $requiredModule.ModuleVersion - } - if ($requiredModule.RequiredVersion) { - $importParams.RequiredVersion = $requiredModule.RequiredVersion - } - if ($requiredModule.MaximumVersion) { - $importParams.MaximumVersion = $requiredModule.MaximumVersion - } - } - - Write-Host " - [$($psResourceParams.Name)] - Installing module with Install-PSResource using version spec: $($psResourceParams.Version)" - $VerbosePreferenceOriginal = $VerbosePreference - $VerbosePreference = 'SilentlyContinue' - $retryCount = 5 - $retryDelay = 10 - for ($i = 0; $i -lt $retryCount; $i++) { - try { - Install-PSResource @psResourceParams - break - } catch { - Write-Warning "Installation of $($psResourceParams.Name) failed with error: $_" - if ($i -eq $retryCount - 1) { - throw - } - Write-Warning "Retrying in $retryDelay seconds..." - Start-Sleep -Seconds $retryDelay - } - } - $VerbosePreference = $VerbosePreferenceOriginal - - Write-Host " - [$($importParams.Name)] - Importing module with legacy version spec" - $VerbosePreferenceOriginal = $VerbosePreference - $VerbosePreference = 'SilentlyContinue' - Import-Module @importParams - $VerbosePreference = $VerbosePreferenceOriginal - Write-Host " - [$($importParams.Name)] - Done" - } - Write-Host ' - Resolving dependencies - Done' -} diff --git a/scripts/helpers/Show-FileContent.ps1 b/scripts/helpers/Show-FileContent.ps1 deleted file mode 100644 index 6ad6295..0000000 --- a/scripts/helpers/Show-FileContent.ps1 +++ /dev/null @@ -1,32 +0,0 @@ -function Show-FileContent { - <# - .SYNOPSIS - Prints the content of a file with line numbers in front of each line. - - .DESCRIPTION - Prints the content of a file with line numbers in front of each line. - - .EXAMPLE - $Path = 'C:\Utilities\Show-FileContent.ps1' - Show-FileContent -Path $Path - - Shows the content of the file with line numbers in front of each line. - #> - [CmdletBinding()] - param ( - # The path to the file to show the content of. - [Parameter(Mandatory)] - [string] $Path - ) - - $content = Get-Content -Path $Path - $lineNumber = 1 - $columnSize = $content.Count.ToString().Length - # Foreach line print the line number in front of the line with [ ] around it. - # The linenumber should dynamically adjust to the number of digits with the length of the file. - foreach ($line in $content) { - $lineNumberFormatted = $lineNumber.ToString().PadLeft($columnSize) - Write-Host "[$lineNumberFormatted] $line" - $lineNumber++ - } -} From e48d8171f81eec70b2fc975702a6ec0f2f266816 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Wed, 5 Mar 2025 20:01:53 +0100 Subject: [PATCH 39/44] Refactor Build-PSModuleDocumentation.ps1 to replace Import-PSModule with Install-PSModule for improved module installation process. --- scripts/helpers/Build-PSModuleDocumentation.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/helpers/Build-PSModuleDocumentation.ps1 b/scripts/helpers/Build-PSModuleDocumentation.ps1 index da46069..d979beb 100644 --- a/scripts/helpers/Build-PSModuleDocumentation.ps1 +++ b/scripts/helpers/Build-PSModuleDocumentation.ps1 @@ -46,7 +46,7 @@ $docsOutputFolder = New-Item -Path $DocsOutputFolderPath -ItemType Directory -Force Write-Host '::group::Build docs - Generate markdown help - Raw' - Import-PSModule -Path $ModuleOutputFolder + Install-PSModule -Path $ModuleOutputFolder Write-Host ($ModuleName | Get-Module) $null = New-MarkdownHelp -Module $ModuleName -OutputFolder $DocsOutputFolder -Force -Verbose Get-ChildItem -Path $DocsOutputFolder -Recurse -Force -Include '*.md' | ForEach-Object { From 643013ee8ea3b630200159f4ab429a608084fd8f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Thu, 6 Mar 2025 17:20:13 +0100 Subject: [PATCH 40/44] Update action.yml to change default WorkingDirectory to '.' for improved script execution context --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a9f2f9f..74a04d3 100644 --- a/action.yml +++ b/action.yml @@ -27,7 +27,7 @@ inputs: WorkingDirectory: description: The working directory where the script will run from. required: false - default: ${{ github.workspace }} + default: '.' runs: using: composite From caad0c6769057e7b9954d53e4c3d87431431e45e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 8 Mar 2025 11:57:07 +0100 Subject: [PATCH 41/44] Remove GITHUB_TOKEN environment variable from Auto-Release workflow for improved security. --- .github/workflows/Auto-Release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index 1a580b8..db872f5 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -30,5 +30,3 @@ jobs: - name: Auto-Release uses: PSModule/Auto-Release@v1 - env: - GITHUB_TOKEN: ${{ github.token }} From 25b8d499f8d9163be4581f4128de72e07d8f3eee Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 9 Mar 2025 16:15:01 +0100 Subject: [PATCH 42/44] Enhance module installation process with retry logic and improved error handling --- scripts/main.ps1 | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 19eb61c..608fe59 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -8,8 +8,24 @@ param() $PSStyle.OutputRendering = 'Ansi' 'platyPS' | ForEach-Object { - Install-PSResource -Name $_ -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery - Import-Module -Name $_ + $name = $_ + Write-Output "Installing module: $name" + $retryCount = 5 + $retryDelay = 10 + for ($i = 0; $i -lt $retryCount; $i++) { + try { + Install-PSResource -Name $name -WarningAction SilentlyContinue -TrustRepository -Repository PSGallery + break + } catch { + Write-Warning "Installation of $($psResourceParams.Name) failed with error: $_" + if ($i -eq $retryCount - 1) { + throw + } + Write-Warning "Retrying in $retryDelay seconds..." + Start-Sleep -Seconds $retryDelay + } + } + Import-Module -Name $name } $path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers') | Get-Item | Resolve-Path -Relative From d1f92248bb621d23eab41af5faaaa6392f66da48 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 18 Apr 2025 01:55:47 +0200 Subject: [PATCH 43/44] Update README.md and action.yml to enhance documentation and streamline inputs for Document-PSModule action --- README.md | 34 +++++++++++++++++++++++++++++++--- action.yml | 15 --------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d560186..ce432ef 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,45 @@ -# Template-Action +# Document-PSModule (by PSModule) -A template repository for GitHub Actions +A GitHub Action that automates the generation of documentation for PowerShell modules using markdown help files. + +This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the +[Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. + +## Details + +This action: +- Installs necessary modules, including `platyPS` for documentation generation. +- Loads helper scripts required by the documentation process. +- Generates markdown documentation from PowerShell module files. +- Ensures markdown documentation is properly formatted, with correctly tagged PowerShell code blocks. +- Adjusts markdown file paths to mirror the structure of the source PowerShell module files. +- Outputs organized markdown documentation suitable for publishing or distribution. ## Usage +Include this action in your workflow to automatically build and structure documentation for your PowerShell module. + ### Inputs +| Input | Description | Required | Default | +|--------------------|-----------------------------------------------|----------|-------------| +| `Name` | Name of the module to document. | No | | +| `WorkingDirectory` | Directory from which the script will execute. | No | `.` | + ### Secrets +This action does not require any secrets. + ### Outputs +This action does not have defined outputs. + ### Example ```yaml -Example here +- name: Document PowerShell Module + uses: PSModule/Document-PSModule@v1 + with: + Name: 'MyModule' + WorkingDirectory: './module-directory' ``` diff --git a/action.yml b/action.yml index 74a04d3..e5b49d8 100644 --- a/action.yml +++ b/action.yml @@ -9,21 +9,6 @@ inputs: Name: description: Name of the module to process. required: false - Debug: - description: Enable debug output. - required: false - default: 'false' - Verbose: - description: Enable verbose output. - required: false - default: 'false' - Version: - description: Specifies the version of the GitHub module to be installed. The value must be an exact version. - required: false - Prerelease: - description: Allow prerelease versions if available. - required: false - default: 'false' WorkingDirectory: description: The working directory where the script will run from. required: false From ab2e68d7b66e9976b300c2a82faae03ef881359a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Fri, 18 Apr 2025 04:02:35 +0200 Subject: [PATCH 44/44] Fix Markdown casing in README.md for consistency --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ce432ef..9fb3dfe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Document-PSModule (by PSModule) -A GitHub Action that automates the generation of documentation for PowerShell modules using markdown help files. +A GitHub Action that automates the generation of documentation for PowerShell modules using Markdown help files. This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. @@ -10,10 +10,10 @@ This GitHub Action is a part of the [PSModule framework](https://github.com/PSMo This action: - Installs necessary modules, including `platyPS` for documentation generation. - Loads helper scripts required by the documentation process. -- Generates markdown documentation from PowerShell module files. -- Ensures markdown documentation is properly formatted, with correctly tagged PowerShell code blocks. -- Adjusts markdown file paths to mirror the structure of the source PowerShell module files. -- Outputs organized markdown documentation suitable for publishing or distribution. +- Generates Markdown documentation from PowerShell module files. +- Ensures Markdown documentation is properly formatted, with correctly tagged PowerShell code blocks. +- Adjusts Markdown file paths to mirror the structure of the source PowerShell module files. +- Outputs organized Markdown documentation suitable for publishing or distribution. ## Usage