Skip to content

Commit f26e8fd

Browse files
committed
ci: open the Flathub update PR on stable releases
1 parent d16bc3b commit f26e8fd

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

‎.github/workflows/tauri-build.yml‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,88 @@ jobs:
11991199
git commit -m "sable ${VERSION}"
12001200
# The tap may still be an empty repository on the first run.
12011201
git push origin HEAD:refs/heads/main
1202+
1203+
distribute-flathub:
1204+
name: Open the Flathub update PR
1205+
needs: [setup-release, linux]
1206+
runs-on: ubuntu-latest
1207+
timeout-minutes: 15
1208+
if: ${{ needs.setup-release.outputs.nightly != 'true' }}
1209+
permissions:
1210+
contents: read
1211+
env:
1212+
TAG: ${{ needs.setup-release.outputs.tag }}
1213+
VERSION: ${{ needs.setup-release.outputs.version }}
1214+
steps:
1215+
- name: Bump the Flathub manifest
1216+
shell: bash
1217+
env:
1218+
FLATHUB_TOKEN: ${{ secrets.FLATHUB_TOKEN }}
1219+
GH_TOKEN: ${{ secrets.FLATHUB_TOKEN }}
1220+
run: |
1221+
if [ -z "${FLATHUB_TOKEN:-}" ]; then
1222+
echo "::notice::FLATHUB_TOKEN is not set; skipping the Flathub PR."
1223+
exit 0
1224+
fi
1225+
git clone --depth 1 \
1226+
"https://x-access-token:${FLATHUB_TOKEN}@github.com/flathub/moe.sable.client.git" flathub
1227+
1228+
gh release view "$TAG" --json assets \
1229+
--jq '.assets[] | select(.name | test("-linux-(x86_64|aarch64)\\.tar\\.gz$"))
1230+
| "\(.name) \(.digest)"' > assets.txt
1231+
1232+
# The manifest pins these two by content, read from dev.
1233+
for name in moe.sable.client.metainfo.xml moe.sable.client.desktop; do
1234+
curl -fsSL "https://raw.githubusercontent.com/SableClient/Sable/dev/packaging/flatpak/$name" \
1235+
| sha256sum | awk -v n="$name" '{print n, "sha256:" $1}' >> assets.txt
1236+
done
1237+
1238+
VERSION="$VERSION" python3 - flathub/moe.sable.client.yml assets.txt <<'PY'
1239+
import os, re, sys
1240+
1241+
manifest, digests = sys.argv[1], sys.argv[2]
1242+
version = os.environ["VERSION"]
1243+
sha = {}
1244+
for line in open(digests):
1245+
name, digest = line.split()
1246+
sha[name] = digest.removeprefix("sha256:")
1247+
1248+
text = open(manifest).read()
1249+
for arch in ("x86_64", "aarch64"):
1250+
name = f"Sable-{version}-linux-{arch}.tar.gz"
1251+
url = f"https://github.com/SableClient/Sable/releases/download/v{version}/{name}"
1252+
text, count = re.subn(
1253+
rf"url: \S*Sable-\S+-linux-{arch}\.tar\.gz\n(\s+)sha256: \w+",
1254+
lambda m: f"url: {url}\n{m.group(1)}sha256: {sha[name]}",
1255+
text,
1256+
)
1257+
if count != 1:
1258+
sys.exit(f"expected one {arch} source, found {count}")
1259+
1260+
for name in ("moe.sable.client.metainfo.xml", "moe.sable.client.desktop"):
1261+
text, count = re.subn(
1262+
rf"(url: \S*/packaging/flatpak/{re.escape(name)}\n\s+)sha256: \w+",
1263+
lambda m: f"{m.group(1)}sha256: {sha[name]}",
1264+
text,
1265+
)
1266+
if count != 1:
1267+
sys.exit(f"expected one {name} source, found {count}")
1268+
1269+
open(manifest, "w").write(text)
1270+
PY
1271+
1272+
cd flathub
1273+
git config user.name "github-actions[bot]"
1274+
git config user.email "github-actions[bot]@users.noreply.github.com"
1275+
git add moe.sable.client.yml
1276+
if git diff --cached --quiet; then
1277+
echo "Nothing changed; skipping the Flathub PR."
1278+
exit 0
1279+
fi
1280+
git checkout -b "update-${VERSION}"
1281+
git commit -m "Update Sable to ${VERSION}"
1282+
git push origin "update-${VERSION}"
1283+
gh pr create --repo flathub/moe.sable.client \
1284+
--base master --head "update-${VERSION}" \
1285+
--title "Update Sable to ${VERSION}" \
1286+
--body "Bumps the x86_64 and aarch64 release tarballs to ${VERSION}."

0 commit comments

Comments
 (0)