Skip to content

Commit 405925f

Browse files
authored
Merge pull request #233 from getsigit/fix/winget-issue-first-two-token
ci(winget): file Package Request issue first, split into two tokens
2 parents 2d011fc + 6728985 commit 405925f

1 file changed

Lines changed: 86 additions & 35 deletions

File tree

‎.github/workflows/release-winget.yml‎

Lines changed: 86 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,65 @@ jobs:
123123
shell: pwsh
124124
run: Invoke-WebRequest -Uri "https://aka.ms/wingetcreate/latest" -OutFile wingetcreate.exe
125125

126+
# winget-pkgs convention: file the "please add/update this package"
127+
# Package Request issue *first*, then open the manifest PR that fulfils
128+
# it with "Resolves #N". Doing it the other way round (PR first, issue
129+
# after) reads as "here's a request, and here's the PR that already did
130+
# it", posted seconds apart.
131+
#
132+
# The issue and the PR are authored by two separate PATs, configured as
133+
# the repo secrets WINGET_ISSUE_TOKEN (the Package Request issue) and
134+
# WINGET_PR_TOKEN (the manifest PR). Both need public_repo scope on
135+
# microsoft/winget-pkgs (fork + open issues/PRs). WINGET_PR_TOKEN
136+
# replaces the old single WINGET_TOKEN.
137+
- name: File the winget Package Request issue
138+
id: issue
139+
shell: bash
140+
env:
141+
# Authored by the issue account for this repo.
142+
GH_TOKEN: ${{ secrets.WINGET_ISSUE_TOKEN }}
143+
run: |
144+
set -euo pipefail
145+
146+
if [ -z "${GH_TOKEN:-}" ]; then
147+
echo "WINGET_ISSUE_TOKEN is not set. It needs a PAT (public_repo) for the account that should author the Package Request issue." >&2
148+
exit 1
149+
fi
150+
151+
VERSION="${{ steps.release.outputs.version }}"
152+
TAG="${{ steps.release.outputs.tag }}"
153+
154+
# The release assets, same URLs the update step feeds wingetcreate.
155+
BASE="https://github.com/${REPO}/releases/download/${TAG}"
156+
INSTALLER_AMD64="${BASE}/sigit-win-amd64.exe"
157+
INSTALLER_ARM64="${BASE}/sigit-win-arm64.exe"
158+
159+
# winget-pkgs' Package Request is an issue *form*
160+
# (.github/ISSUE_TEMPLATE/package_request.yml): the title must be
161+
# "[Package Request]: ..." and the body has to carry the labelled
162+
# fields below (Installer Url especially — without it a maintainer
163+
# just replies "please provide the installer link"). A free-text
164+
# body lands as Needs-Triage and can't be acted on.
165+
ISSUE_BODY=$(cat <<EOF
166+
Download Page Url: https://github.com/${REPO}/releases/tag/${TAG}
167+
Publisher: getSigit
168+
Package Name: siGit Code
169+
Description: siGit Code, an AI coding agent that runs on your machine.
170+
Package Version: ${VERSION}
171+
Installer Url: ${INSTALLER_AMD64}
172+
Installer Url: ${INSTALLER_ARM64}
173+
EOF
174+
)
175+
176+
ISSUE_URL=$(gh issue create \
177+
--repo microsoft/winget-pkgs \
178+
--title "[Package Request]: ${PACKAGE_IDENTIFIER} ${VERSION}" \
179+
--body "$ISSUE_BODY")
180+
181+
echo "Opened issue ${ISSUE_URL}"
182+
echo "issue_url=${ISSUE_URL}" >> "$GITHUB_OUTPUT"
183+
echo "issue_number=${ISSUE_URL##*/}" >> "$GITHUB_OUTPUT"
184+
126185
- name: Submit new package
127186
id: submit_new
128187
if: steps.exists.outputs.found == 'false'
@@ -131,10 +190,11 @@ jobs:
131190
# wingetcreate reads the token from this variable. Passing it as
132191
# --token instead makes the tool warn that the token can end up in
133192
# logs, which on a shared runner is not a warning worth ignoring.
134-
WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_TOKEN }}
193+
# This is the PR-author account for this repo (see mapping above).
194+
WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }}
135195
run: |
136196
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."
197+
Write-Error "WINGET_PR_TOKEN is not set. It needs a PAT with public_repo scope so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR."
138198
}
139199
140200
$version = "${{ steps.release.outputs.version }}"
@@ -164,10 +224,11 @@ jobs:
164224
if: steps.exists.outputs.found == 'true'
165225
shell: pwsh
166226
env:
167-
WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_TOKEN }}
227+
# PR-author account for this repo (see mapping above).
228+
WINGET_CREATE_GITHUB_TOKEN: ${{ secrets.WINGET_PR_TOKEN }}
168229
run: |
169230
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."
231+
Write-Error "WINGET_PR_TOKEN is not set. It needs a PAT with public_repo scope so wingetcreate can fork microsoft/winget-pkgs and open the manifest PR."
171232
}
172233
173234
$tag = "${{ steps.release.outputs.tag }}"
@@ -198,58 +259,47 @@ jobs:
198259
Write-Warning "Could not find the PR URL in wingetcreate output; skipping issue linking."
199260
}
200261
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.
262+
# wingetcreate has no --prbody flag (only --prtitle), so it always opens
263+
# the PR with the winget-pkgs template: an empty Description and an
264+
# unticked "Linked to an issue" box next to a "Resolves #[Issue Number]"
265+
# placeholder. The issue already exists (filed first, above), so this
266+
# step just rewrites the body to point the PR at it with "Resolves #N".
206267
#
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
268+
# This must run as the PR author (WINGET_PR_TOKEN) — the account that
269+
# opened the PR via wingetcreate — since only the author (or a repo
270+
# maintainer) can edit it.
271+
- name: Set the winget PR body and link the issue
212272
id: link
213273
if: >-
214274
(steps.submit_new.outputs.pr_number != '') ||
215275
(steps.submit_update.outputs.pr_number != '')
216276
shell: bash
217277
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 }}
278+
GH_TOKEN: ${{ secrets.WINGET_PR_TOKEN }}
222279
run: |
223280
set -euo pipefail
224281
225282
PR_URL="${{ steps.submit_new.outputs.pr_url || steps.submit_update.outputs.pr_url }}"
226-
NEW_PACKAGE="${{ steps.exists.outputs.found == 'false' }}"
283+
ISSUE_NUMBER="${{ steps.issue.outputs.issue_number }}"
227284
VERSION="${{ steps.release.outputs.version }}"
228285
TAG="${{ steps.release.outputs.tag }}"
229286
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).
243287
if [ -n "$ISSUE_NUMBER" ]; then
244288
CHECKBOX="- [x] Linked to an issue (if applicable)"
245289
RESOLVES="- Resolves #${ISSUE_NUMBER}"
246-
DESC="Adds ${PACKAGE_IDENTIFIER} version ${VERSION} from ${TAG}."
247290
else
248291
CHECKBOX="- [ ] Linked to an issue (if applicable)"
249292
RESOLVES=""
293+
fi
294+
295+
if [ "${{ steps.exists.outputs.found }}" = "false" ]; then
296+
DESC="Adds ${PACKAGE_IDENTIFIER} version ${VERSION} from ${TAG}."
297+
else
250298
DESC="Updates ${PACKAGE_IDENTIFIER} to version ${VERSION} from ${TAG}."
251299
fi
252300
301+
# Mirrors the current .github/PULL_REQUEST_TEMPLATE.md; keep the
302+
# checklist items in sync with it (e.g. the 1.12 schema line).
253303
BODY=$(cat <<EOF
254304
## 📖 Description
255305
${DESC}
@@ -260,8 +310,9 @@ jobs:
260310
## 📦 Manifest Checklist
261311
- [x] Checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change
262312
- [x] This PR only modifies one (1) manifest
263-
- [x] Validated manifest locally with \`winget validate\`
264-
- [x] Tested manifest locally with \`winget install\`
313+
- [x] Validated manifest locally with \`winget validate --manifest <directory>\`
314+
- [x] Tested manifest locally with \`winget install --manifest <directory>\`
315+
- [x] Manifest conforms to the [1.12 schema](https://github.com/microsoft/winget-pkgs/tree/master/doc/manifest/schema/1.12.0)
265316
EOF
266317
)
267318

0 commit comments

Comments
 (0)