| 1 | name: winget Release |
| 2 | |
| 3 | # Dispatched manually once the GitHub release and its checksums.txt exist. |
| 4 | # |
| 5 | # winget manifests live in microsoft/winget-pkgs, and `wingetcreate update` |
| 6 | # only works on a package that is already there. So this workflow branches: |
| 7 | # |
| 8 | # - package already in winget-pkgs -> `wingetcreate update`, which rewrites |
| 9 | # the URL and re-hashes the installer for us. |
| 10 | # - package not there yet -> render the manifests in packaging/winget/ and |
| 11 | # `wingetcreate submit` them as a new package. |
| 12 | # |
| 13 | # The second path only runs once, but keeping it here means a first release |
| 14 | # does not need someone to sit at a Windows box running `wingetcreate new` |
| 15 | # interactively. |
| 16 | # |
| 17 | # splitfire-agent ships a single Windows x64 zip (splitfire-agent-windows-x64.zip). |
| 18 | # The SHA256 is extracted from the combined checksums.txt that the release |
| 19 | # workflow uploads after all build jobs finish. |
| 20 | on: |
| 21 | workflow_dispatch: |
| 22 | inputs: |
| 23 | tag: |
| 24 | description: "Release tag (e.g. v1.1.1)" |
| 25 | required: true |
| 26 | |
| 27 | concurrency: |
| 28 | # Queue a re-dispatched tag behind the original instead of cancelling it: |
| 29 | # a cancelled mid-publish run can leave a channel half-updated, whereas a |
| 30 | # queued duplicate just hits the "already published" check and exits clean. |
| 31 | group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }} |
| 32 | cancel-in-progress: false |
| 33 | |
| 34 | permissions: |
| 35 | contents: read |
| 36 | |
| 37 | env: |
| 38 | REPO: SplitFireAI/splitfire-agent |
| 39 | PACKAGE_IDENTIFIER: SplitFireAI.Agent |
| 40 | |
| 41 | jobs: |
| 42 | submit-winget-manifest: |
| 43 | name: Submit winget manifest |
| 44 | # wingetcreate is a Windows-only tool. |
| 45 | runs-on: windows-latest |
| 46 | |
| 47 | steps: |
| 48 | - name: Check out repository |
| 49 | uses: actions/checkout@v4 |
| 50 | |
| 51 | - name: Resolve tag, version and release date |
| 52 | id: release |
| 53 | shell: bash |
| 54 | env: |
| 55 | GH_TOKEN: ${{ github.token }} |
| 56 | run: | |
| 57 | TAG="${{ github.event.inputs.tag }}" |
| 58 | VERSION="${TAG#v}" |
| 59 | # wingetcreate wants ReleaseDate as YYYY-MM-DD. |
| 60 | DATE=$(gh release view "$TAG" --repo "$REPO" --json publishedAt --jq '.publishedAt[0:10]') |
| 61 | |
| 62 | echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 63 | echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 64 | echo "date=${DATE}" >> "$GITHUB_OUTPUT" |
| 65 | |
| 66 | - name: Extract SHA256 from checksums.txt |
| 67 | id: sha |
| 68 | shell: bash |
| 69 | env: |
| 70 | GH_TOKEN: ${{ github.token }} |
| 71 | run: | |
| 72 | TAG="${{ steps.release.outputs.tag }}" |
| 73 | mkdir -p artifacts |
| 74 | gh release download "$TAG" --repo "$REPO" --pattern "checksums.txt" --dir artifacts/ |
| 75 | |
| 76 | # checksums.txt lines: "<hash> <filename>" |
| 77 | # The schema wants 64 uppercase hex characters. |
| 78 | SHA_X64=$(grep 'splitfire-agent-windows-x64\.zip' artifacts/checksums.txt \ |
| 79 | | awk '{print $1}' | tr '[:lower:]' '[:upper:]') |
| 80 | |
| 81 | if [ -z "$SHA_X64" ]; then |
| 82 | echo "::error::Could not find splitfire-agent-windows-x64.zip in checksums.txt" |
| 83 | exit 1 |
| 84 | fi |
| 85 | |
| 86 | echo "sha_x64=${SHA_X64}" >> "$GITHUB_OUTPUT" |
| 87 | |
| 88 | - name: Check whether the package is already in winget-pkgs |
| 89 | id: exists |
| 90 | shell: bash |
| 91 | env: |
| 92 | GH_TOKEN: ${{ github.token }} |
| 93 | run: | |
| 94 | # Manifests are filed under the lowercased first letter of the |
| 95 | # publisher, e.g. manifests/s/SplitFireAI/Agent. |
| 96 | PUBLISHER="${PACKAGE_IDENTIFIER%%.*}" |
| 97 | NAME="${PACKAGE_IDENTIFIER#*.}" |
| 98 | FIRST=$(echo "${PUBLISHER:0:1}" | tr '[:upper:]' '[:lower:]') |
| 99 | PATH_IN_REPO="manifests/${FIRST}/${PUBLISHER}/${NAME}" |
| 100 | |
| 101 | if gh api "repos/microsoft/winget-pkgs/contents/${PATH_IN_REPO}" >/dev/null 2>&1; then |
| 102 | echo "Found ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}; submitting an update." |
| 103 | echo "found=true" >> "$GITHUB_OUTPUT" |
| 104 | echo "pending=false" >> "$GITHUB_OUTPUT" |
| 105 | exit 0 |
| 106 | fi |
| 107 | |
| 108 | echo "found=false" >> "$GITHUB_OUTPUT" |
| 109 | |
| 110 | # Until the first New-package PR merges the folder check above is |
| 111 | # always false, so without this every release would open another |
| 112 | # PR and Package Request issue for the same package. |
| 113 | OPEN_PR=$(gh pr list --repo microsoft/winget-pkgs --state open \ |
| 114 | --search "New package: ${PACKAGE_IDENTIFIER} in:title" \ |
| 115 | --json number,url --jq '.[0].url // empty') |
| 116 | |
| 117 | if [ -n "$OPEN_PR" ]; then |
| 118 | echo "No ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}, but ${OPEN_PR} is already open; not submitting again." |
| 119 | echo "pending=true" >> "$GITHUB_OUTPUT" |
| 120 | else |
| 121 | echo "No ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}; submitting it as a new package." |
| 122 | echo "pending=false" >> "$GITHUB_OUTPUT" |
| 123 | fi |
| 124 | |
| 125 | - name: Render manifests for a first submission |
| 126 | if: steps.exists.outputs.found == 'false' && steps.exists.outputs.pending != 'true' |
| 127 | shell: bash |
| 128 | run: | |
| 129 | TAG="${{ steps.release.outputs.tag }}" |
| 130 | VERSION="${{ steps.release.outputs.version }}" |
| 131 | SHA_X64="${{ steps.sha.outputs.sha_x64 }}" |
| 132 | RELEASE_DATE="${{ steps.release.outputs.date }}" |
| 133 | |
| 134 | mkdir -p manifests |
| 135 | |
| 136 | for template in packaging/winget/*.yaml.in; do |
| 137 | out="manifests/$(basename "$template" .in)" |
| 138 | sed \ |
| 139 | -e "s|@VERSION@|${VERSION}|g" \ |
| 140 | -e "s|@TAG@|${TAG}|g" \ |
| 141 | -e "s|@REPO@|${REPO}|g" \ |
| 142 | -e "s|@SHA_X64@|${SHA_X64}|g" \ |
| 143 | -e "s|@RELEASE_DATE@|${RELEASE_DATE}|g" \ |
| 144 | "$template" > "$out" |
| 145 | |
| 146 | echo "--- ${out} ---" |
| 147 | cat "$out" |
| 148 | done |
| 149 | |
| 150 | - name: Download wingetcreate |
| 151 | shell: pwsh |
| 152 | run: Invoke-WebRequest -Uri "https://aka.ms/wingetcreate/latest" -OutFile wingetcreate.exe |
| 153 | |
| 154 | # winget-pkgs convention: file the "please add/update this package" |
| 155 | # Package Request issue *first*, then open the manifest PR that fulfils |
| 156 | # it with "Resolves #N". The other way round reads as a request and its |
| 157 | # fix posted seconds apart. |
| 158 | # |
| 159 | # The issue and the PR are authored by two separate PATs, both with |
| 160 | # public_repo scope on microsoft/winget-pkgs (fork + open issues/PRs): |
| 161 | # WINGET_ISSUE_TOKEN files the Package Request issue. |
| 162 | # WINGET_PR_TOKEN opens the manifest PR. It also needs read:org and |
| 163 | # read:discussion: the "Set the winget PR body" step |
| 164 | # calls `gh pr edit`, whose GraphQL query resolves |
| 165 | # org/team and discussion fields and fails with a |
| 166 | # scope error without them. |
| 167 | - name: File the winget Package Request issue |
| 168 | id: issue |
| 169 | if: steps.exists.outputs.pending != 'true' |
| 170 | shell: bash |
| 171 | env: |
| 172 | GH_TOKEN: ${{ secrets.WINGET_ISSUE_TOKEN }} |
| 173 | run: | |
| 174 | set -euo pipefail |
| 175 | |
| 176 | if [ -z "${GH_TOKEN:-}" ]; then |
| 177 | echo "::error::WINGET_ISSUE_TOKEN is not set. It needs a PAT (public_repo) for the account that should author the Package Request issue." |
| 178 | exit 1 |
| 179 | fi |
| 180 | |
| 181 | VERSION="${{ steps.release.outputs.version }}" |
| 182 | TAG="${{ steps.release.outputs.tag }}" |
| 183 | INSTALLER="https://github.com/${REPO}/releases/download/${TAG}/splitfire-agent-windows-x64.zip" |
| 184 | |
| 185 | # winget-pkgs' Package Request is an issue *form* |
| 186 | # (.github/ISSUE_TEMPLATE/package_request.yml): the title must be |
| 187 | # "[Package Request]: ..." and the body has to carry the labelled |
| 188 | # fields below (Installer Url especially). A free-text body lands as |
| 189 | # Needs-Triage and can't be acted on. |
| 190 | ISSUE_BODY=$(cat <<EOF |
| 191 | Download Page Url: https://github.com/${REPO}/releases/tag/${TAG} |
| 192 | Publisher: SplitFireAI |
| 193 | Package Name: SplitFire Agent |
| 194 | Description: Music-domain ACP agent for theory, production, industry, culture and live shows. |
| 195 | Package Version: ${VERSION} |
| 196 | Installer Url: ${INSTALLER} |
| 197 | EOF |
| 198 | ) |
| 199 | |
| 200 | ISSUE_URL=$(gh issue create \ |
| 201 | --repo microsoft/winget-pkgs \ |
| 202 | --title "[Package Request]: ${PACKAGE_IDENTIFIER} ${VERSION}" \ |
| 203 | --body "$ISSUE_BODY") |
| 204 | |
| 205 | echo "Opened issue ${ISSUE_URL}" |
| 206 | echo "issue_url=${ISSUE_URL}" >> "$GITHUB_OUTPUT" |
| 207 | echo "issue_number=${ISSUE_URL##*/}" >> "$GITHUB_OUTPUT" |
| 208 | |
| 209 | # Leave a gap so the issue and the PR aren't posted seconds apart. |
| 210 | - name: Sebat dulu ... |
| 211 | if: steps.issue.outputs.issue_number != '' |
| 212 | shell: bash |
| 213 | run: sleep $(( RANDOM % 61 + 150 )) |
| 214 | |
| 215 | - name: Submit new package |
| 216 | id: submit_new |
| 217 | if: steps.exists.outputs.found == 'false' && steps.exists.outputs.pending != 'true' |
| 218 | shell: pwsh |
| 219 | env: |
| 220 | WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }} |
| 221 | run: | |
| 222 | if (-not $env:WINGET_CREATE_GITHUB_TOKEN) { |
| 223 | Write-Error "WINGET_PR_TOKEN is not set. It needs a PAT with public_repo, read:org and read:discussion scopes so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR." |
| 224 | } |
| 225 | |
| 226 | $version = "${{ steps.release.outputs.version }}" |
| 227 | |
| 228 | # Tee the output so we can scrape the PR url wingetcreate prints on success. |
| 229 | # --no-open because the runner has no browser to open the PR in. |
| 230 | .\wingetcreate.exe submit manifests ` |
| 231 | --prtitle "New package: $env:PACKAGE_IDENTIFIER version $version" ` |
| 232 | --no-open 2>&1 | Tee-Object -Variable output |
| 233 | |
| 234 | if ($LASTEXITCODE -ne 0) { |
| 235 | Write-Error "wingetcreate submit failed with exit code $LASTEXITCODE" |
| 236 | } |
| 237 | |
| 238 | $pr = ($output | Select-String -Pattern 'https://github\.com/microsoft/winget-pkgs/pull/\d+' ` |
| 239 | | Select-Object -First 1).Matches.Value |
| 240 | if ($pr) { |
| 241 | $number = $pr -replace '.*/pull/','' |
| 242 | "pr_url=$pr" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 243 | "pr_number=$number" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 244 | Write-Host "Opened $pr" |
| 245 | } else { |
| 246 | Write-Warning "Could not scrape a PR url from wingetcreate output." |
| 247 | } |
| 248 | |
| 249 | - name: Submit manifest update |
| 250 | id: submit_update |
| 251 | if: steps.exists.outputs.found == 'true' |
| 252 | shell: pwsh |
| 253 | env: |
| 254 | WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }} |
| 255 | run: | |
| 256 | if (-not $env:WINGET_CREATE_GITHUB_TOKEN) { |
| 257 | Write-Error "WINGET_PR_TOKEN is not set. It needs a PAT with public_repo, read:org and read:discussion scopes so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR." |
| 258 | } |
| 259 | |
| 260 | $tag = "${{ steps.release.outputs.tag }}" |
| 261 | $version = "${{ steps.release.outputs.version }}" |
| 262 | $base = "https://github.com/${env:REPO}/releases/download/$tag" |
| 263 | |
| 264 | # Single x64 zip installer — no arch suffix needed in the URL hint. |
| 265 | # Tee the output so we can scrape the PR url wingetcreate prints on success. |
| 266 | .\wingetcreate.exe update $env:PACKAGE_IDENTIFIER ` |
| 267 | --version $version ` |
| 268 | --urls "$base/splitfire-agent-windows-x64.zip|x64" ` |
| 269 | --release-notes-url "https://github.com/${env:REPO}/releases/tag/$tag" ` |
| 270 | --release-date "${{ steps.release.outputs.date }}" ` |
| 271 | --prtitle "Update $env:PACKAGE_IDENTIFIER to version $version" ` |
| 272 | --submit ` |
| 273 | --no-open 2>&1 | Tee-Object -Variable output |
| 274 | |
| 275 | if ($LASTEXITCODE -ne 0) { |
| 276 | Write-Error "wingetcreate failed with exit code $LASTEXITCODE" |
| 277 | } |
| 278 | |
| 279 | $pr = ($output | Select-String -Pattern 'https://github\.com/microsoft/winget-pkgs/pull/\d+' ` |
| 280 | | Select-Object -First 1).Matches.Value |
| 281 | if ($pr) { |
| 282 | $number = $pr -replace '.*/pull/','' |
| 283 | "pr_url=$pr" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 284 | "pr_number=$number" | Out-File -FilePath $env:GITHUB_OUTPUT -Append |
| 285 | Write-Host "Opened $pr" |
| 286 | } else { |
| 287 | Write-Warning "Could not scrape a PR url from wingetcreate output." |
| 288 | } |
| 289 | |
| 290 | # Tie the manifest PR back to the tracking issue and tick the submission |
| 291 | # checklist winget-pkgs asks for. Runs under WINGET_PR_TOKEN so the comment/edit |
| 292 | # is attributed to the same identity that opened the PR. |
| 293 | - name: Set the winget PR body |
| 294 | id: link |
| 295 | if: steps.issue.outputs.issue_number != '' && (steps.submit_new.outputs.pr_number != '' || steps.submit_update.outputs.pr_number != '') |
| 296 | shell: bash |
| 297 | env: |
| 298 | GH_TOKEN: ${{ secrets.WINGET_PR_TOKEN }} |
| 299 | run: | |
| 300 | set -euo pipefail |
| 301 | |
| 302 | if [ -z "${GH_TOKEN:-}" ]; then |
| 303 | echo "::error::WINGET_PR_TOKEN is not set. It needs a PAT that can edit PRs on microsoft/winget-pkgs." |
| 304 | exit 1 |
| 305 | fi |
| 306 | |
| 307 | ISSUE_NUMBER="${{ steps.issue.outputs.issue_number }}" |
| 308 | PR_NUMBER="${{ steps.submit_new.outputs.pr_number }}${{ steps.submit_update.outputs.pr_number }}" |
| 309 | VERSION="${{ steps.release.outputs.version }}" |
| 310 | |
| 311 | # printf, not an indented heredoc: GitHub dedents only the common leading |
| 312 | # whitespace of the run block, which would leave a leading-space-prefixed |
| 313 | # closing EOF that bash would not recognise as the terminator. |
| 314 | BODY=$(printf '%s\n' \ |
| 315 | "Resolves #${ISSUE_NUMBER}" \ |
| 316 | "" \ |
| 317 | "${PACKAGE_IDENTIFIER} version ${VERSION}." \ |
| 318 | "" \ |
| 319 | "- [x] Have you signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs)?" \ |
| 320 | "- [x] Have you checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change?" \ |
| 321 | "- [x] Have you validated your manifest locally with \`winget validate --manifest <path>\`?" \ |
| 322 | "- [x] Have you tested your manifest locally with \`winget install --manifest <path>\`?" \ |
| 323 | "- [x] Does your manifest conform to the [1.12 schema](https://github.com/microsoft/winget-pkgs/tree/master/doc/manifest/schema/1.12.0)?" \ |
| 324 | "- [x] This PR is linked to an issue.") |
| 325 | |
| 326 | gh pr edit "$PR_NUMBER" \ |
| 327 | --repo microsoft/winget-pkgs \ |
| 328 | --body "$BODY" |