diff --git a/.github/workflows/build-test-and-deploy-powershell-module.yml b/.github/workflows/build-test-and-deploy-powershell-module.yml index ad7d258..0f491c4 100644 --- a/.github/workflows/build-test-and-deploy-powershell-module.yml +++ b/.github/workflows/build-test-and-deploy-powershell-module.yml @@ -16,6 +16,10 @@ on: env: artifactsDirectoryPath: './artifacts' + powershellModuleName: 'Retrieved dynamically from build workflow output' + prereleaseModuleArtifactName: 'Retrieved dynamically from build workflow output' + stableModuleArtifactName: 'Retrieved dynamically from build workflow output' + deployFilesArtifactName: 'Retrieved dynamically from build workflow output' jobs: run-build-and-test: @@ -23,29 +27,47 @@ jobs: with: versionNumber: ${{ github.event.inputs.versionNumber }} - publish-prerelease-module: + set-env-variables-from-build-output: needs: run-build-and-test runs-on: ubuntu-latest + steps: + - name: Set environment variables from build output variables + shell: pwsh + run: | + [string] $powershellModuleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + [string] $prereleaseModuleArtifactName = '${{ needs.run-build-and-test.outputs.prereleaseModuleArtifactName }}' + [string] $stableModuleArtifactName = '${{ needs.run-build-and-test.outputs.stableModuleArtifactName }}' + [string] $deployFilesArtifactName = '${{ needs.run-build-and-test.outputs.deployFilesArtifactName }}' + + Write-Output "Setting environment variables." + "powerShellModuleName=$powershellModuleName" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + "prereleaseModuleArtifactName=$prereleaseModuleArtifactName" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + "stableModuleArtifactName=$stableModuleArtifactName" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + "deployFilesArtifactName=$deployFilesArtifactName" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append + + publish-prerelease-module: + needs: set-env-variables-from-build-output + runs-on: ubuntu-latest outputs: prereleaseVersionNumber: ${{ steps.output-version-number.outputs.prereleaseVersionNumber }} steps: - name: Download prerelease module artifact uses: actions/download-artifact@v3 with: - name: ${{ needs.run-build-and-test.outputs.prereleaseModuleArtifactName }} + name: ${{ env.prereleaseModuleArtifactName }} path: ${{ env.artifactsDirectoryPath }} - name: Publish prerelease PowerShell module shell: pwsh run: | - [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}" + [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$Env: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/${{ needs.run-build-and-test.outputs.powerShellModuleName }}/${{ needs.run-build-and-test.outputs.powerShellModuleName }}.psd1" + [string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName/$Env:powerShellModuleName.psd1" Write-Output "Reading module manifest from '$moduleManifestPath'." [hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression [string] $versionNumber = $manifest.ModuleVersion @@ -73,7 +95,7 @@ jobs: - name: Install prerelease module from PowerShell Gallery shell: pwsh run: | - [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + [string] $moduleName = $Env:powerShellModuleName [string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}' Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery." @@ -82,7 +104,7 @@ jobs: - name: Download deploy files artifact uses: actions/download-artifact@v3 with: - name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}} + name: ${{ env.deployFilesArtifactName}} path: ${{ env.artifactsDirectoryPath }} - name: Run smoke tests @@ -101,7 +123,7 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + Get-Module -Name $Env:powerShellModuleName test-prerelease-module-in-windows-powershell: needs: publish-prerelease-module @@ -114,7 +136,7 @@ jobs: - name: Install prerelease module from PowerShell Gallery shell: powershell run: | - [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + [string] $moduleName = $Env:powerShellModuleName [string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}' Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery." @@ -123,7 +145,7 @@ jobs: - name: Download deploy files artifact from triggered workflow uses: actions/download-artifact@v3 with: - name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}} + name: ${{ env.deployFilesArtifactName}} path: ${{ env.artifactsDirectoryPath }} - name: Run smoke tests @@ -142,7 +164,7 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + Get-Module -Name $Env:powerShellModuleName publish-stable-module: needs: [test-prerelease-module-in-pwsh, test-prerelease-module-in-windows-powershell] @@ -154,20 +176,20 @@ jobs: - name: Download stable module artifact from triggered workflow uses: actions/download-artifact@v3 with: - name: ${{ needs.run-build-and-test.outputs.stableModuleArtifactName}} + name: ${{ env.stableModuleArtifactName}} path: ${{ env.artifactsDirectoryPath }} - name: Publish stable PowerShell module shell: pwsh run: | - [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/${{ needs.run-build-and-test.outputs.powerShellModuleName }}" + [string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$Env: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/${{ needs.run-build-and-test.outputs.powerShellModuleName }}/${{ needs.run-build-and-test.outputs.powerShellModuleName }}.psd1" + [string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$Env:powerShellModuleName/$Env:powerShellModuleName.psd1" Write-Output "Reading module manifest from '$moduleManifestPath'." [hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression [string] $versionNumber = $manifest.ModuleVersion @@ -193,7 +215,7 @@ jobs: - name: Install stable module from PowerShell Gallery shell: pwsh run: | - [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + [string] $moduleName = $Env:powerShellModuleName [string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}' Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery." @@ -202,7 +224,7 @@ jobs: - name: Download deploy files artifact from triggered workflow uses: actions/download-artifact@v3 with: - name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}} + name: ${{ env.deployFilesArtifactName}} path: ${{ env.artifactsDirectoryPath }} - name: Run smoke tests @@ -221,7 +243,7 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + Get-Module -Name $Env:powerShellModuleName test-stable-module-in-windows-powershell: needs: publish-stable-module @@ -234,7 +256,7 @@ jobs: - name: Install stable module from PowerShell Gallery shell: powershell run: | - [string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + [string] $moduleName = $Env:powerShellModuleName [string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}' Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery." @@ -243,7 +265,7 @@ jobs: - name: Download deploy files artifact from triggered workflow uses: actions/download-artifact@v3 with: - name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}} + name: ${{ env.deployFilesArtifactName}} path: ${{ env.artifactsDirectoryPath }} - name: Run smoke tests @@ -262,4 +284,4 @@ jobs: Invoke-Pester -Configuration $pesterConfig Write-Output "Displaying the installed module version that was used for the smoke tests." - Get-Module -Name '${{ needs.run-build-and-test.outputs.powerShellModuleName }}' + Get-Module -Name $Env:powerShellModuleName