From 353fdd7a10d1830645ec3ea384bf6d66ca56bdd8 Mon Sep 17 00:00:00 2001 From: deadlydog Date: Sun, 22 Oct 2023 15:13:13 -0600 Subject: [PATCH] refactor: Have deploy grab the module name dynamically instead of hardcoding it in multiple places --- .../build-and-test-powershell-module.yml | 6 ++++- ...uild-test-and-deploy-powershell-module.yml | 25 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-and-test-powershell-module.yml b/.github/workflows/build-and-test-powershell-module.yml index 074d9ee..241a46c 100644 --- a/.github/workflows/build-and-test-powershell-module.yml +++ b/.github/workflows/build-and-test-powershell-module.yml @@ -15,6 +15,9 @@ on: type: string default: '' outputs: + powerShellModuleName: + description: 'The name of the PowerShell module being built.' + value: ${{ jobs.build-and-test.outputs.powerShellModuleName }} prereleaseModuleArtifactName: description: 'The name of the prerelease module artifact created by the build.' value: ${{ jobs.build-and-test.outputs.prereleaseModuleArtifactName }} @@ -26,7 +29,7 @@ on: value: ${{ jobs.build-and-test.outputs.deployFilesArtifactName }} env: - powerShellModuleName: 'tiPS' # Must match the name in the deployment workflow. + powerShellModuleName: 'tiPS' powerShellModuleDirectoryPath: './src/tiPS' powerShellModuleManifestFileName: 'tiPS.psd1' deployFilesDirectoryPath: './deploy' @@ -42,6 +45,7 @@ jobs: build-and-test: runs-on: windows-latest # Use Windows agent to ensure dotnet.exe is available to build C# assemblies. outputs: + powerShellModuleName: ${{ env.powerShellModuleName }} prereleaseModuleArtifactName: ${{ env.prereleaseModuleArtifactName }} stableModuleArtifactName: ${{ env.stableModuleArtifactName }} deployFilesArtifactName: ${{ env.deployFilesArtifactName }} diff --git a/.github/workflows/build-test-and-deploy-powershell-module.yml b/.github/workflows/build-test-and-deploy-powershell-module.yml index ff81850..ed1a8f8 100644 --- a/.github/workflows/build-test-and-deploy-powershell-module.yml +++ b/.github/workflows/build-test-and-deploy-powershell-module.yml @@ -15,7 +15,6 @@ on: default: '' env: - powerShellModuleName: 'tiPS' # Must match the name in the build workflow. artifactsDirectoryPath: './artifacts' jobs: @@ -39,14 +38,14 @@ jobs: - name: Publish prerelease PowerShell module shell: pwsh run: | - [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName" + [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}" Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose - name: Make prerelease version number available to downstream jobs id: output-version-number shell: pwsh run: | - [string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName/$Env:powerShellModuleName.psd1" + [string] $moduleManifestPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}.psd1" Write-Output "Reading module manifest from '$moduleManifestPath'." [hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression [string] $versionNumber = $manifest.ModuleVersion @@ -74,7 +73,7 @@ jobs: - name: Install prerelease module from PowerShell Gallery shell: pwsh run: | - [string] $moduleName = $Env:powerShellModuleName + [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' [string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}' Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery." @@ -102,7 +101,7 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name $Env:powerShellModuleName + Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' test-prerelease-module-in-windows-powershell: needs: publish-prerelease-module @@ -115,7 +114,7 @@ jobs: - name: Install prerelease module from PowerShell Gallery shell: powershell run: | - [string] $moduleName = $Env:powerShellModuleName + [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' [string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}' Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery." @@ -143,7 +142,7 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name $Env:powerShellModuleName + Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' publish-stable-module: needs: [test-prerelease-module-in-pwsh, test-prerelease-module-in-windows-powershell] @@ -161,14 +160,14 @@ jobs: - name: Publish stable PowerShell module shell: pwsh run: | - [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName" + [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}" Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose - name: Make stable version number available to downstream jobs id: output-version-number shell: pwsh run: | - [string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName/$Env:powerShellModuleName.psd1" + [string] $moduleManifestPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}/${{ needs.run-build-and-test.outputs.powerShellModuleName }}.psd1" Write-Output "Reading module manifest from '$moduleManifestPath'." [hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression [string] $versionNumber = $manifest.ModuleVersion @@ -194,7 +193,7 @@ jobs: - name: Install stable module from PowerShell Gallery shell: pwsh run: | - [string] $moduleName = $Env:powerShellModuleName + [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' [string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}' Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery." @@ -222,7 +221,7 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name $Env:powerShellModuleName + Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' test-stable-module-in-windows-powershell: needs: publish-stable-module @@ -235,7 +234,7 @@ jobs: - name: Install stable module from PowerShell Gallery shell: powershell run: | - [string] $moduleName = $Env:powerShellModuleName + [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' [string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}' Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery." @@ -263,4 +262,4 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name $Env:powerShellModuleName + Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'