|
| 1 | +name: Update Chocolatey package |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + update-chocolatey: |
| 9 | + if: github.event.release.prerelease == false |
| 10 | + runs-on: windows-latest |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v6 |
| 14 | + |
| 15 | + - name: Set release version |
| 16 | + shell: pwsh |
| 17 | + run: | |
| 18 | + $version = "${{ github.event.release.tag_name }}".TrimStart('v').Split('-')[0] |
| 19 | + "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 20 | +
|
| 21 | + - name: Set MSI variables |
| 22 | + shell: pwsh |
| 23 | + run: | |
| 24 | + $msiName = "Defguard_${env:VERSION}_x64_en-US.msi" |
| 25 | + $msiUrl = "https://github.com/DefGuard/client/releases/download/v${env:VERSION}/Defguard_${env:VERSION}_x64_en-US.msi" |
| 26 | + "MSI_NAME=$msiName" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 27 | + "MSI_URL=$msiUrl" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 28 | +
|
| 29 | + - name: Download MSI asset |
| 30 | + shell: pwsh |
| 31 | + env: |
| 32 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + run: | |
| 34 | + gh release download "${{ github.event.release.tag_name }}" --pattern $env:MSI_NAME --dir "$pwd" |
| 35 | +
|
| 36 | + - name: Calculate MSI checksum |
| 37 | + shell: pwsh |
| 38 | + run: | |
| 39 | + $hash = (Get-FileHash -Algorithm SHA256 -Path $env:MSI_NAME).Hash.ToLower() |
| 40 | + "MSI_SHA256=$hash" | Out-File -FilePath $env:GITHUB_ENV -Append |
| 41 | +
|
| 42 | + - name: Update Chocolatey package files |
| 43 | + shell: pwsh |
| 44 | + working-directory: chocolatey/defguard |
| 45 | + run: | |
| 46 | + $nuspecPath = "defguard.nuspec" |
| 47 | + $installPath = "tools\chocolateyinstall.ps1" |
| 48 | +
|
| 49 | + (Get-Content -Raw $nuspecPath) ` |
| 50 | + -replace '<version>[^<]+</version>', "<version>$env:VERSION</version>" | |
| 51 | + Set-Content -NoNewline -Encoding UTF8 $nuspecPath |
| 52 | +
|
| 53 | + $content = Get-Content -Raw $installPath |
| 54 | + $content = $content -replace '__MSI_URL__', $env:MSI_URL |
| 55 | + $content = $content -replace '__MSI_CHECKSUM__', $env:MSI_SHA256 |
| 56 | + $content | Set-Content -NoNewline -Encoding UTF8 $installPath |
| 57 | +
|
| 58 | + - name: Refresh local nupkg |
| 59 | + shell: pwsh |
| 60 | + working-directory: chocolatey/defguard |
| 61 | + run: | |
| 62 | + $old = Get-ChildItem -Filter "defguard.*.nupkg" | Where-Object { $_.Name -ne "defguard.$env:VERSION.nupkg" } |
| 63 | + if ($old) { $old | Remove-Item -Force } |
| 64 | +
|
| 65 | + - name: Pack Chocolatey package |
| 66 | + shell: pwsh |
| 67 | + working-directory: chocolatey/defguard |
| 68 | + run: choco pack |
| 69 | + |
| 70 | + - name: Push Chocolatey package |
| 71 | + shell: pwsh |
| 72 | + working-directory: chocolatey/defguard |
| 73 | + env: |
| 74 | + CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }} |
| 75 | + run: | |
| 76 | + $nupkg = "defguard.$env:VERSION.nupkg" |
| 77 | + choco push $nupkg --source "https://push.chocolatey.org/" -k="$env:CHOCO_API_KEY" |
0 commit comments