-
Notifications
You must be signed in to change notification settings - Fork 3
327 lines (325 loc) · 17.3 KB
/
jcapi-powershell-ci.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
name: PowerShell SDK CI
on:
pull_request:
branches:
- "master"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
Filter-Branch:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'SDK')
steps:
- run: echo "Building SDKs"
Check-PR-Labels:
needs: ['Filter-Branch']
runs-on: ubuntu-latest
outputs:
RELEASE_TYPE: ${{ steps.validate.outputs.RELEASE_TYPE }}
steps:
- name: Validate-PR-Version-Labels
id: validate
shell: pwsh
run: |
$PR_LABEL_LIST=$(curl -s "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels" | jq -r '.[].name')
if ("SDK" -in $PR_LABEL_LIST) {
write-host "Starting Build for PowerShell SDK Release"
}
# validate type from label list:
$types = @('major', 'minor', 'patch', 'manual')
$typeCount = 0
foreach ($item in $PR_LABEL_LIST) {
if ($item -in $types) {
write-host "$item"
$typeCount += 1
$RELEASE_TYPE = $item
}
}
if ($typeCount -eq 1) {
echo "RELEASE_TYPE=$RELEASE_TYPE" >> $env:GITHUB_OUTPUT
} else {
throw "Multiple or invalid release types were found on PR"
exit 1
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Setup-Build-Dependancies:
needs: ['Filter-Branch']
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Setup PowerShell Module Cache
id: cacher
uses: actions/cache@v3
with:
path: "/home/runner/.local/share/powershell/Modules/"
key: PS-Dependancies
- name: Install dependencies
if: steps.cacher.outputs.cache-hit != 'true'
shell: pwsh
env:
PESTER_APIKEY: ${{ secrets.PESTER_APIKEY }}
PESTER_ORGID: ${{ secrets.PESTER_ORGID }}
PESTER_MSP_APIKEY: ${{ secrets.PESTER_MSP_APIKEY }}
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('SilentlyContinue'))) {
Write-Host ('[status]Installing package provider NuGet');
Install-PackageProvider -Name:('NuGet') -Scope:('CurrentUser') -Force
}
$PSDependencies = @{
'AWS.Tools.CodeArtifact' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.14.0' }
'AWS.Tools.Common' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.14.0' }
'BuildHelpers' = @{Repository = 'PSGallery'; RequiredVersion = '2.0.15'}
'Pester' = @{Repository = 'PSGallery'; RequiredVersion = '5.3.1'}
'powershell-yaml' = @{Repository = 'PSGallery'; RequiredVersion = '0.4.2'}
'PowerShellGet' = @{Repository = 'PSGallery'; RequiredVersion = '3.0.12-beta'}
'PSScriptAnalyzer' = @{Repository = 'PSGallery'; RequiredVersion = '1.19.1'}
}
foreach ($RequiredModule in $PSDependencies.Keys) {
If ([System.String]::IsNullOrEmpty((Get-InstalledModule | Where-Object { $_.Name -eq $RequiredModule }))) {
Write-Host("[status]Installing module: '$RequiredModule'; version: $($PSDependencies[$RequiredModule].RequiredVersion) from $($PSDependencies[$RequiredModule].Repository)")
Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository)) -RequiredVersion:($($PSDependencies[$RequiredModule].RequiredVersion)) -AllowPrerelease -Force
}
}
Validate-SDK-Module:
needs: ["Setup-Build-Dependancies"]
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v3
with:
path: "/home/runner/.local/share/powershell/Modules/"
key: PS-Dependancies
- uses: actions/checkout@v4
- name: Validate SDK Module
id: validate
shell: pwsh
run: |
Install-Module -Name Pester
Invoke-Pester -Path /home/runner/work/jcapi-powershell/jcapi-powershell/Tools/ModuleValidation.Tests.ps1
Build-SDK:
needs: ["Setup-Build-Dependancies"]
runs-on: ubuntu-latest
timeout-minutes: 70
strategy:
fail-fast: false
matrix:
SDKName: ['JumpCloud.SDK.DirectoryInsights', 'JumpCloud.SDK.V1', 'JumpCloud.SDK.V2']
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: "/home/runner/.local/share/powershell/Modules/"
key: PS-Dependancies
- name: Build ${{ matrix.SDKName }}
shell: pwsh
run: |
./BuildAutoRest -SDKName:("${{ matrix.SDKName }}")
- name: Pack ${{ matrix.SDKName }} Module
shell: pwsh
run: |
$ModuleName = "${{ matrix.SDKName }}"
$Psd1 = Import-PowerShellDataFile -Path:("/home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/$ModuleName/$ModuleName.psd1")
$nupkgFilePath = "/home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/$ModuleName/bin/nupkg"
$csprojFilePath = "/home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/$ModuleName/$ModuleName.csproj"
$nuspecFilePath = "/home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/$ModuleName/$ModuleName.nuspec"
$BuildVersion = $Psd1.ModuleVersion
$nuspecContent = [System.Xml.XmlDocument](Get-Content -Path:($nuspecFilePath))
$nuspecContent.package.metadata.version = $BuildVersion
$nuspecContent.save($nuspecFilePath)
dotnet pack $csprojFilePath --output $nupkgFilePath --configuration=$ModuleName
- name: Zip ${{ matrix.SDKName }} Module
shell: pwsh
run: |
# zip contents for artifact
Compress-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/${{ matrix.SDKName }} -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/${{ matrix.SDKName }}.zip -CompressionLevel Optimal -Force
- uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.SDKName }}
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/${{ matrix.SDKName }}.zip
retention-days: 1
Test-SDK:
needs: ["Setup-Build-Dependancies", "Build-SDK"]
runs-on: ubuntu-latest
timeout-minutes: 70
strategy:
fail-fast: false
matrix:
SDKName: ['JumpCloud.SDK.DirectoryInsights', 'JumpCloud.SDK.V1', 'JumpCloud.SDK.V2']
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: "/home/runner/.local/share/powershell/Modules/"
key: PS-Dependancies
- uses: actions/download-artifact@v4
with:
name: build-${{ matrix.SDKName }}
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/
- name: Unzip ${{ matrix.SDKName }} module
shell: pwsh
run: |
Expand-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/${{ matrix.SDKName }}.zip -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ -Force
- uses: actions/download-artifact@v4
with:
name: build-JumpCloud.SDK.V1
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/
if: matrix.SDKName == 'JumpCloud.SDK.V2'
- name: Unzip V1 module for V2 Tests
shell: pwsh
run: |
Expand-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/JumpCloud.SDK.V1.zip -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ -Force
if: matrix.SDKName == 'JumpCloud.SDK.V2'
- name: Test ${{ matrix.SDKName }}
shell: pwsh
env:
PESTER_APIKEY: ${{ secrets.PESTER_APIKEY }}
PESTER_ORGID: ${{ secrets.PESTER_ORGID }}
PESTER_MSP_APIKEY: ${{ secrets.PESTER_MSP_APIKEY }}
PESTER_PROVIDERID: ${{ secrets.PESTER_PROVIDERID }}
run: |
$ErrorActionnPreference = 'Stop'
./Test-Module.ps1 -JCApiKey:($env:PESTER_APIKEY) -JCOrgId:($env:PESTER_ORGID) -JCApiKeyMTP:($env:PESTER_MSP_APIKEY) -JCProviderId:($env:PESTER_PROVIDERID) -ExcludeTagList:("MTP") -IncludeTagList:("*") -testModulePath:("./SDKs/PowerShell/${{ matrix.SDKName }}/test-module.ps1")
Test-SDK-MTP:
needs: ["Setup-Build-Dependancies", "Build-SDK"]
runs-on: ubuntu-latest
timeout-minutes: 70
strategy:
fail-fast: false
matrix:
SDKName: ['JumpCloud.SDK.V1', 'JumpCloud.SDK.V2']
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
with:
path: "/home/runner/.local/share/powershell/Modules/"
key: PS-Dependancies
- uses: actions/download-artifact@v4
with:
name: build-${{ matrix.SDKName }}
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/
- name: Unzip ${{ matrix.SDKName }} module
shell: pwsh
run: |
Expand-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/${{ matrix.SDKName }}.zip -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ -Force
- uses: actions/download-artifact@v4
with:
name: build-JumpCloud.SDK.V1
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/
if: matrix.SDKName == 'JumpCloud.SDK.V2'
- name: Unzip V1 module for V2 Tests
shell: pwsh
run: |
Expand-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/JumpCloud.SDK.V1.zip -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ -Force
if: matrix.SDKName == 'JumpCloud.SDK.V2'
- name: Test MTP ${{ matrix.SDKName }}
shell: pwsh
env:
PESTER_APIKEY: ${{ secrets.PESTER_APIKEY }}
PESTER_ORGID: ${{ secrets.PESTER_ORGID }}
PESTER_MSP_APIKEY: ${{ secrets.PESTER_MSP_APIKEY }}
PESTER_PROVIDERID: ${{ secrets.PESTER_PROVIDERID }}
run: |
$ErrorActionnPreference = 'Stop'
./Test-Module.ps1 -JCApiKey:($env:PESTER_APIKEY) -JCOrgId:($env:PESTER_ORGID) -JCApiKeyMTP:($env:PESTER_MSP_APIKEY) -JCProviderId:($env:PESTER_PROVIDERID) -ExcludeTagList:("None") -IncludeTagList:("MTP") -testModulePath:("./SDKs/PowerShell/${{ matrix.SDKName }}/test-module.ps1")
# Invoke-Pester:
# needs: ["Setup-Build-Dependancies", "Build-SDK"]
# runs-on: ubuntu-latest
# timeout-minutes: 70
# steps:
# - uses: actions/checkout@v4
# - name: Checkout Support Repo
# uses: actions/checkout@v4
# with:
# repository: TheJumpCloud/support
# path: './support'
# - uses: actions/cache@v3
# with:
# path: "/home/runner/.local/share/powershell/Modules/"
# key: PS-Dependancies
# - uses: actions/download-artifact@v4
# with:
# name: build-JumpCloud.SDK.DirectoryInsights
# path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/
# - uses: actions/download-artifact@v4
# with:
# name: build-JumpCloud.SDK.V1
# path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/
# - uses: actions/download-artifact@v4
# with:
# name: build-JumpCloud.SDK.V2
# path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/
# - name: Unzip artifacts
# shell: pwsh
# run: |
# Expand-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights.zip -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ -Force
# Expand-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/JumpCloud.SDK.V1.zip -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ -Force
# Expand-Archive -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/JumpCloud.SDK.V2.zip -DestinationPath /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ -Force
# - name: Invoke Pester
# shell: pwsh
# env:
# PESTER_APIKEY: ${{ secrets.PESTER_APIKEY }}
# PESTER_ORGID: ${{ secrets.PESTER_ORGID }}
# PESTER_MSP_APIKEY: ${{ secrets.PESTER_MSP_APIKEY }}
# PESTER_PROVIDERID: ${{ secrets.PESTER_PROVIDERID }}
# run: |
# $ErrorActionPreference = 'stop'
# # Import all the SDKs
# # register PS Repo local
# Register-PSRepository -Name SDKs -SourceLocation "/home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/"
# $sdks = @('JumpCloud.SDK.DirectoryInsights', 'JumpCloud.SDK.V1', 'JumpCloud.SDK.V2')
# foreach ($sdk in $sdks){
# Publish-Module -Path /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/$sdk/ -Repository SDKs
# Install-Module -Repository SDKs -Name $sdk -Force
# }
# # list JumpCloud Modules Imported
# Get-Module -Name Jumpcloud*
# # Get functions from module:
# $pathList = @('Private', 'Public')
# # Get matching functions
# $functions = $pathList | ForEach-Object {
# Get-ChildItem "./support/PowerShell/JumpCloud Module/$($_)/*.ps1" -Recurse
# }
# # Get Tags with SDK functions:
# $testTags = @()
# # For each function file
# foreach ($file in $functions) {
# $regex = [regex]'jcsdk'
# if (Select-String -path $file.FullName -Pattern $regex){
# # If 'jcsdk' is used in the function file continue
# # get test file
# $testFile = ($file.FullName -replace "JumpCloud Module", "JumpCloud Module/Tests") -replace ".ps1", ".Tests.ps1"
# $tagRegex = [regex]'-Tag:\(.(\w+).\)'
# $testTag = Select-String -path $testFile -Pattern $tagRegex
# # "$test"
# if ($testTag.matches) {
# # If tag found in test file add to testTags list:
# $testTags += $testTag.matches.Groups[1].Value
# }
# }
# }
# # return found tags
# $tags = ($testTags | Select-Object -Unique)
# # Manually add tags that we can't automatically add with script above:
# # At this time only associations need to be added:
# $tags += 'JCAssociation'
# # setup org:
# $variables = . "./support/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1" -JumpCloudApiKey "$env:PESTER_APIKEY" -JumpCloudApiKeyMsp "$env:PESTER_MSP_APIKEY"
# Write-Host "[status] Setting Env Variables for tests"
# $variables | Foreach-Object {
# if ($_.Name) {
# Set-Variable -Name $_.Name -Value $_.Value -Scope Global
# }
# }
# # remove email users if they exitst
# $emailUsers = Search-JCSDKUser -Searchfilter @{searchTerm = 'importcsvuser';fields = @('email')}
# if ($emailUsers){
# $emailUsers | ForEach-Object { Remove-JcSdkUser -id $_.id }
# }
# Import-Module "./support/PowerShell/JumpCloud Module/JumpCloud.psd1"
# # disable parallel tests:
# Set-JCSettingsFile -parallelOverride $true
# # Invoke Pester
# . "./support/PowerShell/JumpCloud Module/Tests/InvokePester.ps1" -JumpCloudApiKey $env:PESTER_APIKEY -ExcludeTagList:('MSP', 'JCDeployment', 'JCOnline') -IncludeTagList:($tags) -RequiredModulesRepo:('PSGallery')