#!/bin/bash # Update the Flathub submission (fork at FLATHUB_DIR) to the latest release tag # and open/update the submission PR against flathub/flathub. # # After this PR is merged, routine releases are handled automatically by # Flatpak's external-data-checker (x-checker-data in com.linuxy.App.yaml), which # opens update PRs when a new "v*" tag is pushed. Run this script only when the # checker is not used or the submission needs a manual refresh. # # Required environment variables: # GH_TOKEN - GitHub token with access to the flathub fork and flathub/flathub # Optional: # FLATHUB_DIR - path to the flathub fork checkout (default: ../flathub) # FLATHUB_BRANCH - branch holding the submission (default: linuxy-submission) # FLATHUB_MAX_ATTEMPTS - max push attempts (default: 6) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" FLATHUB_DIR="${FLATHUB_DIR:-$REPO_ROOT/flathub}" BRANCH="${FLATHUB_BRANCH:-linuxy-submission}" MAX_ATTEMPTS="${FLATHUB_MAX_ATTEMPTS:-6}" GENERATOR="$REPO_ROOT/flatpak/flatpak-cargo-generator.py" TARGET_DIR="$FLATHUB_DIR/com.linuxy.App" echo "Determining latest release tag" TAG="$(git -C "$REPO_ROOT" describe --tags --abbrev=0 --match 'v*')" COMMIT="$(git -C "$REPO_ROOT" rev-parse "${TAG}^{commit}")" echo " Pinning submission to ${TAG} (${COMMIT})" TMP_WORK="$(mktemp -d)" trap 'rm -rf "$TMP_WORK"' EXIT echo "Regenerating cargo-sources.json from ${TAG}'s Cargo.lock" git -C "$REPO_ROOT" show "${TAG}:src-tauri/Cargo.lock" >"$TMP_WORK/Cargo.lock" uv run "$GENERATOR" "$TMP_WORK/Cargo.lock" -o "$TMP_WORK/cargo-sources.json" TMP_WORK="$TMP_WORK" REPO_ROOT="$REPO_ROOT" python3 - <<'PYEOF' import json, yaml, os base = open(os.path.join(os.environ["TMP_WORK"], "cargo-sources.json")) sources = json.load(base) def plain(s): return yaml.safe_dump(s, default_style="", width=10**9).replace("\n...\n", "\n").strip() lines = [] for s in sources: if s["type"] == "archive": lines += [f" - type: {s['type']}", f" url: {plain(s['url'])}", f" sha256: {plain(s['sha256'])}", f" archive-type: {s['archive-type']}", f" dest: {plain(s['dest'])}"] else: lines += [f" - type: {s['type']}", f" contents: {plain(s['contents'])}", f" dest: {plain(s['dest'])}", f" dest-filename: {plain(s['dest-filename'])}"] manifest = open(os.path.join(os.environ["REPO_ROOT"], "flatpak/com.linuxy.App.yaml")).read() header = manifest.split(" # Generated by flatpak-cargo-generator.py")[0] with open(os.path.join(os.environ["REPO_ROOT"], "flatpak/com.linuxy.App.yaml"), "w") as f: f.write(header + " # Generated by flatpak-cargo-generator.py from src-tauri/Cargo.lock\n") f.write("\n".join(lines) + "\n") PYEOF echo "Updating manifest tag and commit in flatpak/" sed -i "s/^ tag: .*/ tag: ${TAG}/; s/^ commit: .*/ commit: ${COMMIT}/" \ "$REPO_ROOT/flatpak/com.linuxy.App.yaml" echo "Syncing files to the flathub fork ($FLATHUB_DIR)" mkdir -p "$TARGET_DIR/icons" cp "$REPO_ROOT/flatpak/com.linuxy.App.yaml" "$TARGET_DIR/" cp "$REPO_ROOT/flatpak/com.linuxy.App.desktop" "$TARGET_DIR/" cp "$REPO_ROOT/flatpak/com.linuxy.App.metainfo.xml" "$TARGET_DIR/" cp "$REPO_ROOT/flatpak/icons/"*.png "$TARGET_DIR/icons/" git -C "$FLATHUB_DIR" checkout --quiet "$BRANCH" 2>/dev/null || \ git -C "$FLATHUB_DIR" checkout --quiet -b "$BRANCH" origin/"$BRANCH" 2>/dev/null || \ git -C "$FLATHUB_DIR" checkout --quiet -b "$BRANCH" git -C "$FLATHUB_DIR" add -A if git -C "$FLATHUB_DIR" diff --cached --quiet; then echo "No changes to push; Flathub submission is already up to date." exit 0 fi echo "Committing changes" git -C "$FLATHUB_DIR" -c user.name="Linuxy Bot" -c user.email="bot@localhost" \ commit -q -m "chore(com.linuxy.App): update to ${TAG}" echo "Pushing to the flathub fork" attempt=0 while ! git -C "$FLATHUB_DIR" push --quiet origin "$BRANCH"; do attempt=$((attempt + 1)) if [ "$attempt" -ge "$MAX_ATTEMPTS" ]; then echo "Failed to push to the flathub fork after ${attempt} attempts." >&2 exit 1 fi delay=$((attempt * 30)) echo "Push failed (attempt ${attempt}/${MAX_ATTEMPTS}); retrying in ${delay}s..." >&2 sleep "$delay" done echo "Opening/updating the submission PR" if ! gh pr list --repo flathub/flathub --head "$BRANCH" --state open --json number \ --jq 'length' | grep -q '^[1-9]'; then gh pr create --repo flathub/flathub --base master --head "swadhinbiswas:$BRANCH" \ --title "Add com.linuxy.App" \ --body "Linuxy is a modern Linux application manager with one-click installation, Firejail sandboxing, optional delta updates, and secure desktop integration. Built with Tauri 2 (Rust + React). Sources are vendored; the app is pinned to the latest release tag (${TAG}) with x-checker-data enabled for automatic update PRs." else echo "PR already open; pushed ${TAG} to ${BRANCH}." fi echo "Successfully updated the Flathub submission to ${TAG}."