build test changes #21
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: | |
Setup-Build-Dependancies: | |
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 | |
} | |
} | |
Build-Test-SDK: | |
needs: ["Setup-Build-Dependancies"] | |
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 | |
with: | |
name: jcapi-powershell-build | |
path: /home/runner/work/jcapi-powershell/jcapi-powershell/SDKs/PowerShell | |
- name: Build ${{ matrix.SDKName }} | |
shell: pwsh | |
run: | | |
./BuildAutoRest -SDKName:("${{ matrix.SDKName }}") | |
- 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' | |
# build v1 for v2 tests: | |
if ("${{ matrix.SDKName }}" -eq "JumpCloud.SDK.V2"){ | |
# build v1 | |
./buildAutoRest.ps1 -SDKName:("JumpCloud.SDK.V1") | |
# change dir back to root | |
cd ../../../ | |
} | |
./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") | |
if if (("${{ matrix.SDKName }}" -eq "JumpCloud.SDK.V2") -or ("${{ matrix.SDKName }}" -eq "JumpCloud.SDK.V1")){ | |
# invoke MTP tests: | |
./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-Test-SDK"] | |
runs-on: ubuntu-latest | |
timeout-minutes: 70 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v3 | |
with: | |
path: "/home/runner/.local/share/powershell/Modules/" | |
key: PS-Dependancies | |
- uses: actions/download-artifact | |
with: | |
name: build-JumpCloud.SDK.DirectoryInsights | |
path: ./SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights | |
- uses: actions/download-artifact | |
with: | |
name: build-JumpCloud.SDK.V1 | |
path: ./SDKs/PowerShell/JumpCloud.SDK.V1 | |
- uses: actions/download-artifact | |
with: | |
name: build-JumpCloud.SDK.V2 | |
path: ./SDKs/PowerShell/JumpCloud.SDK.V2 | |
- 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' | |
./support\PowerShell\Deploy\SdkSync\jcapiToSupportSync.ps1 -RequiredModulesRepo CodeArtifact | |
# Get functions where 'jcsdk' functions are found | |
# Private & Public Functions | |
$pathList = @('Private', 'Public') | |
# Get matching functions | |
$functions = $pathList | ForEach-Object { | |
Get-ChildItem "./support/PowerShell/Jumpcloud Module/$($_)/*.ps1" -Recurse | |
} | |
$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' | |
# Invoke Pester | |
. "./support/PowerShell/JumpCloud Module/Tests/InvokePester.ps1" -JumpCloudApiKey $env:PESTER_APIKEY -JumpCloudApiKeyMsp $env:PESTER_MSP_APIKEY -ExcludeTagList:('None') -IncludeTagList:($tags) -RequiredModulesRepo:('CodeArtifact') | |