# SPDX-License-Identifier: GPL-3.0-only # SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts® name: Flatpak # The aarch64 flatpak, built after the tests for pull requests, when # started by hand and for a pushed tag X.Y.Z. Only the tag's run publishes: # the flatpak as the `stable` branch of the Catcrafts flatpak repository # (flatpak.catcrafts.net) with the app's ref file beside it, and release # X.Y.Z on the forge. # # Every push to main is a release: the owner signs its tag locally and # pushes it with the main it releases, and a push without one runs nothing. # The tag names the version, which the app and the metainfo's newest # have to carry; that entry's description is the release notes # (packaging/release-version.sh). # # Two jobs, by trust. `check` builds what is no release (a pull request, a # run by hand) cold: no host volume, neither the published repository nor # its key. `publish` builds a pushed tag with the four volumes it mounts: # the crafter-build installation every consumer repository's publish job on # the runner shares (crafter-flatpak-org-system: crafter-build //stable and # its runtime), this app's own build cache # (crafter-flatpak-messages-cache: the aarch64 Sdk, the sysroot and the # build directories, kept between runs), /var/www/flatpak (the published # repository) and /etc/crafter-flatpak (its signing key, which never enters # the forge) — the repository and the key Crafter.Build's workflow # publishes with. Both run on the Catcrafts organisation's privileged # `flatpak` runner, whose config must allow exactly those four volumes. The # shared installation is for publish jobs only: a pull request's job runs # as root in a privileged container and must never reach it. # # Crafter.Build's and Crafter.Review's workflows publish into the same # repository: each of the three holds /var/www/flatpak/.publish.lock while # it commits and updates the summary. on: pull_request: branches: [main] push: tags: ['[0-9]*.[0-9]*.[0-9]*'] workflow_dispatch: # Pushes are tags only, so every release run is in one group and queues # behind the one before it. A pull request's group also holds its number, # which only a pull request's event carries, so a new push to it cancels # its own outdated run and no other. concurrency: group: flatpak-${{ github.event_name }}-${{ github.event.pull_request.number }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: APP_ID: net.catcrafts.ImsdMessages ARCH: aarch64 BRANCH: stable CRAFTER_REF: net.catcrafts.CrafterBuild//stable REPO_DIR: /srv/flatpak/repo # A release tag carries a signature Forgejo verifies for this address. RELEASE_SIGNER: jorijnvdgraaf@catcrafts.net jobs: check: if: github.event_name != 'push' runs-on: flatpak timeout-minutes: 150 container: image: archlinux:latest steps: - name: Install tools # A mirror answering 502 can fail a pacman transaction even with # another mirror behind it; a retry starts over. run: | retry() { for i in 1 2 3 4 5; do "$@" && return 0; echo "attempt $i of 5 failed: $*" >&2; [ "$i" = 5 ] || sleep 30; done; return 1; } pacman-key --init pacman-key --populate archlinux retry pacman -Sy --noconfirm --needed archlinux-keyring retry pacman -Syu --noconfirm --needed flatpak ostree appstream binutils curl xz gnupg git nodejs util-linux python jq git config --global --add safe.directory '*' - name: crafter-build # The Crafter.Build Flatpak's stable branch, which moves only with its # releases; its Sdk comes from Flathub. # Flathub's CDN answers 502 now and then, which flatpak reports as a # missing runtime: each of these gets five tries. run: | retry() { for i in 1 2 3 4 5; do "$@" && return 0; echo "attempt $i of 5 failed: $*" >&2; [ "$i" = 5 ] || sleep 30; done; return 1; } retry flatpak remote-add --if-not-exists catcrafts https://flatpak.catcrafts.net/catcrafts.flatpakrepo retry flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo retry flatpak install -y --noninteractive catcrafts "$CRAFTER_REF" retry flatpak update -y --noninteractive flatpak info "$CRAFTER_REF" | sed -n 's/^ *\(Version\|Commit\|Date\): */crafter-build \1: /p' - name: Checkout # No step pushes, so the token is not kept in the checkout. uses: actions/checkout@v4 with: persist-credentials: false - name: Build user # crafter-build and the scripts run as a user; root installs. run: | id build >/dev/null 2>&1 || useradd -m build chown -R build: "$GITHUB_WORKSPACE" /home/build - name: Version run: runuser -u build -- packaging/release-version.sh - name: Sysroot run: runuser -u build -- packaging/make-flatpak-sysroot.sh - name: Tests run: runuser -u build -- flatpak run "$CRAFTER_REF" test - name: Build run: runuser -u build -- packaging/build-flatpak.sh repo "$BRANCH" publish: if: github.event_name == 'push' runs-on: flatpak timeout-minutes: 150 container: image: archlinux:latest options: >- -v crafter-flatpak-org-system:/var/lib/flatpak -v crafter-flatpak-messages-cache:/home/build/.cache -v /var/www/flatpak:/srv/flatpak -v /etc/crafter-flatpak:/run/crafter-flatpak:ro steps: - name: Install tools # A mirror answering 502 can fail a pacman transaction even with # another mirror behind it; a retry starts over. run: | retry() { for i in 1 2 3 4 5; do "$@" && return 0; echo "attempt $i of 5 failed: $*" >&2; [ "$i" = 5 ] || sleep 30; done; return 1; } pacman-key --init pacman-key --populate archlinux retry pacman -Sy --noconfirm --needed archlinux-keyring retry pacman -Syu --noconfirm --needed flatpak ostree appstream binutils curl xz gnupg git nodejs util-linux python jq git config --global --add safe.directory '*' - name: crafter-build # The Crafter.Build Flatpak's stable branch, which moves only with its # releases; its Sdk comes from Flathub. # Flathub's CDN answers 502 now and then, which flatpak reports as a # missing runtime: each of these gets five tries. run: | retry() { for i in 1 2 3 4 5; do "$@" && return 0; echo "attempt $i of 5 failed: $*" >&2; [ "$i" = 5 ] || sleep 30; done; return 1; } retry flatpak remote-add --if-not-exists catcrafts https://flatpak.catcrafts.net/catcrafts.flatpakrepo retry flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo retry flatpak install -y --noninteractive catcrafts "$CRAFTER_REF" retry flatpak update -y --noninteractive flatpak info "$CRAFTER_REF" | sed -n 's/^ *\(Version\|Commit\|Date\): */crafter-build \1: /p' - name: Checkout # Every branch and tag, for the release checks; no step pushes, so # the token is not kept in the checkout. uses: actions/checkout@v4 with: fetch-depth: 0 persist-credentials: false - name: Build user # crafter-build and the scripts run as a user; root installs and # publishes. run: | id build >/dev/null 2>&1 || useradd -m build chown -R build: "$GITHUB_WORKSPACE" /home/build - name: Version id: meta # The release checks, before anything is built; the notes go to # release-notes.md, for the release. env: RELEASE_NOTES: release-notes.md run: | set -eu version=$(runuser -u build -- packaging/release-version.sh "$GITHUB_REF_NAME") echo "version=$version" >> "$GITHUB_OUTPUT" echo "version $version" - name: Sysroot run: runuser -u build -- packaging/make-flatpak-sysroot.sh - name: Tests run: runuser -u build -- flatpak run "$CRAFTER_REF" test - name: Build # repo is made anew, as dist is below: root bundles and publishes # from it. run: | rm -rf repo runuser -u build -- packaging/build-flatpak.sh repo "$BRANCH" - name: Bundle # dist is made anew: the release carries every file in it, and a # checkout can bring a dist of its own, or a link by that name. run: | rm -rf dist mkdir dist flatpak build-bundle --arch="$ARCH" --runtime-repo=https://dl.flathub.org/repo/flathub.flatpakrepo \ repo "dist/imsd-messages-${{ steps.meta.outputs.version }}-$ARCH.flatpak" "$APP_ID" "$BRANCH" - name: Upload bundle uses: actions/upload-artifact@v3 with: name: imsd-messages-${{ steps.meta.outputs.version }}-aarch64 path: dist/*.flatpak if-no-files-found: error - name: Publish to the Catcrafts repository run: | set -eu if [ ! -s /run/crafter-flatpak/signing-key.asc ] || [ ! -s /run/crafter-flatpak/key-id ]; then echo "no signing key under /etc/crafter-flatpak on the runner host" >&2 exit 1 fi export GNUPGHOME=$(mktemp -d) gpg --batch --quiet --import /run/crafter-flatpak/signing-key.asc key_id=$(cat /run/crafter-flatpak/key-id) # Crafter.Build's and Crafter.Review's workflows publish into the # same repository, and each holds this lock while it does, so a # commit and the summary update of one never interleave with # another's. exec 9> /srv/flatpak/.publish.lock flock 9 # The repository's catcrafts.flatpakrepo, which an install adds, is # Crafter.Build's to write, so a repository that is not there is # not this workflow's to start; it commits its own ref and then # updates the repository as the other two do. [ -f "$REPO_DIR/config" ] || { echo "no published repository at $REPO_DIR" >&2; exit 1; } # The app's ref file, the repository's key in it: the checkout's, # read as the build user like every file of the checkout. It is # made before anything is published, so a file that cannot carry # the key publishes nothing, and moved beside the repository # after it. key=$(gpg --export "$key_id" | base64 --wrap=0) [ -n "$key" ] || { echo "the signing key did not export" >&2; exit 1; } runuser -u build -- sed "s|^GPGKey=.*|GPGKey=$key|" "packaging/$APP_ID.flatpakref" > "/srv/flatpak/.$APP_ID.flatpakref.new" grep -qx "GPGKey=$key" "/srv/flatpak/.$APP_ID.flatpakref.new" flatpak build-commit-from --src-repo=repo \ --gpg-sign="$key_id" --gpg-homedir="$GNUPGHOME" \ "$REPO_DIR" "app/$APP_ID/$ARCH/$BRANCH" flatpak build-update-repo --gpg-sign="$key_id" --gpg-homedir="$GNUPGHOME" \ --generate-static-deltas --prune "$REPO_DIR" mv "/srv/flatpak/.$APP_ID.flatpakref.new" "/srv/flatpak/$APP_ID.flatpakref" flock -u 9 - name: Release files # The ref file as published, with the repository's key (the # checkout's has a placeholder), and the checksums of what the # release carries. run: | set -eu cp "/srv/flatpak/$APP_ID.flatpakref" dist/ (cd dist && sha256sum * > SHA256SUMS && ls -la) - name: Publish release # The notes are release-notes.md, which the Version step wrote. uses: https://code.forgejo.org/actions/forgejo-release@v2 with: direction: upload url: ${{ github.server_url }} repo: ${{ github.repository }} tag: ${{ steps.meta.outputs.version }} title: imsd-messages ${{ steps.meta.outputs.version }} release-notes-file: release-notes.md release-dir: dist token: ${{ secrets.GITHUB_TOKEN }}