diff --git a/.github/workflows/jcapi-powershell-ci.yml b/.github/workflows/jcapi-powershell-ci.yml index 20dad063d..a4de635ab 100644 --- a/.github/workflows/jcapi-powershell-ci.yml +++ b/.github/workflows/jcapi-powershell-ci.yml @@ -8,117 +8,56 @@ 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'} + 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 } - - 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-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 }}") - # 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@v3 - 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", "Invoke-Pester"] - 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@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 ${{ 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") - + } + 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 @@ -247,4 +186,3 @@ jobs: # 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') - diff --git a/Tools/ModuleValidation.Tests.ps1 b/Tools/ModuleValidation.Tests.ps1 index f41730ac6..744323f05 100644 --- a/Tools/ModuleValidation.Tests.ps1 +++ b/Tools/ModuleValidation.Tests.ps1 @@ -1,4 +1,50 @@ + Describe -Tag:('ModuleValidation') 'Module Manifest Tests' { + It ('Validates Module Versions'){ + [version]$v1GalleryVersion = Find-Module -name JumpCloud.SDK.V1 | Select-Object -Property Version | ForEach-Object { $_.Version } + # Compare the versions to SDKs/PowerShell/JumpCloud.SDK.V1/JumpCloud.SDK.V1.psd1 + [version]$V1LocalVersion = Get-Content -Path "./SDKs/PowerShell/JumpCloud.SDK.V1/JumpCloud.SDK.V1.psd1" | Select-String -Pattern "ModuleVersion = '(.*)'" | ForEach-Object { $_.Matches.Groups[1].Value } + + # Compare the versions to SDKs/PowerShell/JumpCloud.SDK.V2/JumpCloud.SDK.V2.psd1 + [version]$v2GalleryVersion = Find-Module -name JumpCloud.SDK.V2 | Select-Object -Property Version | ForEach-Object { $_.Version } + [version]$V2LocalVersion = Get-Content -Path "./SDKs/PowerShell/JumpCloud.SDK.V2/JumpCloud.SDK.V2.psd1" | Select-String -Pattern "ModuleVersion = '(.*)'" | ForEach-Object { $_.Matches.Groups[1].Value } + + # Compare the versions to SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/JumpCloud.SDK.DirectoryInsights.psd1 + [version]$DiGalleryVersion = Find-Module -name JumpCloud.SDK.DirectoryInsights | Select-Object -Property Version | ForEach-Object { $_.Version } + [version]$DiLocalVersion = Get-Content -Path "./SDKs/PowerShell/JumpCloud.SDK.DirectoryInsights/JumpCloud.SDK.DirectoryInsights.psd1" | Select-String -Pattern "ModuleVersion = '(.*)'" | ForEach-Object { $_.Matches.Groups[1].Value } + + + switch ($env:RELEASE_TYPE) { + 'major' { + $V1LocalVersion.Major | Should -Be ($v1GalleryVersion.Major + 1) + $V2LocalVersion.Major | Should -Be ($v2GalleryVersion.Major + 1) + $DiLocalVersion.Major | Should -Be ($DiGalleryVersion.Major + 1) + + $V1LocalVersion | Should -BeGreaterThan $v1GalleryVersion + $V2LocalVersion | Should -BeGreaterThan $v2GalleryVersion + $DiGalleryVersion | Should -BeGreaterThan $DiGalleryVersion + } + 'minor' { + $V1LocalVersion.Minor | Should -Be ($v1GalleryVersion.Minor + 1) + $V2LocalVersion.Minor | Should -Be ($v2GalleryVersion.Minor + 1) + $DiLocalVersion.Minor | Should -Be ($DiGalleryVersion.Minor + 1) + + $V1LocalVersion | Should -BeGreaterThan $v1GalleryVersion + $V2LocalVersion | Should -BeGreaterThan $v2GalleryVersion + $DiGalleryVersion | Should -BeGreaterThan $DiGalleryVersion + } + 'patch' { + #Test + $V1LocalVersion.Build | Should -Be ($v1GalleryVersion.Build + 1) + $V2LocalVersion.Build | Should -Be ($v2GalleryVersion.Build + 1) + $DiLocalVersion.Build | Should -Be ($DiGalleryVersion.Build + 1) + + $V1LocalVersion | Should -BeGreaterThan $v1GalleryVersion + $V2LocalVersion | Should -BeGreaterThan $v2GalleryVersion + $DiLocalVersion | Should -BeGreaterThan $DiGalleryVersion + + + } It 'The data on the current version of the Module Changelog should be todays date' { if ($env:RELEASE_TYPE) { @('JumpCloud.SDK.DirectoryInsights', 'JumpCloud.SDK.V1', 'JumpCloud.SDK.V2')| ForEach-Object { @@ -50,7 +96,6 @@ Describe -Tag:('ModuleValidation') 'Module Manifest Tests' { $moduleChangelogPath = "$rootPath/$_.md" $moduleChangelogContent = Get-Content ("$moduleChangelogPath") $moduleChangelogContent | Should -Not -Match "{{Fill in the" - } } } \ No newline at end of file