|
| 1 | +name: Release and Publish ADMU Module |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: |
| 5 | + - closed |
| 6 | + branches: |
| 7 | + - master |
| 8 | +jobs: |
| 9 | + Check-If-Merged: |
| 10 | + if: github.event.pull_request.merged == true |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Check if Merged |
| 14 | + run: echo {GITHUB_HEAD_REF} merged into master |
| 15 | + |
| 16 | + Filter-Branch: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: contains(github.event.pull_request.labels.*.name, 'ADMU') |
| 19 | + steps: |
| 20 | + - run: echo "Building JumpCloud Module 'ADMU'" |
| 21 | + Check-PR-Labels: |
| 22 | + needs: ["Filter-Branch", "Check-If-Merged"] |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + RELEASE_TYPE: ${{ steps.validate.outputs.RELEASE_TYPE }} |
| 26 | + steps: |
| 27 | + - name: Validate-PR-Version-Labels |
| 28 | + id: validate |
| 29 | + shell: pwsh |
| 30 | + run: | |
| 31 | + $PR_LABEL_LIST=$(curl -s "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels" | jq -r '.[].name') |
| 32 | + if ("ADMU" -in $PR_LABEL_LIST) { |
| 33 | + write-host "Starting Build for ADMU Module Release" |
| 34 | + } |
| 35 | + # validate type from label list: |
| 36 | + $types = @('major', 'minor', 'patch', 'manual') |
| 37 | + $typeCount = 0 |
| 38 | + foreach ($item in $PR_LABEL_LIST) { |
| 39 | + if ($item -in $types) { |
| 40 | + write-host "$item" |
| 41 | + $typeCount += 1 |
| 42 | + $RELEASE_TYPE = $item |
| 43 | + } |
| 44 | + } |
| 45 | +
|
| 46 | + if ($typeCount -eq 1) { |
| 47 | + echo "RELEASE_TYPE=$RELEASE_TYPE" >> $env:GITHUB_OUTPUT |
| 48 | + } else { |
| 49 | + throw "Multiple or invalid release types were found on PR" |
| 50 | + exit 1 |
| 51 | + } |
| 52 | + env: |
| 53 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + Setup-Build-Dependancies: |
| 55 | + needs: ["Filter-Branch", "Check-PR-Labels"] |
| 56 | + runs-on: windows-latest |
| 57 | + timeout-minutes: 10 |
| 58 | + steps: |
| 59 | + - uses: actions/checkout@v4 |
| 60 | + - name: Setup PowerShell Module Cache |
| 61 | + id: cacher |
| 62 | + uses: actions/cache@v3 |
| 63 | + with: |
| 64 | + path: 'C:\Users\runneradmin\Documents\PowerShell\Modules\' |
| 65 | + key: PS-Dependancies |
| 66 | + - name: Install dependencies |
| 67 | + if: steps.cacher.outputs.cache-hit != 'true' |
| 68 | + shell: pwsh |
| 69 | + run: | |
| 70 | + Set-PSRepository PSGallery -InstallationPolicy Trusted |
| 71 | +
|
| 72 | + If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('SilentlyContinue'))) { |
| 73 | + Write-Host ('[status]Installing package provider NuGet'); |
| 74 | + Install-PackageProvider -Name:('NuGet') -Scope:('CurrentUser') -Force |
| 75 | + } |
| 76 | + # define dependancies for this ci workflow: |
| 77 | + $PSDependencies = @{ |
| 78 | + 'PowerShellGet' = @{Repository = 'PSGallery'; RequiredVersion = '3.0.12-beta' } |
| 79 | + 'ps2exe' = @{Repository = 'PSGallery'; RequiredVersion = '1.0.13' } |
| 80 | + 'PlatyPS' = @{Repository = 'PSGallery'; RequiredVersion = '0.14.2' } |
| 81 | + 'JumpCloud.SDK.V1' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'} |
| 82 | + 'JumpCloud.SDK.V2' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'} |
| 83 | + 'JumpCloud.SDK.DirectoryInsights' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'} |
| 84 | + 'JumpCloud' = @{Repository = 'PSGallery'; RequiredVersion = 'latest'} |
| 85 | + } |
| 86 | + foreach ($RequiredModule in $PSDependencies.Keys) { |
| 87 | + If ([System.String]::IsNullOrEmpty((Get-InstalledModule | Where-Object { $_.Name -eq $RequiredModule }))) { |
| 88 | + $latestModule = find-module $RequiredModule |
| 89 | + Write-Host "[status] latest module: $RequiredModule; latest version: $($latestModule.Version)" |
| 90 | + Write-Host("[status] Installing module: '$RequiredModule'; version: $($PSDependencies[$RequiredModule].RequiredVersion) from $($PSDependencies[$RequiredModule].Repository)") |
| 91 | + if ($($PSDependencies[$RequiredModule].RequiredVersion) -eq "latest"){ |
| 92 | + Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository))-Force |
| 93 | + } else { |
| 94 | + Install-Module -Name $RequiredModule -Repository:($($PSDependencies[$RequiredModule].Repository)) -RequiredVersion:($($PSDependencies[$RequiredModule].RequiredVersion)) -AllowPrerelease -Force |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + Build-Sign-ADMU: |
| 99 | + runs-on: windows-latest |
| 100 | + needs: ["Setup-Build-Dependancies", "Check-PR-Labels"] |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@v4 |
| 103 | + - uses: actions/cache@v3 |
| 104 | + with: |
| 105 | + path: "/home/runner/.local/share/powershell/Modules/" |
| 106 | + key: PS-Dependancies |
| 107 | + - name: Build ADMU Module |
| 108 | + shell: powershell |
| 109 | + env: |
| 110 | + RELEASE_TYPE: ${{ needs.Check-PR-Labels.outputs.RELEASE_TYPE }} |
| 111 | + run: | |
| 112 | + . "${{ github.workspace }}/Deploy/build.ps1" -ModuleVersionType $env:RELEASE_TYPE -ModuleName "JumpCloud.ADMU" |
| 113 | + - name: Pack nuspec |
| 114 | + shell: pwsh |
| 115 | + run: | |
| 116 | + nuget pack "${{ github.workspace }}/jumpcloud-ADMU/JumpCloud.ADMU.nuspec" |
| 117 | + - name: Validate NuPkg File |
| 118 | + shell: pwsh |
| 119 | + run: | |
| 120 | + $NupkgPathDirectory = (Get-ChildItem -Path:("./*.nupkg")).Directory |
| 121 | + $nupkgPath = (Get-ChildItem -Path:("./*.nupkg")).FullName |
| 122 | + Write-Host "NuPkg Path: $nupkgPath" |
| 123 | + mkdir $NupkgPathDirectory/nupkg_module |
| 124 | + unzip $nupkgPath -d $NupkgPathDirectory/nupkg_module |
| 125 | + $moduleRootFiles = Get-ChildItem -File -Path:("$NupkgPathDirectory/nupkg_module") |
| 126 | + $moduleRootDirectories = Get-ChildItem -Directory -Path:("$NupkgPathDirectory/nupkg_module") |
| 127 | + Write-Host "Module Files:\n$moduleRootFiles" |
| 128 | + Write-Host "Module Directories:\n$moduleRootDirectories" |
| 129 | + - name: Setup Code Signing Variables |
| 130 | + shell: bash |
| 131 | + run: | |
| 132 | + # Create Client Cert File |
| 133 | + echo "${{ secrets.SM_CLIENT_CERT_FILE_B64 }}" | base64 --decode > /d/Certificate_pkcs12.p12 |
| 134 | + # Create Environment Variables |
| 135 | + echo "::set-output name=version::${GITHUB_REF#refs/tags/v}" |
| 136 | + echo "SM_HOST=${{ secrets.SM_HOST }}" >> "$GITHUB_ENV" |
| 137 | + echo "SM_API_KEY=${{ secrets.SM_API_KEY }}" >> "$GITHUB_ENV" |
| 138 | + echo "SM_CLIENT_CERT_FILE=D:\\Certificate_pkcs12.p12" >> "$GITHUB_ENV" |
| 139 | + echo "SM_CLIENT_CERT_PASSWORD=${{ secrets.SM_CLIENT_CERT_PASSWORD }}" >> "$GITHUB_ENV" |
| 140 | + echo "C:\Program Files (x86)\Windows Kits\10\App Certification Kit" >> $GITHUB_PATH |
| 141 | + echo "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools" >> $GITHUB_PATH |
| 142 | + echo "C:\Program Files\DigiCert\DigiCert One Signing Manager Tools" >> $GITHUB_PATH |
| 143 | + - name: Setup SSM KSP for Code Signing |
| 144 | + shell: cmd |
| 145 | + run: | |
| 146 | + curl -X GET https://one.digicert.com/signingmanager/api-ui/v1/releases/smtools-windows-x64.msi/download -H "x-api-key:%SM_API_KEY%" -o smtools-windows-x64.msi |
| 147 | + msiexec /i smtools-windows-x64.msi /quiet /qn |
| 148 | + smksp_registrar.exe list > nul 2>&1 |
| 149 | + smctl.exe keypair ls > nul 2>&1 |
| 150 | + C:\Windows\System32\certutil.exe -csp "DigiCert Signing Manager KSP" -key -user > nul 2>&1 |
| 151 | + smksp_cert_sync.exe > nul 2>&1 |
| 152 | + - name: Sign ADMU EXE |
| 153 | + shell: pwsh |
| 154 | + env: |
| 155 | + SM_CODE_SIGNING_CERT_SHA1_HASH: ${{ secrets.SM_CODE_SIGNING_CERT_SHA1_HASH }} |
| 156 | + run: | |
| 157 | + ${{ github.workspace }}/Deploy/Sign.ps1 |
| 158 | + - name: Upload Release Artifacts |
| 159 | + uses: actions/upload-artifact@v3 |
| 160 | + with: |
| 161 | + name: jumpcloud-admu |
| 162 | + path: | |
| 163 | + ${{ github.workspace }}/Jumpcloud-ADMU/Exe/*.exe |
| 164 | + ${{ github.workspace }}/Jumpcloud-ADMU/JumpCloud.ADMU.nuspec |
| 165 | + ${{ github.workspace }}/JumpCloud.ADMU.*.nupkg |
| 166 | +
|
| 167 | + Draft-GH-Release: |
| 168 | + needs: [Build-Sign-ADMU] |
| 169 | + runs-on: ubuntu-latest |
| 170 | + steps: |
| 171 | + - uses: actions/checkout@v4 |
| 172 | + - name: Download ADMU artifact |
| 173 | + uses: actions/download-artifact@v3 |
| 174 | + with: |
| 175 | + name: jumpcloud-admu |
| 176 | + - name: Build Draft Release |
| 177 | + run: | |
| 178 | + VERSION=$(grep -Po '(\d+\.\d+\.\d+)' ${{ github.workspace }}/jumpcloud-ADMU/JumpCloud.ADMU.psd1) |
| 179 | + TITLE="JumpCloud ADMU v$VERSION" |
| 180 | + CHANGELOG=$(cat ${{ github.workspace }}/ModuleChangelog.md |awk "/^## $VERSION/{ f = 1; next } /## [0-9]+.[0-9]+.[0-9]+/{ f = 0 } f") |
| 181 | + TAG="v$VERSION" |
| 182 | + BODY="$TITLE $CHANGELOG" |
| 183 | + # draft release |
| 184 | + (gh release view $TAG && echo "Release exists for $TAG") || gh release create $TAG --title "$TITLE" --notes "$BODY" --draft |
| 185 | + # upload signed artifacts |
| 186 | + ls -la ${{ github.workspace }}/jumpcloud-ADMU/Exe/ |
| 187 | + gh release upload $TAG ${{ github.workspace }}/jumpcloud-ADMU/Exe/gui_jcadmu.exe ${{ github.workspace }}/jumpcloud-ADMU/Exe/uwp_jcadmu.exe |
| 188 | + env: |
| 189 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 190 | + Manual-Approval-Release: |
| 191 | + needs: ["Draft-GH-Release"] |
| 192 | + environment: PublishToPSGallery |
| 193 | + runs-on: ubuntu-latest |
| 194 | + steps: |
| 195 | + - name: Manual Approval for Release |
| 196 | + run: echo "Awaiting approval from required reviewers before continuing" |
| 197 | + Deploy-Nupkg: |
| 198 | + needs: [Manual-Approval-Release, Build-Sign-ADMU] |
| 199 | + runs-on: ubuntu-latest |
| 200 | + steps: |
| 201 | + - name: Download ADMU artifact |
| 202 | + uses: actions/download-artifact@v3 |
| 203 | + with: |
| 204 | + name: jumpcloud-admu |
| 205 | + - name: Publish |
| 206 | + shell: pwsh |
| 207 | + run: | |
| 208 | + # add nuget source for PSGallery: |
| 209 | + dotnet nuget add source "https://www.powershellgallery.com/api/v2/package" --name PSGallery |
| 210 | + # get nupkg artifact: |
| 211 | + $nupkgPath = (Get-ChildItem -Path:("./*.nupkg")).FullName |
| 212 | + # test |
| 213 | + $nupkgPath | Should -Exist |
| 214 | + Write-Host "Nupkg Artifact Restored: $nupkgPath" |
| 215 | + # nuget push from here: |
| 216 | + # TODO: TO PUBLISH UNCOMMENT BELOW: |
| 217 | + # dotnet nuget push $nupkgPath --source PSGallery --api-key $env:NuGetApiKey |
| 218 | + env: |
| 219 | + NuGetApiKey: ${{ secrets.NUGETAPIKEY }} |
0 commit comments