Skip to content

Commit

Permalink
refactor: Set environment variables instead of referencing job output…
Browse files Browse the repository at this point in the history
… variables
  • Loading branch information
deadlydog committed Oct 22, 2023
1 parent 6cad206 commit 03659c0
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions .github/workflows/build-test-and-deploy-powershell-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,58 @@ 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:
uses: ./.github/workflows/build-and-test-powershell-module.yml
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
Expand Down Expand Up @@ -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."
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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."
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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."
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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."
Expand All @@ -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
Expand All @@ -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

0 comments on commit 03659c0

Please sign in to comment.