build(packaging): add the Forgejo workflow that tests and releases

.forgejo/workflows/flatpak.yaml, after imsd-messages' workflow, of whose
packaging scripts make-aarch64-sysroot.sh and build-aarch64.sh are the
counterparts. `check` runs the version check, the tests, the lint and
the aarch64 build of both Flatpaks for a pull request or a run by hand.
`publish` does the same but the lint for a pushed tag X.Y.Z, then
commits the service and the app into the Catcrafts Flatpak repository,
signed with the key on the runner's host, and makes the release on the
forge. A push without a tag runs nothing, so this push does not.

packaging/flatpak/release-version.sh is that app's script for Nostro:
NOSTRO_VERSION in project.cpp against the newest <release> of the app's
metainfo, and for a tag that it is that version, annotated, signed by
the owner as Forgejo verifies it, on master and newer than every
release.

Both files are after ones of imsd-messages, which are Catcrafts' own
and GPL-3.0-only, and are LGPL-3.0-only here, as nostro's packaging is
(design rule 13): a move between licences.

Not run: no runner has had the workflow. It parses as YAML and each of
its steps as shell. release-version.sh was run on this tree without a
tag, where it prints 0.1.0 and renders the notes, and with a tag that
is no version, which it refuses; what it checks of a real tag needs the
forge.

What a first run needs, and did not have on 2026-11-19, is in
AGENTS.template.md under "Releasing": a runner labelled `flatpak` for
this repository, the cache volume allowed in that runner's config, and
Crafter.Graphics' text-input change on the forge as the branch
claude/nostro-app. That change was uncommitted work in one local
checkout that day, so the app could be built nowhere else: the notes
on --graphics= now say so.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-11-19 16:14:33 +01:00
commit 1292a6eef1
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
3 changed files with 438 additions and 5 deletions

View file

@ -0,0 +1,120 @@
#!/bin/sh
# SPDX-License-Identifier: LGPL-3.0-only
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
# release-version.sh: prints the version this tree releases, checked. After imsd-messages' script of the same name.
#
# packaging/flatpak/release-version.sh # any tree
# packaging/flatpak/release-version.sh <tag> # CI's run for a pushed tag
#
# The version is that of the app's metainfo's newest <release>, its first one, and NOSTRO_VERSION in project.cpp has to
# be the same. The entry's description is the release notes: it has to render some, and they are written as Markdown
# to the file $RELEASE_NOTES names, when it names one.
#
# For a tag the release is checked as well: the tag is that version, annotated and signed by $RELEASE_SIGNER as Forgejo
# verifies it, on master, and newer than every release the forge has published. Those checks read $GITHUB_SERVER_URL,
# $GITHUB_REPOSITORY and $GITHUB_SHA, and the checkout's tags and origin/master. Needs python3, and for a tag curl, jq
# and git.
set -eu
SRC=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
METAINFO=packaging/flatpak/net.catcrafts.Nostro.metainfo.xml
# The metainfo is parsed, once, for both the version and the notes: a comment or another attribute order would mislead
# a text search. AppStream has no headings, so a paragraph that introduces a list is one: <p>New</p><ul>...</ul> comes
# out as "## New" over its items, and a paragraph on its own stays a paragraph. <em> and <code> get their Markdown
# spelling.
newest=$(python3 - "$SRC/$METAINFO" "${RELEASE_NOTES:-}" <<'EOF'
import sys
import xml.etree.ElementTree as ET
release = ET.parse(sys.argv[1]).getroot().find("releases/release")
desc = None if release is None else release.find("description")
def text(el):
parts = [el.text or ""]
for child in el:
inner = text(child)
parts.append({"em": f"*{inner}*", "code": f"`{inner}`"}.get(child.tag, inner))
parts.append(child.tail or "")
return " ".join("".join(parts).split())
blocks = [] if desc is None else list(desc)
out = []
for i, el in enumerate(blocks):
heads_list = i + 1 < len(blocks) and blocks[i + 1].tag in ("ul", "ol")
if el.tag == "p":
out.append(f"## {text(el)}" if heads_list else text(el))
elif el.tag == "ul":
out.append("\n".join(f"- {text(li)}" for li in el))
elif el.tag == "ol":
out.append("\n".join(f"{n}. {text(li)}" for n, li in enumerate(el, 1)))
notes = "\n\n".join(out)
if not notes.strip():
sys.exit("the metainfo needs a <release> at the top of <releases> whose <description> renders release notes")
if sys.argv[2]:
with open(sys.argv[2], "w") as f:
print(notes, file=f)
print(release.get("version", ""))
EOF
)
app=$(sed -n 's/.*{"NOSTRO_VERSION", "\(.*\)"}.*/\1/p' "$SRC/project.cpp")
if [ "$app" != "$newest" ]; then
echo "the app's version is \"$app\", but the metainfo's newest release is \"$newest\": a release bumps NOSTRO_VERSION in project.cpp and adds its <release> entry at the top of $METAINFO" >&2
exit 1
fi
[ $# -ge 1 ] || { echo "$newest"; exit 0; }
# A release. The tag itself is read from the forge: the checkout fetches a pushed tag again as a plain ref to its
# commit, so the local one is never the annotated tag.
version=$1
if ! printf '%s\n' "$version" | grep -qxE '[0-9]+\.[0-9]+\.[0-9]+'; then
echo "the tag $version is not a version of the form X.Y.Z" >&2
exit 1
fi
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY"
tag=$(curl -sSf "$api/tags/$version")
object=$(printf '%s' "$tag" | jq -r .id)
commit=$(printf '%s' "$tag" | jq -r .commit.sha)
if [ "$commit" != "$GITHUB_SHA" ]; then
echo "the forge has the tag $version on $commit, not on this run's commit $GITHUB_SHA" >&2
exit 1
fi
if [ "$object" = "$commit" ]; then
echo "$version is a lightweight tag; a release tag is annotated and signed: git tag -s $version -m 'Nostro $version'" >&2
exit 1
fi
# Forgejo verifies a signed tag's own signature, and for an unsigned one falls back to its commit's, so the verdict
# also has to cover the tag's payload, not the commit's.
signed=$(curl -sSf "$api/git/tags/$object" |
jq -r --arg c "$commit" --arg v "$version" '"\(.verification.verified) \(.verification.signer.email // "") \(.verification.payload // "" | startswith("object \($c)\ntype commit\ntag \($v)\n"))"')
if [ "$signed" != "true $RELEASE_SIGNER true" ]; then
echo "Forgejo does not verify the tag $version itself as signed by $RELEASE_SIGNER (verified, signer, over the tag's payload: $signed)" >&2
exit 1
fi
if ! git -C "$SRC" merge-base --is-ancestor "$GITHUB_SHA" origin/master; then
echo "the tag $version is on $(git -C "$SRC" rev-parse --short "$GITHUB_SHA"), which is not on master: push the tag with the master it releases" >&2
exit 1
fi
# Newer than every release the forge has published, its own included, and not every tag: a later tag whose run still
# queues behind this one has no release yet, and a tag that is no X.Y.Z version never gets one.
for t in $(git -C "$SRC" tag --list | awk '/^[0-9]+\.[0-9]+\.[0-9]+$/' | sort -V); do
[ "$(printf '%s\n%s\n' "$t" "$version" | sort -V | tail -n 1)" = "$t" ] || continue
code=$(curl -s -o /dev/null -w '%{http_code}' "$api/releases/tags/$t")
case "$code" in
404) ;;
200)
if [ "$t" = "$version" ]; then
echo "$version is released already; to re-run after a release left half made, delete that release first" >&2
else
echo "$version is not newer than the release $t" >&2
fi
exit 1 ;;
*) echo "the forge answered $code when asked whether $t is released" >&2; exit 1 ;;
esac
done
if [ "$newest" != "$version" ]; then
echo "the metainfo's newest release is \"$newest\", but the tag is $version: the tagged commit needs the <release> entry for $version at the top of $METAINFO" >&2
exit 1
fi
echo "$version"