Repository navigation
315 lines (286 loc) · 13.6 KB
/
Copy pathpackages.yml
File metadata and controls
315 lines (286 loc) · 13.6 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
name: Publish package repositories
# Publishes both repositories to pkg.lookout.hackclub.com via Pages:
# /deb flat apt repository
# /rpm dnf repository
#
# Sources every package from the GitHub releases rather than from a build, so
# it runs in a couple of minutes and can be fired by hand at any time --
# getting a repository up, or repairing one, does not require cutting a tag.
#
# A Pages deploy replaces the whole site, so both repositories are rebuilt
# every run. They cannot be published independently.
on:
workflow_dispatch:
inputs:
tag:
description: "Release tag to publish (blank = the newest published release)"
required: false
type: string
workflow_call:
inputs:
tag:
required: true
type: string
concurrency:
group: pkg-pages
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
permissions:
# write only so the token can see a draft release: release.yml starts
# this for the tag while its release is still a draft. Nothing is written.
contents: write
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deploy.outputs.page_url }}
env:
KEEP: "5"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Install repository tooling
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends dpkg-dev apt-utils createrepo-c rpm
- name: Import the signing key
env:
APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }}
run: |
set -euo pipefail
if [ -z "${APT_GPG_PRIVATE_KEY:-}" ]; then
echo "::error::APT_GPG_PRIVATE_KEY is not set. Run scripts/apt-keygen.sh and add the secrets." >&2
exit 1
fi
export GNUPGHOME="$(mktemp -d)"
chmod 700 "$GNUPGHOME"
echo "GNUPGHOME=$GNUPGHOME" >> "$GITHUB_ENV"
printf '%s\n' "$APT_GPG_PRIVATE_KEY" | gpg --batch --quiet --import
fpr=$(gpg --batch --with-colons --list-secret-keys | awk -F: '/^fpr:/ {print $10; exit}')
echo "SIGNING_FPR=$fpr" >> "$GITHUB_ENV"
echo "signing with $fpr"
- name: Collect packages from the releases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
mkdir -p repo/deb/pool repo/rpm arch-in
grab() {
gh release download "$1" --dir repo/deb/pool --pattern '*.deb' --clobber || return 1
gh release download "$1" --dir repo/rpm --pattern '*.rpm' --clobber || true
gh release download "$1" --dir arch-in --pattern '*.pkg.tar.zst' --clobber || true
}
# A tag passed in is taken even if its release is still a draft --
# release.yml creates drafts, and the repositories have to advertise
# the version that was just built.
if [ -n "${TAG:-}" ]; then
echo "including $TAG"
grab "$TAG"
fi
# Older versions stay in the pool so that an index someone cached
# before this release still points at a .deb that exists, and so
# `apt install lookout=<version>` keeps working.
want="$KEEP"
[ -n "${TAG:-}" ] && want=$((KEEP - 1))
gh release list --limit 50 --exclude-drafts --json tagName -q '.[].tagName' \
| grep -v "^${TAG:-}$" | head -n "$want" | while read -r t; do
echo "including $t"
grab "$t" || echo " (no .deb assets on $t -- skipping)"
done
if [ -z "$(ls -A repo/deb/pool)" ]; then
echo "::error::No .deb assets found on any release -- nothing to publish." >&2
exit 1
fi
echo "deb pool: $(ls repo/deb/pool | wc -l) files, $(du -sh repo/deb/pool | cut -f1)"
echo "rpm pool: $(ls repo/rpm | wc -l) files, $(du -sh repo/rpm | cut -f1)"
echo "arch: $(ls arch-in 2>/dev/null | wc -l) files"
# Signing with a key whose public half isn't the one a .deb installs makes
# every enrolled machine fail apt update with NO_PUBKEY, and the fix can't
# be delivered through apt. Releases from before the keyring shipped carry
# no key at all, which is fine -- they just never enrolled anyone.
- name: Verify shipped keyrings match the signing key
run: |
set -euo pipefail
checked=0
for deb in repo/deb/pool/*.deb; do
if ! dpkg-deb --fsys-tarfile "$deb" \
| tar -xO ./usr/share/lookout/lookout-archive-keyring.asc > shipped.asc 2>/dev/null; then
echo "$(basename "$deb"): no keyring (predates enrollment) -- skipped"
continue
fi
fpr=$(gpg --batch --with-colons --show-keys shipped.asc | awk -F: '/^fpr:/ {print $10; exit}')
if [ "$fpr" != "$SIGNING_FPR" ]; then
echo "::error::$(basename "$deb") ships key $fpr, but the repository is signed by $SIGNING_FPR. Publishing this would make apt update fail on every enrolled machine." >&2
exit 1
fi
echo "$(basename "$deb"): key matches"
checked=$((checked + 1))
done
echo "$checked package(s) carried a keyring, all matching"
- name: Build the apt repository
run: |
set -euo pipefail
cd repo/deb
# One index for every arch and kept version; apt filters on each
# entry's Architecture and picks the highest Version.
dpkg-scanpackages --multiversion pool > Packages
gzip -9kf Packages
xz -9kf Packages
# After the compressed indices exist -- Release carries their hashes.
apt-ftparchive \
-o APT::FTPArchive::Release::Origin=Lookout \
-o APT::FTPArchive::Release::Label=Lookout \
-o APT::FTPArchive::Release::Suite=stable \
-o APT::FTPArchive::Release::Architectures="amd64 arm64" \
release . > Release
echo "--- Release ---"; cat Release
echo "--- indexed ---"; grep -E '^(Package|Version|Architecture|Filename):' Packages
- name: Sign the apt index
env:
APT_GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }}
run: |
set -euo pipefail
cd repo/deb
# InRelease is what modern apt fetches; Release.gpg for older clients.
gpg --batch --yes --pinentry-mode loopback --passphrase "$APT_GPG_PASSPHRASE" \
--local-user "$SIGNING_FPR" --clearsign -o InRelease Release
gpg --batch --yes --pinentry-mode loopback --passphrase "$APT_GPG_PASSPHRASE" \
--local-user "$SIGNING_FPR" -abs -o Release.gpg Release
# Verify with only the public half, the way a client would.
gpg --batch --armor --export "$SIGNING_FPR" > pub.asc
rm -rf verify && mkdir verify && chmod 700 verify
GNUPGHOME=verify gpg --batch --quiet --import pub.asc
GNUPGHOME=verify gpg --batch --verify InRelease
rm -rf verify pub.asc
# dnf checks signatures on the packages themselves, not only on the
# metadata, so gpgcheck=1 in the .repo file needs every rpm signed. They
# arrive off the releases unsigned.
- name: Sign the rpms and build the dnf repository
env:
APT_GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }}
run: |
set -euo pipefail
if [ -z "$(ls -A repo/rpm)" ]; then
echo "no .rpm assets on any release -- publishing the apt repository only"
rmdir repo/rpm
exit 0
fi
pass=$(mktemp); printf '%s' "$APT_GPG_PASSPHRASE" > "$pass"
trap 'shred -u "$pass" 2>/dev/null || rm -f "$pass"' EXIT
rpmsign \
--define "_gpg_name $SIGNING_FPR" \
--define "_gpg_sign_cmd_extra_args --pinentry-mode loopback --passphrase-file $pass" \
--addsign repo/rpm/*.rpm
# Read the signature back with only the public half, the way a
# client does -- rpmsign reports success on things dnf then rejects.
gpg --batch --armor --export "$SIGNING_FPR" > pub.asc
rpmkeys --import pub.asc
for r in repo/rpm/*.rpm; do
rpmkeys --checksig "$r" | grep -q "signatures OK" \
|| { echo "::error::$(basename "$r") is not verifiably signed" >&2; exit 1; }
done
rm pub.asc
echo "signed and verified $(ls repo/rpm/*.rpm | wc -l) rpm(s)"
createrepo_c --quiet repo/rpm
# repo_gpgcheck=1 verifies this detached signature over the metadata.
gpg --batch --yes --pinentry-mode loopback --passphrase "$APT_GPG_PASSPHRASE" \
--local-user "$SIGNING_FPR" --detach-sign --armor repo/rpm/repodata/repomd.xml
echo "dnf repository built"
# Runs last of the build steps: it lists what is actually in repo/, and
# Pages serves no directory indexes, so without it every path under the
# root that isn't an exact file is a 404 with no way to look around.
# pacman keys its repositories on $arch, so the packages are split by
# architecture rather than sharing one index the way apt's do.
- name: Sign the Arch packages and build the pacman repository
env:
APT_GPG_PASSPHRASE: ${{ secrets.APT_GPG_PASSPHRASE }}
run: |
set -euo pipefail
if [ -z "$(ls -A arch-in 2>/dev/null || true)" ]; then
echo "no .pkg.tar.zst assets on any release -- skipping the pacman repository"
exit 0
fi
for p in arch-in/*.pkg.tar.zst; do
case "$(basename "$p")" in
*aarch64*) a=aarch64 ;;
*) a=x86_64 ;;
esac
mkdir -p "repo/arch/$a"
mv "$p" "repo/arch/$a/"
done
# pacman wants detached BINARY signatures beside each package; an
# armored one is silently not what it looks for.
for p in repo/arch/*/*.pkg.tar.zst; do
gpg --batch --yes --pinentry-mode loopback --passphrase "$APT_GPG_PASSPHRASE" \
--local-user "$SIGNING_FPR" --detach-sign --no-armor -o "$p.sig" "$p"
done
# repo-add ships with pacman, which isn't on this runner.
docker run --rm -v "$PWD/repo/arch:/a" archlinux:base-devel bash -euc '
for d in /a/*/; do
cd "$d"
# Several versions of lookout-bin arrive here (the release plus
# older ones), and without -p the one added last wins, by file
# name: Lookout_linux-0.4.1 sorts before lookout_linux-0.3.14.
# -p keeps the newest whatever the order.
repo-add -q -R -p lookout.db.tar.gz *.pkg.tar.zst
done
'
sudo chown -R "$(id -u):$(id -g)" repo/arch
for d in repo/arch/*/; do
# repo-add leaves lookout.db and lookout.files as symlinks, which
# do not survive being served as static files. Replace them with
# the real thing, then sign what clients actually fetch.
for n in db files; do
[ -e "$d/lookout.$n.tar.gz" ] || continue
cp --remove-destination --dereference "$d/lookout.$n.tar.gz" "$d/lookout.$n"
for f in "$d/lookout.$n" "$d/lookout.$n.tar.gz"; do
gpg --batch --yes --pinentry-mode loopback --passphrase "$APT_GPG_PASSPHRASE" \
--local-user "$SIGNING_FPR" --detach-sign --no-armor -o "$f.sig" "$f"
done
done
done
# Read the signatures back with only the public half, the way pacman
# does -- a signature we cannot verify is worse than none, because
# SigLevel=Required turns it into a hard failure on every upgrade.
gpg --batch --armor --export "$SIGNING_FPR" > pub.asc
rm -rf v && mkdir v && chmod 700 v
GNUPGHOME=v gpg --batch --quiet --import pub.asc
for sig in repo/arch/*/*.sig; do
GNUPGHOME=v gpg --batch --verify "$sig" "${sig%.sig}" 2>/dev/null \
|| { echo "::error::$sig does not verify against the published key" >&2; exit 1; }
done
rm -rf v pub.asc
echo "pacman repository built: $(ls repo/arch)"
- name: Render the homepage
run: |
set -euo pipefail
version=$(grep -m1 '^Version:' repo/deb/Packages | awk '{print $2}')
fpr=$(gpg --fingerprint --with-colons "$SIGNING_FPR" \
| awk -F: '/^fpr:/ {print $10; exit}' \
| sed 's/.\{4\}/& /g; s/ $//')
python3 packaging/pkg-site/render.py \
packaging/pkg-site/index.html repo "$version" "$fpr" repo/index.html
- name: Add Pages metadata
run: |
echo pkg.lookout.hackclub.com > repo/CNAME
# One key signs both repositories; served at the root so the install
# docs have a single URL to point at.
cp clients/native/packaging/linux/repo/lookout-archive-keyring.asc repo/
# Redundant for an Actions deploy, which serves files as-is; kept in
# case the Pages source is ever switched back to a branch.
touch repo/.nojekyll
find repo -type f | sort
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: repo
- id: deploy
uses: actions/deploy-pages@v4
# Install and update through what was just published, from clean machines.
installer:
needs: publish
permissions:
contents: read
uses: ./.github/workflows/installer.yml