Skip to content

Commit e1dabc0

Browse files
committed
ci: Update deployments to only create one module artifact
1 parent 63e66b0 commit e1dabc0

File tree

4 files changed

+106
-178
lines changed

4 files changed

+106
-178
lines changed

.github/workflows/build-and-test-powershell-module.yml

+36-50
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,18 @@ on:
2020
powerShellModuleName:
2121
description: 'The name of the PowerShell module being built.'
2222
value: ${{ jobs.build-and-test.outputs.powerShellModuleName }}
23-
prereleaseModuleArtifactName:
24-
description: 'The name of the prerelease module artifact created by the build.'
25-
value: ${{ jobs.build-and-test.outputs.prereleaseModuleArtifactName }}
26-
stableModuleArtifactName:
27-
description: 'The name of the stable module artifact created by the build.'
28-
value: ${{ jobs.build-and-test.outputs.stableModuleArtifactName }}
23+
stableVersionNumber:
24+
description: 'The stable version number of the PowerShell module created by the build.'
25+
value: ${{ jobs.build-and-test.outputs.stableVersionNumber }}
26+
prereleaseVersionNumber:
27+
description: 'The full prerelease version number of the PowerShell module created by the build.'
28+
value: ${{ jobs.build-and-test.outputs.prereleaseVersionNumber }}
29+
prereleaseVersionLabel:
30+
description: 'The prerelease label of the PowerShell module created by the build.'
31+
value: ${{ jobs.build-and-test.outputs.prereleaseVersionLabel }}
32+
moduleArtifactName:
33+
description: 'The name of the module artifact created by the build.'
34+
value: ${{ jobs.build-and-test.outputs.moduleArtifactName }}
2935
deployFilesArtifactName:
3036
description: 'The name of the deploy files artifact created by the build.'
3137
value: ${{ jobs.build-and-test.outputs.deployFilesArtifactName }}
@@ -34,10 +40,8 @@ env:
3440
powerShellModuleName: 'ScriptModuleRepositoryTemplate'
3541
powerShellModuleDirectoryPath: './src/ScriptModuleRepositoryTemplate'
3642
deployFilesDirectoryPath: './deploy'
37-
prereleaseModuleArtifactName: 'PrereleaseModuleArtifact'
38-
prereleaseModuleArtifactDirectoryPath: './artifacts/Prerelease'
39-
stableModuleArtifactName: 'StableModuleArtifact'
40-
stableModuleArtifactDirectoryPath: './artifacts/Stable'
43+
moduleArtifactName: 'ModuleArtifact'
44+
moduleArtifactDirectoryPath: './artifacts/Module'
4145
deployFilesArtifactName: 'DeployFilesArtifact'
4246
deployFilesArtifactDirectoryPath: './artifacts/deploy'
4347

@@ -46,8 +50,10 @@ jobs:
4650
runs-on: windows-latest # Use Windows agent to ensure dotnet.exe is available to build C# assemblies, if required.
4751
outputs:
4852
powerShellModuleName: ${{ env.powerShellModuleName }}
49-
prereleaseModuleArtifactName: ${{ env.prereleaseModuleArtifactName }}
50-
stableModuleArtifactName: ${{ env.stableModuleArtifactName }}
53+
stableVersionNumber: ${{ steps.version-number.outputs.majorMinorPatch }}
54+
prereleaseVersionNumber: ${{ steps.version-number.outputs.majorMinorPatch }}-${{ steps.version-number.outputs.prereleaseLabel }}
55+
prereleaseVersionLabel: ${{ steps.version-number.outputs.prereleaseLabel}}
56+
moduleArtifactName: ${{ env.moduleArtifactName }}
5157
deployFilesArtifactName: ${{ env.deployFilesArtifactName }}
5258
steps:
5359
- name: Checkout the repo source code
@@ -72,6 +78,7 @@ jobs:
7278
uses: gittools/actions/gitversion/execute@v0
7379

7480
- name: Determine the new version number
81+
id: version-number
7582
shell: pwsh
7683
run: |
7784
[string] $newVersionNumber = '${{ steps.git-version.outputs.majorMinorPatch }}'
@@ -91,9 +98,9 @@ jobs:
9198
# PowerShell prerelease labels can only contain the characters 'a-zA-Z0-9', so sanitize it if needed.
9299
$newVersionNumberPrereleaseLabel = $prereleaseLabel -replace '[^a-zA-Z0-9]', ''
93100
94-
Write-Output "Setting new environment variables 'NewVersionNumberMajorMinorPatch=$newVersionNumber' and 'NewVersionNumberPrereleaseLabel=$newVersionNumberPrereleaseLabel'."
95-
"NewVersionNumberMajorMinorPatch=$newVersionNumber" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
96-
"NewVersionNumberPrereleaseLabel=$newVersionNumberPrereleaseLabel" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
101+
Write-Output "Setting step output variables 'majorMinorPatch=$newVersionNumber' and 'prereleaseLabel=$newVersionNumberPrereleaseLabel'."
102+
"majorMinorPatch=$newVersionNumber" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
103+
"prereleaseLabel=$newVersionNumberPrereleaseLabel" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
97104
98105
- name: Run PowerShell linter with PSScriptAnalyzer
99106
shell: pwsh
@@ -132,40 +139,25 @@ jobs:
132139
min-coverage-overall: 60
133140
min-coverage-changed-files: 60
134141

135-
- name: Create Stable and Prerelease module artifacts
142+
- name: Create the module artifact
136143
shell: pwsh
137144
run: |
138145
Write-Output "Reading in environment variables."
139146
[string] $moduleName = $Env:powerShellModuleName
140147
[string] $moduleDirectoryPath = $Env:powerShellModuleDirectoryPath
141148
[string] $moduleManifestFileName = $moduleName + '.psd1'
142-
[string] $prereleaseArtifactModuleDirectoryPath = Join-Path -Path $Env:prereleaseModuleArtifactDirectoryPath -ChildPath $moduleName
143-
[string] $stableArtifactModuleDirectoryPath = Join-Path -Path $Env:stableModuleArtifactDirectoryPath -ChildPath $moduleName
144-
[string] $newVersionNumber = $Env:NewVersionNumberMajorMinorPatch
145-
[string] $newVersionNumberPrereleaseLabel = $Env:NewVersionNumberPrereleaseLabel
149+
[string] $moduleManifestFilePath = Join-Path -Path $moduleDirectoryPath -ChildPath $moduleManifestFileName
150+
[string] $moduleArtifactDirectoryPath = Join-Path -Path $Env:moduleArtifactDirectoryPath -ChildPath $moduleName
151+
[string] $newVersionNumber = '${{ steps.version-number.outputs.majorMinorPatch}}'
146152
147-
Write-Output "Copying the module files to the Prerelease artifact directory '$prereleaseArtifactModuleDirectoryPath'."
148-
Copy-Item -Path $moduleDirectoryPath -Destination $prereleaseArtifactModuleDirectoryPath -Exclude '*.Tests.ps1' -Recurse -Force
153+
Write-Output "Updating the version number of the module manifest file '$moduleManifestFilePath' to '$newVersionNumber'."
154+
Update-ModuleManifest -Path $moduleManifestFilePath -ModuleVersion $newVersionNumber
149155
150-
Write-Output "Copying the module files to the Stable artifact directory '$stableArtifactModuleDirectoryPath'."
151-
Copy-Item -Path $moduleDirectoryPath -Destination $stableArtifactModuleDirectoryPath -Exclude '*.Tests.ps1' -Recurse -Force
156+
Write-Output "Testing the module manifest file '$moduleManifestFilePath' to ensure it is valid."
157+
Test-ModuleManifest -Path $moduleManifestFilePath
152158
153-
Write-Output "Determining what the module manifest file paths are."
154-
[string] $manifestFilePath = Join-Path -Path $moduleDirectoryPath -ChildPath $moduleManifestFileName
155-
[string] $prereleaseManifestFilePath = Join-Path -Path $prereleaseArtifactModuleDirectoryPath -ChildPath $moduleManifestFileName
156-
[string] $stableManifestFilePath = Join-Path -Path $stableArtifactModuleDirectoryPath -ChildPath $moduleManifestFileName
157-
158-
Write-Output "Updating the prerelease manifest's version number to '$newVersionNumber-$newVersionNumberPrereleaseLabel'."
159-
Update-ModuleManifest -Path $prereleaseManifestFilePath -ModuleVersion $newVersionNumber -Prerelease $newVersionNumberPrereleaseLabel
160-
161-
Write-Output "Updating the stable manifest's version number to '$newVersionNumber'."
162-
Update-ModuleManifest -Path $stableManifestFilePath -ModuleVersion $newVersionNumber
163-
164-
Write-Output "Testing the Prerelease manifest file '$prereleaseManifestFilePath' to ensure it is valid."
165-
Test-ModuleManifest -Path $prereleaseManifestFilePath
166-
167-
Write-Output "Testing the Stable manifest file '$stableManifestFilePath' to ensure it is valid."
168-
Test-ModuleManifest -Path $stableManifestFilePath
159+
Write-Output "Copying the module files to the module artifact directory '$moduleArtifactDirectoryPath'."
160+
Copy-Item -Path $moduleDirectoryPath -Destination $moduleArtifactDirectoryPath -Exclude '*.Tests.ps1' -Recurse -Force
169161
170162
- name: Create deploy files artifact
171163
shell: pwsh
@@ -181,7 +173,7 @@ jobs:
181173
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
182174
shell: pwsh
183175
run: |
184-
[string] $newVersionNumber = $Env:NewVersionNumberMajorMinorPatch
176+
[string] $newVersionNumber = '${{ steps.version-number.outputs.majorMinorPatch}}'
185177
[string] $newVersionTag = "v$newVersionNumber"
186178
187179
# To avoid a 403 error on 'git push', ensure you have granted your GitHub Actions workflow read/write permission.
@@ -192,17 +184,11 @@ jobs:
192184
& git tag $newVersionTag
193185
& git push origin $newVersionTag
194186
195-
- name: Upload prerelease module artifact
196-
uses: actions/upload-artifact@v4
197-
with:
198-
name: ${{ env.prereleaseModuleArtifactName }}
199-
path: ${{ env.prereleaseModuleArtifactDirectoryPath }}
200-
201-
- name: Upload stable module artifact
187+
- name: Upload module artifact
202188
uses: actions/upload-artifact@v4
203189
with:
204-
name: ${{ env.stableModuleArtifactName }}
205-
path: ${{ env.stableModuleArtifactDirectoryPath }}
190+
name: ${{ env.moduleArtifactName }}
191+
path: ${{ env.moduleArtifactDirectoryPath }}
206192

207193
- name: Upload deploy files artifact
208194
uses: actions/upload-artifact@v4

.github/workflows/build-test-and-deploy-powershell-module.yml

+17-39
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,29 @@ jobs:
2626
publish-prerelease-module:
2727
needs: run-build-and-test
2828
runs-on: ubuntu-latest
29-
outputs:
30-
prereleaseVersionNumber: ${{ steps.output-version-number.outputs.prereleaseVersionNumber }}
3129
steps:
32-
- name: Download prerelease module artifact
30+
- name: Download module artifact
3331
uses: actions/download-artifact@v4
3432
with:
35-
name: ${{ needs.run-build-and-test.outputs.prereleaseModuleArtifactName }}
33+
name: ${{ needs.run-build-and-test.outputs.moduleArtifactName }}
3634
path: ${{ env.artifactsDirectoryPath }}
3735

3836
- name: Publish prerelease PowerShell module
3937
shell: pwsh
4038
run: |
4139
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
4240
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$moduleName"
43-
Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose
41+
[string] $moduleManifestFilePath = Join-Path -Path $moduleDirectoryPath -ChildPath "$moduleName.psd1"
42+
[string] $prereleaseVersionLabel = '${{ needs.run-build-and-test.outputs.prereleaseVersionLabel}}'
4443
45-
- name: Make prerelease version number available to downstream jobs
46-
id: output-version-number
47-
shell: pwsh
48-
run: |
49-
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
50-
[string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$moduleName/$moduleName.psd1"
51-
Write-Output "Reading module manifest from '$moduleManifestPath'."
52-
[hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression
53-
[string] $versionNumber = $manifest.ModuleVersion
54-
[string] $prereleasePostfix = $manifest.PrivateData.PSData.Prerelease
55-
[string] $prereleaseVersionNumber = "$versionNumber-$prereleasePostfix"
44+
Write-Output "Updating the module manifest version number's prerelease label to '$prereleaseVersionLabel'."
45+
Update-ModuleManifest -Path $moduleManifestFilePath -Prerelease $prereleaseVersionLabel
46+
47+
Write-Output "Testing the prerelease module manifest file '$moduleManifestFilePath' to ensure it is still valid."
48+
Test-ModuleManifest -Path $moduleManifestFilePath
5649
57-
Write-Output "Saving the prerelease version number '$prereleaseVersionNumber' to an output variable."
58-
"prereleaseVersionNumber=$prereleaseVersionNumber" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
50+
Write-Output "Publishing the prerelease version of the module."
51+
Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose
5952
6053
- name: Wait a short while for the module to be available on the PowerShell Gallery before continuing
6154
shell: pwsh
@@ -76,7 +69,7 @@ jobs:
7669
shell: pwsh
7770
run: |
7871
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
79-
[string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}'
72+
[string] $prereleaseVersionNumber = '${{ needs.run-build-and-test.outputs.prereleaseVersionNumber}}'
8073
8174
Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery."
8275
Install-Module -Name $moduleName -AllowPrerelease -RequiredVersion $prereleaseVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose
@@ -117,7 +110,7 @@ jobs:
117110
shell: powershell
118111
run: |
119112
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
120-
[string] $prereleaseVersionNumber = '${{ needs.publish-prerelease-module.outputs.prereleaseVersionNumber }}'
113+
[string] $prereleaseVersionNumber = '${{ needs.run-build-and-test.outputs.prereleaseVersionNumber}}'
121114
122115
Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery."
123116
Install-Module -Name $moduleName -AllowPrerelease -RequiredVersion $prereleaseVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose
@@ -150,13 +143,11 @@ jobs:
150143
needs: [run-build-and-test, test-prerelease-module-in-pwsh, test-prerelease-module-in-windows-powershell]
151144
runs-on: ubuntu-latest
152145
environment: production # Used for deployment approvals.
153-
outputs:
154-
stableVersionNumber: ${{ steps.output-version-number.outputs.StableVersionNumber }}
155146
steps:
156-
- name: Download stable module artifact from triggered workflow
147+
- name: Download module artifact from triggered workflow
157148
uses: actions/download-artifact@v4
158149
with:
159-
name: ${{ needs.run-build-and-test.outputs.stableModuleArtifactName}}
150+
name: ${{ needs.run-build-and-test.outputs.moduleArtifactName}}
160151
path: ${{ env.artifactsDirectoryPath }}
161152

162153
- name: Publish stable PowerShell module
@@ -166,19 +157,6 @@ jobs:
166157
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$moduleName"
167158
Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose
168159
169-
- name: Make stable version number available to downstream jobs
170-
id: output-version-number
171-
shell: pwsh
172-
run: |
173-
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
174-
[string] $moduleManifestPath = "$Env:artifactsDirectoryPath/$moduleName/$moduleName.psd1"
175-
Write-Output "Reading module manifest from '$moduleManifestPath'."
176-
[hashtable] $manifest = Get-Content -Path $moduleManifestPath -Raw | Invoke-Expression
177-
[string] $versionNumber = $manifest.ModuleVersion
178-
179-
Write-Output "Saving the stable version number '$versionNumber' to an output variable."
180-
"stableVersionNumber=$versionNumber" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
181-
182160
- name: Wait a short while for the module to be available on the PowerShell Gallery before continuing
183161
shell: pwsh
184162
run: Start-Sleep -Seconds 30
@@ -198,7 +176,7 @@ jobs:
198176
shell: pwsh
199177
run: |
200178
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
201-
[string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}'
179+
[string] $stableVersionNumber = '${{ needs.run-build-and-test.outputs.stableVersionNumber}}'
202180
203181
Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery."
204182
Install-Module -Name $moduleName -RequiredVersion $stableVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose
@@ -239,7 +217,7 @@ jobs:
239217
shell: powershell
240218
run: |
241219
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
242-
[string] $stableVersionNumber = '${{ needs.publish-stable-module.outputs.stableVersionNumber }}'
220+
[string] $stableVersionNumber = '${{ needs.run-build-and-test.outputs.stableVersionNumber}}'
243221
244222
Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery."
245223
Install-Module -Name $moduleName -RequiredVersion $stableVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose

0 commit comments

Comments
 (0)