generated from deadlydog/Template.NewGitRepo
-
-
Notifications
You must be signed in to change notification settings - Fork 16
247 lines (206 loc) · 10.6 KB
/
build-test-and-deploy-powershell-module.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: build-and-deploy
on:
push:
branches: main
paths: [ "src/**", "build/**", "deploy/**", ".github/workflows/**", ".cspell.json" ]
# Allows you to run this workflow manually from the Actions tab.
workflow_dispatch:
inputs:
versionNumber:
description: 'The version number to use for the module. This should be in the format of "Major.Minor.Patch". e.g. "1.0.0". Future builds will increment from this version number. This input is optional. If not provided, the previous version numbers Patch will be incremented.'
required: false
type: string
default: ''
env:
artifactsDirectoryPath: './artifacts'
jobs:
run-build-and-test:
uses: ./.github/workflows/build-and-test-powershell-module.yml
with:
versionNumber: ${{ github.event.inputs.versionNumber }}
publish-prerelease-module:
needs: run-build-and-test
runs-on: ubuntu-latest
steps:
- name: Download module artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.run-build-and-test.outputs.moduleArtifactName }}
path: ${{ env.artifactsDirectoryPath }}
- name: Publish prerelease PowerShell module
shell: pwsh
run: |
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$moduleName"
[string] $moduleManifestFilePath = Join-Path -Path $moduleDirectoryPath -ChildPath "$moduleName.psd1"
[string] $prereleaseVersionLabel = '${{ needs.run-build-and-test.outputs.prereleaseVersionLabel}}'
Write-Output "Updating the module manifest version number's prerelease label to '$prereleaseVersionLabel'."
Update-ModuleManifest -Path $moduleManifestFilePath -Prerelease $prereleaseVersionLabel
Write-Output "Testing the prerelease module manifest file '$moduleManifestFilePath' to ensure it is still valid."
Test-ModuleManifest -Path $moduleManifestFilePath
Write-Output "Publishing the prerelease version of the module."
Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose
- name: Wait a short while for the module to be available on the PowerShell Gallery before continuing
shell: pwsh
run: Start-Sleep -Seconds 30
test-prerelease-module-in-pwsh:
needs: [run-build-and-test, publish-prerelease-module]
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Display PowerShell version being used
shell: pwsh
run: $PSVersionTable
- name: Install prerelease module from PowerShell Gallery
shell: pwsh
run: |
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $prereleaseVersionNumber = '${{ needs.run-build-and-test.outputs.prereleaseVersionNumber}}'
Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery."
Install-Module -Name $moduleName -AllowPrerelease -RequiredVersion $prereleaseVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose
- name: Download deploy files artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}}
path: ${{ env.artifactsDirectoryPath }}
- name: Run smoke tests
shell: pwsh
run: |
[string] $smokeTestsScriptPath = "$Env:artifactsDirectoryPath/Invoke-SmokeTests.ps1"
Write-Output "Running Pester smoke tests from file '$smokeTestsScriptPath'."
$pesterConfig = New-PesterConfiguration @{
Output = @{ Verbosity = 'Detailed' }
Run = @{
Path = $smokeTestsScriptPath
Throw = $true
}
}
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 }}'
test-prerelease-module-in-windows-powershell:
needs: [run-build-and-test, publish-prerelease-module]
runs-on: windows-latest
steps:
- name: Display PowerShell version being used
shell: powershell
run: $PSVersionTable
- name: Install prerelease module from PowerShell Gallery
shell: powershell
run: |
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $prereleaseVersionNumber = '${{ needs.run-build-and-test.outputs.prereleaseVersionNumber}}'
Write-Output "Installing the module '$moduleName' prerelease version '$prereleaseVersionNumber' from the PowerShell Gallery."
Install-Module -Name $moduleName -AllowPrerelease -RequiredVersion $prereleaseVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose
- name: Download deploy files artifact from triggered workflow
uses: actions/download-artifact@v4
with:
name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}}
path: ${{ env.artifactsDirectoryPath }}
- name: Run smoke tests
shell: powershell
run: |
[string] $smokeTestsScriptPath = "$Env:artifactsDirectoryPath/Invoke-SmokeTests.ps1"
Write-Output "Running Pester smoke tests from file '$smokeTestsScriptPath'."
$pesterConfig = New-PesterConfiguration @{
Output = @{ Verbosity = 'Detailed' }
Run = @{
Path = $smokeTestsScriptPath
Throw = $true
}
}
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 }}'
publish-stable-module:
needs: [run-build-and-test, test-prerelease-module-in-pwsh, test-prerelease-module-in-windows-powershell]
runs-on: ubuntu-latest
environment: production # Used for deployment approvals.
steps:
- name: Download module artifact from triggered workflow
uses: actions/download-artifact@v4
with:
name: ${{ needs.run-build-and-test.outputs.moduleArtifactName}}
path: ${{ env.artifactsDirectoryPath }}
- name: Publish stable PowerShell module
shell: pwsh
run: |
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $moduleDirectoryPath = "$Env:artifactsDirectoryPath/$moduleName"
Publish-Module -Path $moduleDirectoryPath -NuGetApiKey '${{ secrets.POWERSHELL_GALLERY_API_KEY }}' -Verbose
- name: Wait a short while for the module to be available on the PowerShell Gallery before continuing
shell: pwsh
run: Start-Sleep -Seconds 30
test-stable-module-in-pwsh:
needs: [run-build-and-test, publish-stable-module]
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Display PowerShell version being used
shell: pwsh
run: $PSVersionTable
- name: Install stable module from PowerShell Gallery
shell: pwsh
run: |
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $stableVersionNumber = '${{ needs.run-build-and-test.outputs.stableVersionNumber}}'
Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery."
Install-Module -Name $moduleName -RequiredVersion $stableVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose
- name: Download deploy files artifact from triggered workflow
uses: actions/download-artifact@v4
with:
name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}}
path: ${{ env.artifactsDirectoryPath }}
- name: Run smoke tests
shell: pwsh
run: |
[string] $smokeTestsScriptPath = "$Env:artifactsDirectoryPath/Invoke-SmokeTests.ps1"
Write-Output "Running Pester smoke tests from file '$smokeTestsScriptPath'."
$pesterConfig = New-PesterConfiguration @{
Output = @{ Verbosity = 'Detailed' }
Run = @{
Path = $smokeTestsScriptPath
Throw = $true
}
}
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 }}'
test-stable-module-in-windows-powershell:
needs: [run-build-and-test, publish-stable-module]
runs-on: windows-latest
steps:
- name: Display PowerShell version being used
shell: powershell
run: $PSVersionTable
- name: Install stable module from PowerShell Gallery
shell: powershell
run: |
[string] $moduleName = '${{ needs.run-build-and-test.outputs.powerShellModuleName }}'
[string] $stableVersionNumber = '${{ needs.run-build-and-test.outputs.stableVersionNumber}}'
Write-Output "Installing the module '$moduleName' stable version '$stableVersionNumber' from the PowerShell Gallery."
Install-Module -Name $moduleName -RequiredVersion $stableVersionNumber -Force -Scope CurrentUser -Repository PSGallery -ErrorAction Stop -Verbose
- name: Download deploy files artifact from triggered workflow
uses: actions/download-artifact@v4
with:
name: ${{ needs.run-build-and-test.outputs.deployFilesArtifactName}}
path: ${{ env.artifactsDirectoryPath }}
- name: Run smoke tests
shell: powershell
run: |
[string] $smokeTestsScriptPath = "$Env:artifactsDirectoryPath/Invoke-SmokeTests.ps1"
Write-Output "Running Pester smoke tests from file '$smokeTestsScriptPath'."
$pesterConfig = New-PesterConfiguration @{
Output = @{ Verbosity = 'Detailed' }
Run = @{
Path = $smokeTestsScriptPath
Throw = $true
}
}
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 }}'