JumpCloud Module SA-3607 PowerShell CI Workflow #107
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: PowerShell Module CI | |
env: | |
# Set the release type of the release, valid values are 'major', 'minor' or 'patch' | |
RELEASE_TYPE: "patch" | |
# override version boolean. If specified, valid vlaues are 'true' or 'false' | |
OVERRIDE_VERSION: "false" | |
on: | |
pull_request: | |
# Sequence of patterns matched against refs/heads | |
branches: | |
- "master" | |
push: | |
branches: JumpCloudModule_** | |
jobs: | |
Check-Filepath-Changes: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Check Changes in Directory | |
shell: pwsh | |
run: | | |
# Define List of PWSH directories: | |
$list = @( | |
"/PowerShell/Deploy/", | |
"/PowerShell/JumpCloud Module/", | |
"/PowerShell/ModuleChangelog.md" | |
) | |
# Loop through each file in the list then do git diff | |
$difCount = 0 # Diff Counter | |
git fetch origin $env:GITHUB_BASE_REF | |
$gitDiff = git diff origin/$env:GITHUB_BASE_REF..HEAD . ':!.github/workflows/powershell-module-ci.yml' | |
foreach ($path in $list) { | |
# Check if the path exists in the Git diff | |
if ($gitDiff -match [regex]::Escape($path)) { | |
Write-Host "Path found in Git diff: $path" | |
$difCount++ | |
} | |
} | |
$gitdiff | |
# If difcount = 0 then no changes were made to the files in the list, throw exit 1 | |
if ($difCount -eq 0) { | |
Write-Host "No changes were made to the files in the list, exiting with code 1" | |
exit 1 | |
} else { | |
Write-Host "Changes were made to the files in the list" | |
exit 0 | |
} | |
Validate-Env-Variables: | |
runs-on: ubuntu-latest | |
steps: | |
- shell: pwsh | |
run: | | |
# validate release type variables | |
$env:OVERRIDE_VERSION | Should -BeIn @('true', 'false') | |
$env:RELEASE_TYPE | Should -BeIn @('major','minor','patch') | |
Validate-Module: | |
needs: Setup-Build-Dependancies | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
PowerShell | |
- uses: actions/cache@v3 | |
with: | |
path: "/home/runner/.local/share/powershell/Modules/" | |
key: PS-Dependancies | |
- shell: pwsh | |
run: | | |
. "./PowerShell/JumpCloud Module/Tests/InvokePester.ps1" -ModuleValidation | |
Test-Module: | |
needs: [Setup-Build-Dependancies, Validate-Module, Check-Filepath-Changes] | |
runs-on: ubuntu-latest | |
timeout-minutes: 75 | |
name: Run Pester Tests and Upload Results | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
PowerShell | |
- uses: actions/cache@v3 | |
with: | |
path: "/home/runner/.local/share/powershell/Modules/" | |
key: PS-Dependancies | |
- name: Test PWSH Module | |
shell: pwsh | |
env: | |
PESTER_APIKEY: ${{ secrets.PESTER_APIKEY }} | |
PESTER_ORGID: ${{ secrets.PESTER_ORGID }} | |
PESTER_MSP_APIKEY: ${{ secrets.PESTER_MSP_APIKEY }} | |
run: | | |
. "./PowerShell/JumpCloud Module/Tests/InvokePester.ps1" -JumpCloudApiKey "$env:PESTER_APIKEY" -JumpCloudApiKeyMsp "$env:PESTER_MSP_APIKEY" -JumpCloudMspOrg "$env:PESTER_ORGID" -ExcludeTagList "ModuleValidation, JCDeployment, MSP, JCModule, JCAssociation" -IncludeTagList "JCUser" -RequiredModulesRepo "PSGallery" | |
- name: Upload Test Results | |
uses: actions/upload-artifact@v3 | |
with: | |
name: PWSH-Pester-Tests | |
path: "./PowerShell/JumpCloud Module/Tests/test_results/results.xml" | |
if: ${{ always() }} | |
Test-Module-MSP: | |
runs-on: ubuntu-latest | |
timeout-minutes: 20 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
PowerShell | |
- uses: actions/cache@v3 | |
with: | |
path: "/home/runner/.local/share/powershell/Modules/" | |
key: PS-Dependancies | |
- shell: pwsh | |
env: | |
PESTER_APIKEY: ${{ secrets.PESTER_APIKEY }} | |
PESTER_ORGID: ${{ secrets.PESTER_ORGID }} | |
PESTER_MSP_APIKEY: ${{ secrets.PESTER_MSP_APIKEY }} | |
PESTER_PROVIDER_ID: ${{ secrets.PESTER_PROVIDER_ID }} | |
run: | | |
. "./PowerShell/JumpCloud Module/Tests/InvokePester.ps1" -JumpCloudApiKey "$env:PESTER_APIKEY" -JumpCloudApiKeyMsp "$env:PESTER_MSP_APIKEY" -JumpCloudMspOrg "$env:PESTER_ORGID" -ExcludeTagList "None" -IncludeTagList "MSP" -RequiredModulesRepo "PSGallery" | |
needs: [Test-Module] | |
Setup-Build-Dependancies: | |
runs-on: ubuntu-latest | |
timeout-minutes: 90 | |
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 | |
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 = @{ | |
'PowerShellGet' = @{Repository = 'PSGallery'; RequiredVersion = '3.0.12-beta' } | |
'PackageManagement' = @{Repository = 'PSGallery'; RequiredVersion = '1.4.8.1' } | |
'PSScriptAnalyzer' = @{Repository = 'PSGallery'; RequiredVersion = '1.19.1' } | |
'PlatyPS' = @{Repository = 'PSGallery'; RequiredVersion = '0.14.2' } | |
'AWS.Tools.Common' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.122' } | |
'AWS.Tools.CodeArtifact' = @{Repository = 'PSGallery'; RequiredVersion = '4.1.122' } | |
'JumpCloud.SDK.V1' = @{Repository = 'PSGallery'; RequiredVersion = '0.0.35'} | |
'JumpCloud.SDK.V2' = @{Repository = 'PSGallery'; RequiredVersion = '0.0.39'} | |
'JumpCloud.SDK.DirectoryInsights' = @{Repository = 'PSGallery'; RequiredVersion = '0.0.23'} | |
} | |
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 | |
} | |
} |