forked from cisagov/ScubaGear
-
Notifications
You must be signed in to change notification settings - Fork 0
203 lines (197 loc) · 7 KB
/
run_publish_package.yaml
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
name: Publish Package
on:
schedule:
- cron: "23 0 * * *" # Execute each day at 00:23 UTC
workflow_dispatch:
inputs:
OverrideModuleVersion:
description: "Override the version of the release. Restricted to SemVer 1.0 - 3 segments"
required: false
type: string
IsPrerelease:
description: "Is this a prerelease"
required: false
type: boolean
default: false
PrereleaseTag:
description: "The prerelease tag: [0-9A-Za-z]+"
required: false
type: string
push:
paths:
- ".github/workflows/run_publish_package.yaml"
- "utils/DeployUtils.ps1"
env:
GalleryName: PrivateScubaGearGallery
ModuleName: ScubaGear
jobs:
ReleasePrep:
runs-on: windows-latest
environment: Development
permissions:
id-token: write
contents: write
defaults:
run:
shell: powershell
outputs:
KeyVaultUrl: ${{ steps.key_vault_info.outputs.KeyVaultUrl}}
KeyVaultCertificateName: ${{ steps.key_vault_info.outputs.KeyVaultCertificateName}}
steps:
- name: Get Key Vault info
env:
KEY_VAULT_INFO: ${{ secrets.SCUBA_KEY_VAULT_PROD}}
run: |
$KeyVaultInfo = ${env:KEY_VAULT_INFO} | ConvertFrom-Json
echo "KeyVaultUrl=$($KeyVaultInfo.KeyVault.URL)" >> $env:GITHUB_OUTPUT
echo "KeyVaultCertificateName=$($KeyVaultInfo.KeyVault.CertificateName)" >> $env:GITHUB_OUTPUT
id: "key_vault_info"
Publish-Private-Package:
if: github.event.schedule == '23 0 * * *'
needs: [ReleasePrep]
runs-on: windows-latest
environment: Development
permissions:
id-token: write
contents: write
defaults:
run:
shell: powershell
steps:
- name: Install Azure Signing Tool
run: |
dotnet --version
dotnet tool install --global AzureSignTool --version 4.0.1
- name: Checkout
uses: actions/checkout@v4
with:
path: repo
- name: OIDC Login to Azure Public Cloud with AzPowershell (enableAzPSSession true)
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Create temporary private gallery
run: |
cd repo
. utils/DeployUtils.ps1
New-PrivateGallery -GalleryName $env:GalleryName -Trusted
- name: Sign and publish module to private gallery
uses: azure/powershell@v1
with:
inlineScript: |
. repo/utils/DeployUtils.ps1
# Remove non-release files
Remove-Item -Recurse -Force repo -Include .git*
Publish-ScubaGearModule `
-AzureKeyVaultUrl ${{ needs.ReleasePrep.outputs.KeyVaultUrl}} `
-CertificateName ${{ needs.ReleasePrep.outputs.KeyVaultCertificateName}} `
-ModulePath repo/PowerShell/ScubaGear `
-GalleryName $env:GalleryName
azPSVersion: "latest"
- name: Test Module Publish
run: |
Get-Location
$TestContainers = @()
$TestContainers += New-PesterContainer -Path "repo/Testing/Functional/BuildTest" -Data @{ }
$PesterConfig = @{
Run = @{
Container = $TestContainers
}
Output = @{
Verbosity = 'Detailed'
}
}
$Config = New-PesterConfiguration -Hashtable $PesterConfig
Invoke-Pester -Configuration $Config
- name: Check Scuba Version
run: |
Install-Module -Name ScubaGear -SkipPublisherCheck
Import-Module -Name ScubaGear
Invoke-SCuBA -Version
- name: Sign and publish prerelease module to private gallery
uses: azure/powershell@v1
env:
KEY_VAULT_INFO: ${{ secrets.SCUBA_KEY_VAULT_DEV}}
with:
inlineScript: |
Write-Output "$(pwd)"
. repo/utils/DeployUtils.ps1
$KeyVaultInfo = ${env:KEY_VAULT_INFO} | ConvertFrom-Json
# Remove non-release files
Remove-Item -Recurse -Force repo -Include .git*
Publish-ScubaGearModule `
-AzureKeyVaultUrl $($KeyVaultInfo.KeyVault.URL) `
-CertificateName $($KeyVaultInfo.KeyVault.CertificateName) `
-ModulePath repo/PowerShell/ScubaGear `
-GalleryName $env:GalleryName `
-OverrideModuleVersion '9.9.9' `
-Prerelease 'alpha'
azPSVersion: "latest"
- name: Check Scuba Version
run: |
$ScubaModules = Find-Module -Name ScubaGear -AllVersions -AllowPrerelease
($ScubaModules).Version
if ($ScubaModules.Count -eq 2) {
Exit 0
}
else {
Exit 1
}
Publish-To-PSGallery:
if: github.event_name == 'workflow_dispatch'
needs: [ReleasePrep]
runs-on: windows-latest
environment: Development
permissions:
id-token: write
contents: write
defaults:
run:
shell: powershell
steps:
- name: Install Azure Signing Tool
run: |
dotnet --version
dotnet tool install --global AzureSignTool --version 4.0.1
- name: Checkout
uses: actions/checkout@v4
with:
path: repo
- name: OIDC Login to Azure Public Cloud with AzPowershell (enableAzPSSession true)
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Sign and publish module to PSGallery
run: |
. repo/utils/DeployUtils.ps1
# Remove non-release files
Remove-Item -Recurse -Force repo -Include .git*
$ApiKey = az keyvault secret show --id '${{ needs.ReleasePrep.outputs.KeyVaultUrl }}/secrets/ScubaGear-PSGAllery-API-Key' --query value -o tsv
if (-Not $ApiKey){
Write-Error "Failer to retrieve API key"
}
$PublishSplat = @{
AzureKeyVaultUrl = '${{ needs.ReleasePrep.outputs.KeyVaultUrl }}'
CertificateName = '${{ needs.ReleasePrep.outputs.KeyVaultCertificateName }}'
ModulePath = 'repo/PowerShell/ScubaGear'
GalleryName = 'PSGallery'
NuGetApiKey = $ApiKey
}
if ('true' -eq '${{ inputs.IsPrerelease }}'){
$PublishSplat.Add('PrereleaseTag', '${{ inputs.PrereleaseTag }}')
}
if (-Not [string]::IsNullOrEmpty('${{ inputs.OverrideModuleVersion }}')){
$PublishSplat.Add('OverrideModuleVersion', '${{ inputs.OverrideModuleVersion }}')
}
Publish-ScubaGearModule @PublishSplat
- name: Check Scuba Version
run: |
Install-Module -Name ScubaGear
Import-Module -Name ScubaGear
Invoke-SCuBA -Version