Skip to content

Commit 1fca044

Browse files
committed
Add update flathub beta workflow
1 parent 8333e0a commit 1fca044

2 files changed

Lines changed: 220 additions & 12 deletions

File tree

.github/workflows/build.yml

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,3 +940,211 @@ jobs:
940940
version: ${{ needs.deploy.outputs.version }}
941941
release-tag: v${{ needs.deploy.outputs.version }}
942942
token: ${{ secrets.CI_PAT }}
943+
update-flathub-beta:
944+
name: Update Flathub beta
945+
needs:
946+
- deploy
947+
if: >-
948+
${{
949+
github.event_name == 'release' &&
950+
github.event.action == 'published' &&
951+
github.event.release.prerelease == true
952+
}}
953+
runs-on: ubuntu-24.04
954+
955+
permissions:
956+
contents: read
957+
958+
concurrency:
959+
group: flathub-beta-${{ github.event.release.tag_name }}
960+
cancel-in-progress: false
961+
962+
env:
963+
FLATHUB_REPOSITORY: flathub/dev.linwood.butterfly
964+
FLATHUB_MANIFEST: dev.linwood.butterfly.json
965+
RELEASE_TAG: ${{ github.event.release.tag_name }}
966+
967+
steps:
968+
- name: Download release checksums
969+
env:
970+
GH_TOKEN: ${{ github.token }}
971+
run: |
972+
mkdir -p release
973+
974+
for attempt in {1..12}; do
975+
rm -f release/checksums.txt
976+
977+
if gh release download "$RELEASE_TAG" \
978+
--repo "$GITHUB_REPOSITORY" \
979+
--pattern checksums.txt \
980+
--dir release; then
981+
break
982+
fi
983+
984+
echo "Release assets are not available yet, retrying..."
985+
sleep 10
986+
done
987+
988+
test -s release/checksums.txt
989+
990+
- name: Read Linux checksums
991+
id: checksums
992+
run: |
993+
X86_64_SHA="$(
994+
awk '$2 == "linwood-butterfly-linux-x86_64.tar.gz" {
995+
print $1
996+
}' release/checksums.txt
997+
)"
998+
999+
ARM64_SHA="$(
1000+
awk '$2 == "linwood-butterfly-linux-arm64.tar.gz" {
1001+
print $1
1002+
}' release/checksums.txt
1003+
)"
1004+
1005+
if [[ ! "$X86_64_SHA" =~ ^[0-9a-f]{64}$ ]]; then
1006+
echo "Invalid or missing x86_64 checksum"
1007+
exit 1
1008+
fi
1009+
1010+
if [[ ! "$ARM64_SHA" =~ ^[0-9a-f]{64}$ ]]; then
1011+
echo "Invalid or missing arm64 checksum"
1012+
exit 1
1013+
fi
1014+
1015+
echo "x86_64=$X86_64_SHA" >> "$GITHUB_OUTPUT"
1016+
echo "arm64=$ARM64_SHA" >> "$GITHUB_OUTPUT"
1017+
1018+
- name: Checkout Flathub beta branch
1019+
uses: actions/checkout@v6
1020+
with:
1021+
repository: flathub/dev.linwood.butterfly
1022+
ref: beta
1023+
token: ${{ secrets.CI_PAT }}
1024+
fetch-depth: 0
1025+
path: flathub
1026+
1027+
- name: Update Flathub manifest
1028+
env:
1029+
X86_64_SHA: ${{ steps.checksums.outputs.x86_64 }}
1030+
ARM64_SHA: ${{ steps.checksums.outputs.arm64 }}
1031+
run: |
1032+
python3 <<'PY'
1033+
import os
1034+
import re
1035+
from pathlib import Path
1036+
1037+
manifest = Path("flathub") / os.environ["FLATHUB_MANIFEST"]
1038+
release_tag = os.environ["RELEASE_TAG"]
1039+
1040+
files = {
1041+
"linwood-butterfly-linux-x86_64.tar.gz": os.environ["X86_64_SHA"],
1042+
"linwood-butterfly-linux-arm64.tar.gz": os.environ["ARM64_SHA"],
1043+
}
1044+
1045+
lines = manifest.read_text(encoding="utf-8").splitlines()
1046+
updated = set()
1047+
1048+
for index, line in enumerate(lines):
1049+
for filename, checksum in files.items():
1050+
if '"url":' not in line or filename not in line:
1051+
continue
1052+
1053+
indent = line[: len(line) - len(line.lstrip())]
1054+
lines[index] = (
1055+
f'{indent}"url": '
1056+
f'"https://github.com/LinwoodDev/Butterfly/'
1057+
f'releases/download/{release_tag}/{filename}",'
1058+
)
1059+
1060+
for checksum_index in range(
1061+
index + 1,
1062+
min(index + 6, len(lines)),
1063+
):
1064+
if '"sha256":' not in lines[checksum_index]:
1065+
continue
1066+
1067+
lines[checksum_index] = re.sub(
1068+
r'"sha256":\s*"[^"]+"',
1069+
f'"sha256": "{checksum}"',
1070+
lines[checksum_index],
1071+
)
1072+
updated.add(filename)
1073+
break
1074+
1075+
missing = set(files) - updated
1076+
if missing:
1077+
raise RuntimeError(
1078+
f"Could not update manifest entries: {sorted(missing)}"
1079+
)
1080+
1081+
manifest.write_text(
1082+
"\n".join(lines) + "\n",
1083+
encoding="utf-8",
1084+
)
1085+
PY
1086+
1087+
- name: Commit and push update branch
1088+
id: push
1089+
working-directory: flathub
1090+
run: |
1091+
VERSION="${RELEASE_TAG#v}"
1092+
BRANCH="automation/butterfly-$VERSION"
1093+
1094+
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
1095+
1096+
if git diff --quiet -- "$FLATHUB_MANIFEST"; then
1097+
echo "Manifest already contains this release"
1098+
echo "changed=false" >> "$GITHUB_OUTPUT"
1099+
exit 0
1100+
fi
1101+
1102+
git config user.name "Linwood CI"
1103+
git config user.email "ci@linwood.dev"
1104+
1105+
git checkout -B "$BRANCH"
1106+
git add "$FLATHUB_MANIFEST"
1107+
git commit -m "Update Butterfly to $VERSION"
1108+
git push --force origin "HEAD:refs/heads/$BRANCH"
1109+
1110+
echo "changed=true" >> "$GITHUB_OUTPUT"
1111+
1112+
- name: Create Flathub beta pull request
1113+
if: steps.push.outputs.changed == 'true'
1114+
env:
1115+
GH_TOKEN: ${{ secrets.CI_PAT }}
1116+
BRANCH: ${{ steps.push.outputs.branch }}
1117+
run: |
1118+
EXISTING_PR="$(
1119+
gh pr list \
1120+
--repo "$FLATHUB_REPOSITORY" \
1121+
--base beta \
1122+
--head "$BRANCH" \
1123+
--state open \
1124+
--json number \
1125+
--jq '.[0].number // empty'
1126+
)"
1127+
1128+
if [[ -n "$EXISTING_PR" ]]; then
1129+
echo "Pull request #$EXISTING_PR already exists"
1130+
exit 0
1131+
fi
1132+
1133+
VERSION="${RELEASE_TAG#v}"
1134+
1135+
cat > /tmp/flathub-pr.md <<EOF
1136+
Automated update for Butterfly $VERSION.
1137+
1138+
Release:
1139+
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$RELEASE_TAG
1140+
1141+
The download URLs and SHA256 checksums for the x86_64 and arm64
1142+
Linux archives were generated from the published release assets.
1143+
EOF
1144+
1145+
gh pr create \
1146+
--repo "$FLATHUB_REPOSITORY" \
1147+
--base beta \
1148+
--head "$BRANCH" \
1149+
--title "Update Butterfly to $VERSION" \
1150+
--body-file /tmp/flathub-pr.md

app/pubspec.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ packages:
156156
dependency: "direct main"
157157
description:
158158
name: camera
159-
sha256: "034c38cb8014d29698dcae6d20276688a1bf74e6487dfeb274d70ea05d5f7777"
159+
sha256: "558230d6ce6ccea856b32d390db7e7b557adf4d9320aa614481bd3f2f608953f"
160160
url: "https://pub.dev"
161161
source: hosted
162-
version: "0.12.0+1"
162+
version: "0.12.0+2"
163163
camera_android_camerax:
164164
dependency: transitive
165165
description:
@@ -1307,10 +1307,10 @@ packages:
13071307
dependency: transitive
13081308
description:
13091309
name: shared_preferences_android
1310-
sha256: "93ae5884a9df5d3bb696825bceb3a17590754548b5d740eba51500afc8d088f5"
1310+
sha256: "0634e64bd719f89c012f392938e173521f535d3ecaf66558fa94a056d22b5cc7"
13111311
url: "https://pub.dev"
13121312
source: hosted
1313-
version: "2.4.26"
1313+
version: "2.4.27"
13141314
shared_preferences_foundation:
13151315
dependency: transitive
13161316
description:
@@ -1457,34 +1457,34 @@ packages:
14571457
dependency: "direct main"
14581458
description:
14591459
name: talker
1460-
sha256: f1a14d623f1d1bec42bb3bb77674eb766ffe8d26e5f79af652d85cb097c3e757
1460+
sha256: "342a30d81df3fc2ffca8daafdfee0c1b882269b0825dcc62093075c08bac9500"
14611461
url: "https://pub.dev"
14621462
source: hosted
1463-
version: "5.1.17"
1463+
version: "5.1.19"
14641464
talker_bloc_logger:
14651465
dependency: "direct main"
14661466
description:
14671467
name: talker_bloc_logger
1468-
sha256: b799c899b89472e1b2030a97f56c2ce7dfa739f743f464774c89a2c4d7c61447
1468+
sha256: "2233c7b9009e82c5517365881a048b1a71a176f405457144b2caab5dc96cc19f"
14691469
url: "https://pub.dev"
14701470
source: hosted
1471-
version: "5.1.17"
1471+
version: "5.1.19"
14721472
talker_flutter:
14731473
dependency: "direct main"
14741474
description:
14751475
name: talker_flutter
1476-
sha256: "7e4b5fb520b4dadfc8db97e73a2a76ea5d6eda471a51489f3c0bd58b96a1ed43"
1476+
sha256: a37a15e2a996b6534006d3fa95c712edb07b60299c021a5cf0836f940405be47
14771477
url: "https://pub.dev"
14781478
source: hosted
1479-
version: "5.1.17"
1479+
version: "5.1.19"
14801480
talker_logger:
14811481
dependency: transitive
14821482
description:
14831483
name: talker_logger
1484-
sha256: "459205c3e571f97ecc6be6e1b1b7e6b97b853e78ea458894650be407596e3216"
1484+
sha256: "999b76cb583ee89da098e8ef3a7b863eb5261326f0d33e0877f20c9df1003790"
14851485
url: "https://pub.dev"
14861486
source: hosted
1487-
version: "5.1.17"
1487+
version: "5.1.19"
14881488
term_glyph:
14891489
dependency: transitive
14901490
description:

0 commit comments

Comments
 (0)