Repository navigation
204 lines (189 loc) · 8.43 KB
/
Copy pathwinget.yml
File metadata and controls
204 lines (189 loc) · 8.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
name: WinGet
run-name: WinGet ${{ inputs.version }}${{ inputs.dry_run && ' (dry run)' || '' }}
# Sends each stable Windows release to microsoft/winget-pkgs, so
# `winget install Threadlines.Threadlines` and `winget upgrade` pick it up.
# release.yml starts this after it publishes a stable release: GitHub doesn't
# start workflows from GITHUB_TOKEN release events, and a workflow_dispatch is
# exempt. Run it by hand to retry a version.
#
# Needs the WINGET_TOKEN secret: a classic GitHub token with the public_repo
# and workflow scopes (komac brings the fork up to date with winget-pkgs, whose
# own workflow files change, and GitHub refuses that push without workflow).
# The pull request opens from that account's fork of winget-pkgs, which the
# first run creates. That account's first pull request there also needs
# Microsoft's CLA, agreed to once in a comment on it.
on:
workflow_dispatch:
inputs:
version:
description: "Stable version to send, for example 0.9.0."
required: true
type: string
dry_run:
description: "Build and check the manifests without opening the pull request."
required: false
type: boolean
default: false
permissions:
contents: read
concurrency:
group: winget-${{ inputs.version }}
cancel-in-progress: false
env:
KOMAC_VERSION: 2.17.2
# From the release's SHA256SUMS, for komac-<version>-x86_64-unknown-linux-gnu.tar.gz.
KOMAC_SHA256: b03b020eec98acfb0b53e284a6e21815b884be33de6785b97e7a120f0e748966
jobs:
# Until a moderator approves our first ("New package") pull request,
# Threadlines isn't in winget-pkgs and every version we send is another new
# package request that waits weeks in the same queue. So while one is open,
# skip instead of piling up more; the oldest keeps our place in line. Once
# it's approved, versions go out as normal updates. Send the newest version
# by hand that day so winget doesn't sit on the approved one.
check:
name: Check whether Threadlines is listed
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
waiting: ${{ steps.listing.outputs.waiting }}
steps:
- name: Look for the package and a waiting request
id: listing
env:
GH_TOKEN: ${{ github.token }}
WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }}
run: |
set -euo pipefail
status="$(gh api --include repos/microsoft/winget-pkgs/contents/manifests/t/Threadlines/Threadlines 2> /dev/null | head -n 1 || true)"
if [[ "$status" == *" 200"* ]]; then
echo "Threadlines.Threadlines is in winget-pkgs; sending an update."
echo "waiting=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "$status" != *" 404"* ]]; then
echo "::error::Couldn't tell whether Threadlines is in winget-pkgs (got '${status}')."
exit 1
fi
# Only our own requests count: anyone can open a pull request with
# this title, and a stranger's must not hold back our releases.
if [[ -z "$WINGET_TOKEN" ]]; then
echo "::error::Add a WINGET_TOKEN secret (a classic GitHub token with public_repo and workflow) to send releases to winget."
exit 1
fi
owner="$(GH_TOKEN="$WINGET_TOKEN" gh api user --jq .login)"
pending="$(gh api -X GET search/issues \
-f q="repo:microsoft/winget-pkgs is:pr is:open author:${owner} in:title \"New package: Threadlines.Threadlines\"" \
--jq '[.items[].html_url] | join(" ")')"
if [[ -n "$pending" ]]; then
echo "::notice::Skipped: our first winget request still waits for a moderator (${pending}). Send the newest version by hand once it's approved."
echo "waiting=true" >> "$GITHUB_OUTPUT"
else
echo "No Threadlines package and no waiting request; sending a new one."
echo "waiting=false" >> "$GITHUB_OUTPUT"
fi
submit:
name: Send to winget-pkgs
needs: check
# A dry run only builds and checks the manifests, so it runs either way.
if: ${{ inputs.dry_run || needs.check.outputs.waiting != 'true' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Check for the token
env:
WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }}
run: |
if [[ -z "$WINGET_TOKEN" ]]; then
echo "::error::Add a WINGET_TOKEN secret (a classic GitHub token with public_repo and workflow) to send releases to winget."
exit 1
fi
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@cab1ab9eaff52d4857875f4f2c016e36af8f2c76 # v1.22.0
with:
node-version: "24"
cache: true
run-install: false
- name: Install dependencies
run: vp install --frozen-lockfile --ignore-scripts
- name: Find the Windows installer
id: release
env:
GH_TOKEN: ${{ github.token }}
DISPATCH_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
version="${DISPATCH_VERSION#v}"
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::winget only gets plain stable versions, got '${version}'."
exit 1
fi
installer="Threadlines-${version}-win-x64.exe"
release="$(gh release view "v${version}" --json isDraft,isPrerelease,publishedAt)"
if [[ "$(jq -r '.isDraft or .isPrerelease' <<< "$release")" == "true" ]]; then
echo "::error::v${version} isn't a published stable release."
exit 1
fi
gh release download "v${version}" --pattern "$installer" --dir installer --clobber
sha256="$(sha256sum "installer/${installer}" | cut -d' ' -f1)"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "sha256=${sha256}" >> "$GITHUB_OUTPUT"
echo "release_date=$(jq -r '.publishedAt[0:10]' <<< "$release")" >> "$GITHUB_OUTPUT"
- name: Write the manifests
env:
VERSION: ${{ steps.release.outputs.version }}
SHA256: ${{ steps.release.outputs.sha256 }}
RELEASE_DATE: ${{ steps.release.outputs.release_date }}
run: |
set -euo pipefail
node scripts/winget-manifests.ts \
--version "$VERSION" \
--installer-sha256 "$SHA256" \
--release-date "$RELEASE_DATE" \
--out winget
find winget -name '*.yaml' -print -exec cat {} \;
- name: Install Komac
run: |
set -euo pipefail
archive="komac-${KOMAC_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
mkdir -p "$RUNNER_TEMP/komac"
curl -fsSL -o "$RUNNER_TEMP/komac/${archive}" \
"https://github.com/russellbanks/Komac/releases/download/v${KOMAC_VERSION}/${archive}"
echo "${KOMAC_SHA256} $RUNNER_TEMP/komac/${archive}" | sha256sum --check
tar -xzf "$RUNNER_TEMP/komac/${archive}" -C "$RUNNER_TEMP/komac" komac
echo "$RUNNER_TEMP/komac" >> "$GITHUB_PATH"
- name: Make sure the winget-pkgs fork exists
if: ${{ !inputs.dry_run }}
env:
GH_TOKEN: ${{ secrets.WINGET_TOKEN }}
# Komac opens the pull request from the token owner's fork but doesn't
# create it. GitHub makes a fork in the background, so wait for it.
run: |
set -euo pipefail
owner="$(gh api user --jq .login)"
if ! gh api "repos/${owner}/winget-pkgs" --silent 2> /dev/null; then
gh repo fork microsoft/winget-pkgs --clone=false --default-branch-only
fi
for attempt in $(seq 1 30); do
if gh api "repos/${owner}/winget-pkgs/branches/master" --silent 2> /dev/null; then
echo "Fork ready: ${owner}/winget-pkgs"
exit 0
fi
echo "Waiting for ${owner}/winget-pkgs (attempt ${attempt}/30)"
sleep 10
done
echo "::error::${owner}/winget-pkgs never became ready."
exit 1
- name: Open the winget-pkgs pull request
env:
# Komac reads its token from GITHUB_TOKEN.
GITHUB_TOKEN: ${{ secrets.WINGET_TOKEN }}
IS_DRY_RUN: ${{ inputs.dry_run }}
run: |
set -euo pipefail
args=(submit winget --yes)
if [[ "$IS_DRY_RUN" == "true" ]]; then
args+=(--dry-run)
fi
komac "${args[@]}"