development
yml 311 lines 13.3 KB
Raw
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.splitfire-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/splitfire-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 else
105 echo "No ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}; submitting it as a new package."
106 echo "found=false" >> "$GITHUB_OUTPUT"
107 fi
108
109 - name: Render manifests for a first submission
110 if: steps.exists.outputs.found == 'false'
111 shell: bash
112 run: |
113 TAG="${{ steps.release.outputs.tag }}"
114 VERSION="${{ steps.release.outputs.version }}"
115 SHA_X64="${{ steps.sha.outputs.sha_x64 }}"
116 RELEASE_DATE="${{ steps.release.outputs.date }}"
117
118 mkdir -p manifests
119
120 for template in packaging/winget/*.yaml.in; do
121 out="manifests/$(basename "$template" .in)"
122 sed \
123 -e "s|@VERSION@|${VERSION}|g" \
124 -e "s|@TAG@|${TAG}|g" \
125 -e "s|@REPO@|${REPO}|g" \
126 -e "s|@SHA_X64@|${SHA_X64}|g" \
127 -e "s|@RELEASE_DATE@|${RELEASE_DATE}|g" \
128 "$template" > "$out"
129
130 echo "--- ${out} ---"
131 cat "$out"
132 done
133
134 - name: Download wingetcreate
135 shell: pwsh
136 run: Invoke-WebRequest -Uri "https://aka.ms/wingetcreate/latest" -OutFile wingetcreate.exe
137
138 # winget-pkgs convention: file the "please add/update this package"
139 # Package Request issue *first*, then open the manifest PR that fulfils
140 # it with "Resolves #N". The other way round reads as a request and its
141 # fix posted seconds apart.
142 #
143 # The issue and the PR are authored by two separate PATs, both with
144 # public_repo scope on microsoft/winget-pkgs (fork + open issues/PRs):
145 # WINGET_ISSUE_TOKEN files the Package Request issue.
146 # WINGET_PR_TOKEN opens the manifest PR. It also needs read:org and
147 # read:discussion: the "Set the winget PR body" step
148 # calls `gh pr edit`, whose GraphQL query resolves
149 # org/team and discussion fields and fails with a
150 # scope error without them.
151 - name: File the winget Package Request issue
152 id: issue
153 shell: bash
154 env:
155 GH_TOKEN: ${{ secrets.WINGET_ISSUE_TOKEN }}
156 run: |
157 set -euo pipefail
158
159 if [ -z "${GH_TOKEN:-}" ]; then
160 echo "::error::WINGET_ISSUE_TOKEN is not set. It needs a PAT (public_repo) for the account that should author the Package Request issue."
161 exit 1
162 fi
163
164 VERSION="${{ steps.release.outputs.version }}"
165 TAG="${{ steps.release.outputs.tag }}"
166 INSTALLER="https://github.com/${REPO}/releases/download/${TAG}/splitfire-agent-windows-x64.zip"
167
168 # winget-pkgs' Package Request is an issue *form*
169 # (.github/ISSUE_TEMPLATE/package_request.yml): the title must be
170 # "[Package Request]: ..." and the body has to carry the labelled
171 # fields below (Installer Url especially). A free-text body lands as
172 # Needs-Triage and can't be acted on.
173 ISSUE_BODY=$(cat <<EOF
174 Download Page Url: https://github.com/${REPO}/releases/tag/${TAG}
175 Publisher: SplitFireAI
176 Package Name: SplitFire Agent
177 Description: Music-domain ACP agent for theory, production, industry, culture and live shows.
178 Package Version: ${VERSION}
179 Installer Url: ${INSTALLER}
180 EOF
181 )
182
183 ISSUE_URL=$(gh issue create \
184 --repo microsoft/winget-pkgs \
185 --title "[Package Request]: ${PACKAGE_IDENTIFIER} ${VERSION}" \
186 --body "$ISSUE_BODY")
187
188 echo "Opened issue ${ISSUE_URL}"
189 echo "issue_url=${ISSUE_URL}" >> "$GITHUB_OUTPUT"
190 echo "issue_number=${ISSUE_URL##*/}" >> "$GITHUB_OUTPUT"
191
192 # Leave a gap so the issue and the PR aren't posted seconds apart.
193 - name: Sebat dulu ...
194 if: steps.issue.outputs.issue_number != ''
195 shell: bash
196 run: sleep $(( RANDOM % 61 + 150 ))
197
198 - name: Submit new package
199 id: submit_new
200 if: steps.exists.outputs.found == 'false'
201 shell: pwsh
202 env:
203 WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }}
204 run: |
205 if (-not $env:WINGET_CREATE_GITHUB_TOKEN) {
206 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."
207 }
208
209 $version = "${{ steps.release.outputs.version }}"
210
211 # Tee the output so we can scrape the PR url wingetcreate prints on success.
212 # --no-open because the runner has no browser to open the PR in.
213 .\wingetcreate.exe submit manifests `
214 --prtitle "New package: $env:PACKAGE_IDENTIFIER version $version" `
215 --no-open 2>&1 | Tee-Object -Variable output
216
217 if ($LASTEXITCODE -ne 0) {
218 Write-Error "wingetcreate submit failed with exit code $LASTEXITCODE"
219 }
220
221 $pr = ($output | Select-String -Pattern 'https://github\.com/microsoft/winget-pkgs/pull/\d+' `
222 | Select-Object -First 1).Matches.Value
223 if ($pr) {
224 $number = $pr -replace '.*/pull/',''
225 "pr_url=$pr" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
226 "pr_number=$number" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
227 Write-Host "Opened $pr"
228 } else {
229 Write-Warning "Could not scrape a PR url from wingetcreate output."
230 }
231
232 - name: Submit manifest update
233 id: submit_update
234 if: steps.exists.outputs.found == 'true'
235 shell: pwsh
236 env:
237 WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }}
238 run: |
239 if (-not $env:WINGET_CREATE_GITHUB_TOKEN) {
240 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."
241 }
242
243 $tag = "${{ steps.release.outputs.tag }}"
244 $version = "${{ steps.release.outputs.version }}"
245 $base = "https://github.com/${env:REPO}/releases/download/$tag"
246
247 # Single x64 zip installer — no arch suffix needed in the URL hint.
248 # Tee the output so we can scrape the PR url wingetcreate prints on success.
249 .\wingetcreate.exe update $env:PACKAGE_IDENTIFIER `
250 --version $version `
251 --urls "$base/splitfire-agent-windows-x64.zip|x64" `
252 --release-notes-url "https://github.com/${env:REPO}/releases/tag/$tag" `
253 --release-date "${{ steps.release.outputs.date }}" `
254 --prtitle "Update $env:PACKAGE_IDENTIFIER to version $version" `
255 --submit `
256 --no-open 2>&1 | Tee-Object -Variable output
257
258 if ($LASTEXITCODE -ne 0) {
259 Write-Error "wingetcreate failed with exit code $LASTEXITCODE"
260 }
261
262 $pr = ($output | Select-String -Pattern 'https://github\.com/microsoft/winget-pkgs/pull/\d+' `
263 | Select-Object -First 1).Matches.Value
264 if ($pr) {
265 $number = $pr -replace '.*/pull/',''
266 "pr_url=$pr" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
267 "pr_number=$number" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
268 Write-Host "Opened $pr"
269 } else {
270 Write-Warning "Could not scrape a PR url from wingetcreate output."
271 }
272
273 # Tie the manifest PR back to the tracking issue and tick the submission
274 # checklist winget-pkgs asks for. Runs under WINGET_PR_TOKEN so the comment/edit
275 # is attributed to the same identity that opened the PR.
276 - name: Set the winget PR body
277 id: link
278 if: steps.issue.outputs.issue_number != '' && (steps.submit_new.outputs.pr_number != '' || steps.submit_update.outputs.pr_number != '')
279 shell: bash
280 env:
281 GH_TOKEN: ${{ secrets.WINGET_PR_TOKEN }}
282 run: |
283 set -euo pipefail
284
285 if [ -z "${GH_TOKEN:-}" ]; then
286 echo "::error::WINGET_PR_TOKEN is not set. It needs a PAT that can edit PRs on microsoft/winget-pkgs."
287 exit 1
288 fi
289
290 ISSUE_NUMBER="${{ steps.issue.outputs.issue_number }}"
291 PR_NUMBER="${{ steps.submit_new.outputs.pr_number }}${{ steps.submit_update.outputs.pr_number }}"
292 VERSION="${{ steps.release.outputs.version }}"
293
294 # printf, not an indented heredoc: GitHub dedents only the common leading
295 # whitespace of the run block, which would leave a leading-space-prefixed
296 # closing EOF that bash would not recognise as the terminator.
297 BODY=$(printf '%s\n' \
298 "Resolves #${ISSUE_NUMBER}" \
299 "" \
300 "${PACKAGE_IDENTIFIER} version ${VERSION}." \
301 "" \
302 "- [x] Have you signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs)?" \
303 "- [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?" \
304 "- [x] Have you validated your manifest locally with \`winget validate --manifest <path>\`?" \
305 "- [x] Have you tested your manifest locally with \`winget install --manifest <path>\`?" \
306 "- [x] Does your manifest conform to the [1.12 schema](https://github.com/microsoft/winget-pkgs/tree/master/doc/manifest/schema/1.12.0)?" \
307 "- [x] This PR is linked to an issue.")
308
309 gh pr edit "$PR_NUMBER" \
310 --repo microsoft/winget-pkgs \
311 --body "$BODY"