|
| 1 | +name: Publish to Chocolatey |
| 2 | + |
| 3 | +# Packs and pushes a Chocolatey package wrapping the signed MSI from a GitHub Release |
| 4 | +# to community.chocolatey.org. |
| 5 | +# - `release` event fires automatically when CI / Release publishes the GitHub Release. |
| 6 | +# - `workflow_dispatch` lets us re-publish a past version (used for the first |
| 7 | +# submission once this workflow exists on main). |
| 8 | +# |
| 9 | +# Requires repo secret CHOCO_API_KEY (from https://community.chocolatey.org/account) |
| 10 | +# scoped to push for package id `codeshellmanager`. |
| 11 | + |
| 12 | +on: |
| 13 | + release: |
| 14 | + types: [released] |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + tag: |
| 18 | + description: 'Release tag to publish (e.g. v0.5.0)' |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | +jobs: |
| 26 | + publish: |
| 27 | + runs-on: windows-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v6 |
| 30 | + |
| 31 | + - name: Resolve tag and version |
| 32 | + id: ver |
| 33 | + shell: pwsh |
| 34 | + run: | |
| 35 | + $tag = '${{ inputs.tag }}' |
| 36 | + if (-not $tag) { $tag = '${{ github.event.release.tag_name }}' } |
| 37 | + if (-not $tag) { Write-Error 'No release tag resolved.'; exit 1 } |
| 38 | + $version = $tag.TrimStart('v') |
| 39 | + "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 40 | + "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 41 | + Write-Host "Publishing tag=$tag version=$version" |
| 42 | +
|
| 43 | + - name: Download signed MSI from GitHub Release |
| 44 | + shell: pwsh |
| 45 | + env: |
| 46 | + GH_TOKEN: ${{ github.token }} |
| 47 | + run: | |
| 48 | + $tag = '${{ steps.ver.outputs.tag }}' |
| 49 | + $version = '${{ steps.ver.outputs.version }}' |
| 50 | + $msiName = "CodeShellManager-$version-Setup.msi" |
| 51 | + New-Item -ItemType Directory -Force -Path artifact | Out-Null |
| 52 | + gh release download $tag --repo umage-ai/CodeShellManager --pattern $msiName --dir artifact |
| 53 | + if (-not (Test-Path "artifact\$msiName")) { |
| 54 | + Write-Error "MSI $msiName not found in release $tag." |
| 55 | + exit 1 |
| 56 | + } |
| 57 | + Write-Host "Downloaded artifact\$msiName" |
| 58 | +
|
| 59 | + - name: Template version, URL, and checksum into package |
| 60 | + shell: pwsh |
| 61 | + run: | |
| 62 | + $version = '${{ steps.ver.outputs.version }}' |
| 63 | + $msiName = "CodeShellManager-$version-Setup.msi" |
| 64 | + $url64 = "https://github.com/umage-ai/CodeShellManager/releases/download/v$version/$msiName" |
| 65 | + $sha256 = (Get-FileHash "artifact\$msiName" -Algorithm SHA256).Hash.ToLowerInvariant() |
| 66 | + Write-Host "URL: $url64" |
| 67 | + Write-Host "SHA256: $sha256" |
| 68 | +
|
| 69 | + $installPs1 = '.chocolatey/tools/chocolateyinstall.ps1' |
| 70 | + (Get-Content $installPs1 -Raw). |
| 71 | + Replace('__URL64__', $url64). |
| 72 | + Replace('__CHECKSUM64__', $sha256) | |
| 73 | + Set-Content -Path $installPs1 -NoNewline |
| 74 | +
|
| 75 | + $nuspec = '.chocolatey/codeshellmanager.nuspec' |
| 76 | + (Get-Content $nuspec -Raw). |
| 77 | + Replace('__VERSION__', $version) | |
| 78 | + Set-Content -Path $nuspec -NoNewline |
| 79 | +
|
| 80 | + Write-Host '--- chocolateyinstall.ps1 ---' |
| 81 | + Get-Content $installPs1 |
| 82 | + Write-Host '--- codeshellmanager.nuspec ---' |
| 83 | + Get-Content $nuspec |
| 84 | +
|
| 85 | + - name: choco pack |
| 86 | + shell: pwsh |
| 87 | + run: | |
| 88 | + choco pack .chocolatey/codeshellmanager.nuspec --out artifact |
| 89 | + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } |
| 90 | + Get-ChildItem artifact\*.nupkg |
| 91 | +
|
| 92 | + - name: choco push |
| 93 | + shell: pwsh |
| 94 | + env: |
| 95 | + CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }} |
| 96 | + run: | |
| 97 | + $version = '${{ steps.ver.outputs.version }}' |
| 98 | + $nupkg = "artifact/codeshellmanager.$version.nupkg" |
| 99 | + if (-not (Test-Path $nupkg)) { |
| 100 | + Write-Error "Expected nupkg not found: $nupkg" |
| 101 | + exit 1 |
| 102 | + } |
| 103 | + choco push $nupkg --source https://push.chocolatey.org/ --api-key $env:CHOCO_API_KEY |
| 104 | + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } |
| 105 | +
|
| 106 | + - name: Upload built nupkg as workflow artifact |
| 107 | + if: always() |
| 108 | + uses: actions/upload-artifact@v4 |
| 109 | + with: |
| 110 | + name: codeshellmanager-chocolatey-${{ steps.ver.outputs.version }} |
| 111 | + path: artifact/*.nupkg |
| 112 | + if-no-files-found: warn |
0 commit comments