Merge branch 'SA-3610_GHA_Workflow_Migrations' into SA-3610_GHA_Workf… #57
Workflow file for this run
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 SDK CI | ||
on: | ||
pull_request: | ||
branches: | ||
- "master" | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
jobs: | ||
Check-If-Merged: | ||
# will be switched to true | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check if Merged | ||
run: echo {GITHUB_HEAD_REF} merged into master | ||
Check-PR-Labels: | ||
needs: ["Check-If-Merged"] | ||
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 }} | ||
Validate-SDK-Version: | ||
needs: Check-PR-Labels | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Validate SDK Versions | ||
id: validate | ||
shell: pwsh | ||
run: | | ||
Install-Module -Name Pester | ||
Invoke-Pester -Path /home/runner/work/jcapi-powershell/jcapi-powershell/Tools/ModuleValidation.Tests.ps1 | ||
Test-SDK-MTP: | ||
needs: ["Setup-Build-Dependancies", "Build-SDK", "Invoke-Pester"] | ||
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@v3 | ||
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@v3 | ||
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@v3 | ||
with: | ||
name: build-JumpCloud.SDK.DirectoryInsights | ||
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: build-JumpCloud.SDK.V1 | ||
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/ | ||
- uses: actions/download-artifact@v3 | ||
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 | ||
$sdks = @('JumpCloud.SDK.DirectoryInsights', 'JumpCloud.SDK.V1', 'JumpCloud.SDK.V2') | ||
foreach ($sdk in $sdks){ | ||
Import-Module "/home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell/$sdk/$sdk.psd1" -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: | ||
$orgVars = . "./support/PowerShell/JumpCloud Module/Tests/SetupOrg.ps1" -JumpCloudApiKey "$env:PESTER_APIKEY" -JumpCloudApiKeyMsp "$env:PESTER_MSP_APIKEY" | ||
# Invoke Pester | ||
Import-Module "./support/PowerShell/JumpCloud Module/JumpCloud.psd1" | ||
# disable parallel tests: | ||
Set-JCSettingsFile -parallelOverride $true | ||
. "./support/PowerShell/JumpCloud Module/Tests/InvokePester.ps1" -JumpCloudApiKey $env:PESTER_APIKEY -ExcludeTagList:('MSP', 'JCDeployment', 'JCOnline') -IncludeTagList:($tags) -RequiredModulesRepo:('PSGallery') |