-
Notifications
You must be signed in to change notification settings - Fork 7
175 lines (173 loc) · 7.98 KB
/
admu-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
name: ADMU Module CI
on:
pull_request:
branches:
- master
types: [opened, synchronize, reopened, labeled, unlabeled]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# define jobs
jobs:
Filter-Branch:
runs-on: ubuntu-latest
if: contains(github.event.pull_request.labels.*.name, 'ADMU')
steps:
- run: echo "Building JumpCloud Module 'ADMU'"
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 ("ADMU" -in $PR_LABEL_LIST) {
write-host "Starting Build for PowerShell Module 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 }}
Validate-Env-Variables:
needs: ["Filter-Branch", "Check-PR-Labels"]
runs-on: ubuntu-latest
steps:
- env:
RELEASE_TYPE: ${{ needs.Check-PR-Labels.outputs.RELEASE_TYPE }}
shell: pwsh
run: |
# validate release type variables
$env:RELEASE_TYPE | Should -BeIn @('major','minor','patch','manual')
Setup-Build-Dependencies:
needs: ["Filter-Branch", "Check-PR-Labels", "Validate-Env-Variables"]
runs-on: windows-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Setup PowerShell Module Cache
id: cacher
uses: actions/cache@v4
with:
path: 'C:\Users\runneradmin\Documents\PowerShell\Modules\'
key: PS-Dependencies
- name: Install dependencies
if: steps.cacher.outputs.cache-hit != 'true'
shell: pwsh
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
}
# define dependencies for this ci workflow:
$PSDependencies = @{
'PowerShellGet' = @{Repository = 'PSGallery'; RequiredVersion = '3.0.12-beta' }
'ps2exe' = @{Repository = 'PSGallery'; RequiredVersion = '1.0.13' }
'PlatyPS' = @{Repository = 'PSGallery'; RequiredVersion = '0.14.2' }
'JumpCloud.SDK.V1' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'}
'JumpCloud.SDK.V2' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'}
'JumpCloud.SDK.DirectoryInsights' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'}
'JumpCloud' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'}
}
foreach ($RequiredModule in $PSDependencies.Keys) {
If ([System.String]::IsNullOrEmpty((Get-InstalledModule | Where-Object { $_.Name -eq $RequiredModule }))) {
$latestModule = find-module $RequiredModule
Write-Host "[status] latest module: $RequiredModule; latest version: $($latestModule.Version)"
Write-Host("[status] Installing module: '$RequiredModule'; version: $($PSDependencies[$RequiredModule].RequiredVersion) from $($PSDependencies[$RequiredModule].Repository)")
if ($($PSDependencies[$RequiredModule].RequiredVersion) -eq "latest"){
Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository)) -Force
} else {
if($RequiredModule -eq 'PowerShellGet'){
Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository)) -RequiredVersion:($($PSDependencies[$RequiredModule].RequiredVersion)) -AllowPrerelease -Force -allowClobber
} else {
Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository)) -RequiredVersion:($($PSDependencies[$RequiredModule].RequiredVersion)) -AllowPrerelease -Force
}
}
}
}
Build-Module:
needs: ["Setup-Build-Dependencies", "Check-PR-Labels"]
runs-on: windows-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: 'C:\Users\runneradmin\Documents\PowerShell\Modules\'
key: PS-Dependencies
- name: Build ADMU Module
shell: powershell
env:
RELEASE_TYPE: ${{ needs.Check-PR-Labels.outputs.RELEASE_TYPE }}
run: |
. "${{ github.workspace }}/Deploy/build.ps1" -ModuleVersionType $env:RELEASE_TYPE -ModuleName "JumpCloud.ADMU"
- name: Upload Nuspec
uses: actions/upload-artifact@v4
with:
name: jumpcloud-admu-build
path: |
${{ github.workspace }}/Jumpcloud-ADMU/JumpCloud.ADMU.nuspec
${{ github.workspace }}/Jumpcloud-ADMU/Docs/*.md
${{ github.workspace }}/Jumpcloud-ADMU/en-Us/JumpCloud.ADMU-help.xml
${{ github.workspace }}/Jumpcloud-ADMU/PowerShell/Private/**/*.ps1
${{ github.workspace }}/Jumpcloud-ADMU/PowerShell/Public/**/*.ps1
${{ github.workspace }}/Jumpcloud-ADMU/JumpCloud.ADMU.psd1
${{ github.workspace }}/Jumpcloud-ADMU/JumpCloud.ADMU.psm1
retention-days: 1
Test-Module:
needs: ["Setup-Build-Dependencies", "Check-PR-Labels", "Build-Module"]
runs-on: windows-latest
timeout-minutes: 75
strategy:
fail-fast: false
matrix:
job_group: [0, 1, 2, 3]
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: jumpcloud-admu-build
- uses: actions/cache@v4
with:
path: 'C:\Users\runneradmin\Documents\PowerShell\Modules\'
key: PS-Dependencies
- name: Test PWSH Module
shell: powershell
env:
RELEASE_TYPE: ${{ needs.Check-PR-Labels.outputs.RELEASE_TYPE }}
PESTER_APIKEY: ${{ secrets.PESTER_APIKEY }}
PESTER_ORGID: ${{ secrets.PESTER_ORGID }}
PESTER_CONNECTKEY: ${{ secrets.PESTER_CONNECTKEY }}
run: |
$env:job_group = ${{ matrix.job_group }}
# build before test
$installedModules = Get-ChildItem "C:\Users\runneradmin\Documents\PowerShell\Modules\"
Write-Host "[status] InstalledModules:"
$installedModules
# Explicitly import required modules for powershell shell:
$requiredModules = ('ps2exe', 'JumpCloud.SDK.DirectoryInsights', 'JumpCloud.SDK.V1', 'JumpCloud.SDK.V2', 'JumpCloud')
foreach ($module in $requiredModules){
$modulePSD1 = Get-ChildItem "C:\Users\runneradmin\Documents\PowerShell\Modules\$module" -Recurse -filter "*.psd1"
Write-Host "[status] Importing: $module at path $($modulePSD1.fullname)"
Import-Module "$($modulePSD1.fullname)" -force
}
. "./jumpcloud-ADMU/Powershell/InvokePester.ps1" $env:RELEASE_TYPE