1 name: winget Release
2
3 # Dispatched by release-github.yml once the release and its checksums 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 URLs and re-hashes the installers 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 on:
17 workflow_dispatch:
18 inputs:
19 tag:
20 description: "Release tag (e.g. v1.5.2)"
21 required: true
22
23 concurrency:
24 # A re-pushed or re-dispatched tag fires this a second time. Queue the
25 # duplicate behind the original instead of cancelling it: cancelling a run
26 # mid-publish can leave a channel half-uploaded, whereas a queued duplicate
27 # just hits the "already published" check and exits clean.
28 group: ${{ github.workflow }}-${{ github.event.inputs.tag || github.ref_name }}
29 cancel-in-progress: false
30
31 permissions:
32 contents: read
33
34 env:
35 REPO: getsigit/sigit
36 PACKAGE_IDENTIFIER: getSigit.siGitCode
37
38 jobs:
39 submit-winget-manifest:
40 name: Submit winget manifest
41 # wingetcreate is a Windows-only tool.
42 runs-on: windows-latest
43
44 steps:
45 - name: Check out repository
46 uses: actions/checkout@v6
47
48 - name: Resolve tag, version and release date
49 id: release
50 shell: bash
51 env:
52 GH_TOKEN: ${{ github.token }}
53 run: |
54 TAG="${{ github.event.inputs.tag }}"
55 VERSION="${TAG#v}"
56 # wingetcreate wants ReleaseDate as YYYY-MM-DD.
57 DATE=$(gh release view "$TAG" --repo "$REPO" --json publishedAt --jq '.publishedAt[0:10]')
58
59 echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
60 echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
61 echo "date=${DATE}" >> "$GITHUB_OUTPUT"
62
63 - name: Check whether the package is already in winget-pkgs
64 id: exists
65 shell: bash
66 env:
67 GH_TOKEN: ${{ github.token }}
68 run: |
69 # manifests are filed under the lowercased first letter of the
70 # publisher, e.g. manifests/g/getSigit/siGitCode.
71 PUBLISHER="${PACKAGE_IDENTIFIER%%.*}"
72 NAME="${PACKAGE_IDENTIFIER#*.}"
73 FIRST=$(echo "${PUBLISHER:0:1}" | tr '[:upper:]' '[:lower:]')
74 PATH_IN_REPO="manifests/${FIRST}/${PUBLISHER}/${NAME}"
75
76 if gh api "repos/microsoft/winget-pkgs/contents/${PATH_IN_REPO}" >/dev/null 2>&1; then
77 echo "Found ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}; submitting an update."
78 echo "found=true" >> "$GITHUB_OUTPUT"
79 else
80 echo "No ${PACKAGE_IDENTIFIER} at ${PATH_IN_REPO}; submitting it as a new package."
81 echo "found=false" >> "$GITHUB_OUTPUT"
82 fi
83
84 - name: Render manifests for a first submission
85 if: steps.exists.outputs.found == 'false'
86 shell: bash
87 env:
88 GH_TOKEN: ${{ github.token }}
89 run: |
90 TAG="${{ steps.release.outputs.tag }}"
91 VERSION="${{ steps.release.outputs.version }}"
92
93 mkdir -p artifacts manifests
94
95 gh release download "$TAG" \
96 --repo "$REPO" \
97 --pattern "sigit-win-*.exe.sha256" \
98 --dir artifacts/
99
100 # The schema wants 64 hex characters; the community validation
101 # pipeline writes them uppercase, so match that.
102 SHA_AMD64=$(tr -d '[:space:]' < artifacts/sigit-win-amd64.exe.sha256 | tr '[:lower:]' '[:upper:]')
103 SHA_ARM64=$(tr -d '[:space:]' < artifacts/sigit-win-arm64.exe.sha256 | tr '[:lower:]' '[:upper:]')
104
105 RELEASE_DATE="${{ steps.release.outputs.date }}"
106
107 for template in packaging/winget/*.yaml.in; do
108 out="manifests/$(basename "$template" .in)"
109 sed \
110 -e "s|@VERSION@|${VERSION}|g" \
111 -e "s|@TAG@|${TAG}|g" \
112 -e "s|@REPO@|${REPO}|g" \
113 -e "s|@SHA_AMD64@|${SHA_AMD64}|g" \
114 -e "s|@SHA_ARM64@|${SHA_ARM64}|g" \
115 -e "s|@RELEASE_DATE@|${RELEASE_DATE}|g" \
116 "$template" > "$out"
117
118 echo "--- ${out} ---"
119 cat "$out"
120 done
121
122 - name: Download wingetcreate
123 shell: pwsh
124 run: Invoke-WebRequest -Uri "https://aka.ms/wingetcreate/latest" -OutFile wingetcreate.exe
125
126 - name: Submit new package
127 id: submit_new
128 if: steps.exists.outputs.found == 'false'
129 shell: pwsh
130 env:
131 # wingetcreate reads the token from this variable. Passing it as
132 # --token instead makes the tool warn that the token can end up in
133 # logs, which on a shared runner is not a warning worth ignoring.
134 WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_TOKEN }}
135 run: |
136 if (-not $env:WINGET_CREATE_GITHUB_TOKEN) {
137 Write-Error "WINGET_TOKEN is not set. It needs a PAT with public_repo scope so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR."
138 }
139
140 $version = "${{ steps.release.outputs.version }}"
141
142 # Tee stdout so we can scrape the PR URL afterwards. wingetcreate
143 # prints "Pull request can be found here: <url>" on success, and
144 # that line is the only handle we get on the PR it just opened.
145 # --no-open because the runner has no browser to open the PR in.
146 .\wingetcreate.exe submit manifests `
147 --prtitle "New package: $env:PACKAGE_IDENTIFIER version $version" `
148 --no-open 2>&1 | Tee-Object -Variable output
149
150 if ($LASTEXITCODE -ne 0) {
151 Write-Error "wingetcreate submit failed with exit code $LASTEXITCODE"
152 }
153
154 $match = [regex]::Match(($output -join "`n"), 'https://github\.com/microsoft/winget-pkgs/pull/(\d+)')
155 if ($match.Success) {
156 "pr_url=$($match.Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
157 "pr_number=$($match.Groups[1].Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
158 } else {
159 Write-Warning "Could not find the PR URL in wingetcreate output; skipping issue linking."
160 }
161
162 - name: Submit manifest update
163 id: submit_update
164 if: steps.exists.outputs.found == 'true'
165 shell: pwsh
166 env:
167 WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_TOKEN }}
168 run: |
169 if (-not $env:WINGET_CREATE_GITHUB_TOKEN) {
170 Write-Error "WINGET_TOKEN is not set. It needs a PAT with public_repo scope so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR."
171 }
172
173 $tag = "${{ steps.release.outputs.tag }}"
174 $version = "${{ steps.release.outputs.version }}"
175 $base = "https://github.com/${env:REPO}/releases/download/$tag"
176
177 # The trailing |x64 and |arm64 tell wingetcreate which installer
178 # entry each URL replaces. Without them it guesses from the file
179 # name, and "sigit-win-amd64.exe" is not a spelling it recognises.
180 .\wingetcreate.exe update $env:PACKAGE_IDENTIFIER `
181 --version $version `
182 --urls "$base/sigit-win-amd64.exe|x64" "$base/sigit-win-arm64.exe|arm64" `
183 --release-notes-url "https://github.com/${env:REPO}/releases/tag/$tag" `
184 --release-date "${{ steps.release.outputs.date }}" `
185 --prtitle "Update $env:PACKAGE_IDENTIFIER to version $version" `
186 --submit `
187 --no-open 2>&1 | Tee-Object -Variable output
188
189 if ($LASTEXITCODE -ne 0) {
190 Write-Error "wingetcreate failed with exit code $LASTEXITCODE"
191 }
192
193 $match = [regex]::Match(($output -join "`n"), 'https://github\.com/microsoft/winget-pkgs/pull/(\d+)')
194 if ($match.Success) {
195 "pr_url=$($match.Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
196 "pr_number=$($match.Groups[1].Value)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
197 } else {
198 Write-Warning "Could not find the PR URL in wingetcreate output; skipping issue linking."
199 }
200
201 # wingetcreate has no --prbody flag, so it always opens the PR with the
202 # winget-pkgs template: an empty Description and an unticked
203 # "Linked to an issue" box next to a "Resolves #[Issue Number]"
204 # placeholder. We used to tick that box and fill in the issue number by
205 # hand after every release. This step does it instead.
206 #
207 # On a first submission it also files the Package Request issue the
208 # linkable number comes from. Updates to an existing package don't need
209 # one (the checkbox is "if applicable"), so there we just fill the
210 # Description.
211 - name: Link the winget PR to a Package Request issue
212 id: link
213 if: >-
214 (steps.submit_new.outputs.pr_number != '') ||
215 (steps.submit_update.outputs.pr_number != '')
216 shell: bash
217 env:
218 # The PR and the issue both live in microsoft/winget-pkgs, which the
219 # default GITHUB_TOKEN can't write to. Reuse the wingetcreate PAT,
220 # which already has the scope to open PRs there.
221 GH_TOKEN: ${{ secrets.WINGET_TOKEN }}
222 run: |
223 set -euo pipefail
224
225 PR_URL="${{ steps.submit_new.outputs.pr_url || steps.submit_update.outputs.pr_url }}"
226 NEW_PACKAGE="${{ steps.exists.outputs.found == 'false' }}"
227 VERSION="${{ steps.release.outputs.version }}"
228 TAG="${{ steps.release.outputs.tag }}"
229
230 ISSUE_NUMBER=""
231 if [ "$NEW_PACKAGE" = "true" ]; then
232 ISSUE_URL=$(gh issue create \
233 --repo microsoft/winget-pkgs \
234 --title "Package Request: ${PACKAGE_IDENTIFIER} ${VERSION}" \
235 --body "Request to add ${PACKAGE_IDENTIFIER} version ${VERSION} to the Windows Package Manager Community Repository. Installers come from ${TAG} of ${REPO}.")
236 echo "Opened issue ${ISSUE_URL}"
237 ISSUE_NUMBER="${ISSUE_URL##*/}"
238 fi
239
240 # Rewrite the template body: fill the Description, tick the issue
241 # box when we have an issue, and drop in the real number (or remove
242 # the placeholder line on updates that aren't linked to anything).
243 if [ -n "$ISSUE_NUMBER" ]; then
244 CHECKBOX="- [x] Linked to an issue (if applicable)"
245 RESOLVES="- Resolves #${ISSUE_NUMBER}"
246 DESC="Adds ${PACKAGE_IDENTIFIER} version ${VERSION} from ${TAG}."
247 else
248 CHECKBOX="- [ ] Linked to an issue (if applicable)"
249 RESOLVES=""
250 DESC="Updates ${PACKAGE_IDENTIFIER} to version ${VERSION} from ${TAG}."
251 fi
252
253 BODY=$(cat <<EOF
254 ## 📖 Description
255 ${DESC}
256 ## ✅ Checklist
257 - [x] Signed the [Contributor License Agreement](https://cla.opensource.microsoft.com)
258 ${CHECKBOX}
259 ${RESOLVES}
260 ## 📦 Manifest Checklist
261 - [x] Checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change
262 - [x] This PR only modifies one (1) manifest
263 - [x] Validated manifest locally with \`winget validate\`
264 - [x] Tested manifest locally with \`winget install\`
265 EOF
266 )
267
268 gh pr edit "$PR_URL" --body "$BODY"
269 echo "Linked ${PR_URL} to issue #${ISSUE_NUMBER:-<none>}"