From 7b64da8a3893ea5a3cdd27f362186ac457d94c8c Mon Sep 17 00:00:00 2001 From: BlackAngelTVdev Date: Wed, 25 Nov 2026 10:14:56 +0100 Subject: [PATCH] ci(release): publish the Arch package when the version changes Releases were built and uploaded by hand, so the published package could lag behind main and nothing checked the tree before it shipped. The new version file drives a pipeline that lints, builds and tests the exact commit, then creates the Gitea release and pushes the package to the pacman repository. --- .gitea/workflows/ci.yml | 62 ++++++++++++ .gitea/workflows/package.yml | 190 +++++++++++++++++++++++++++++++++++ .gitignore | 4 + README.md | 19 ++++ kitty/options/definition.py | 3 +- packaging/PKGBUILD | 8 +- packaging/README.md | 27 ++++- packaging/check-version.sh | 42 ++++++++ version | 1 + 9 files changed, 352 insertions(+), 4 deletions(-) create mode 100644 .gitea/workflows/ci.yml create mode 100644 .gitea/workflows/package.yml create mode 100755 packaging/check-version.sh create mode 100644 version diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..9418dd5 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,62 @@ +# Continuous integration: every pull request and every push to main must pass +# the linter, the build and the tests. Packaging lives in package.yml, which +# only runs when the version file changes. +name: CI + +on: + pull_request: + push: + branches: [main] + workflow_dispatch: + +# A new push on the same branch supersedes the previous run, but main builds run +# to completion so a broken merge is always reported. +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + check: + # Arch Linux host runner: kitty builds against the Arch toolchain (base-devel, + # go, python, harfbuzz, shader-slang...) and makepkg refuses to run as root. + runs-on: arch-host + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + + - name: Check the version files agree + run: ./packaging/check-version.sh + + - name: Lint Python + run: | + ruff check . + ruff format --check . + + - name: Check Go formatting + run: | + # Generated files only exist after ./dev.sh build and are not tracked, + # so only the committed sources are checked. + unformatted="$(git ls-files -z '*.go' | xargs -0 gofmt -s -l)" + if [ -n "$unformatted" ]; then + echo "::error::gofmt is required for:" + echo "$unformatted" + exit 1 + fi + + - name: Build + run: ./dev.sh build + + # The Go packages import generated code and embedded data produced by the + # build above, so vet and tests cannot run on a bare checkout. + - name: Vet + run: go vet ./kittens/file_manager/ + + - name: Test + run: go test --tags testing ./kittens/file_manager/ + + - name: Smoke test the binaries + run: | + ./kitty/launcher/kitty --version + ./kitty/launcher/kitten --version diff --git a/.gitea/workflows/package.yml b/.gitea/workflows/package.yml new file mode 100644 index 0000000..939b71e --- /dev/null +++ b/.gitea/workflows/package.yml @@ -0,0 +1,190 @@ +# Release pipeline. A change to the version file on main is the only thing that +# publishes: the package is built from that exact commit, attached to a Gitea +# release and pushed to the pacman repository at repo.laxacube.ch. +# +# Required secrets: RELEASE_TOKEN (release API), REPO_TOKEN (pacman repository). +name: Release + +on: + push: + branches: [main] + # Only a version bump releases; every other commit stays on the CI path. + paths: [version] + workflow_dispatch: + +permissions: + contents: write + +# Releases are ordered: a second run waits instead of racing for the same tag. +concurrency: + group: release + cancel-in-progress: false + +jobs: + # Keep in sync with .gitea/workflows/ci.yml: a release must never ship a + # commit that the CI job would have rejected. + check: + runs-on: arch-host + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + + - name: Check the version files agree + run: ./packaging/check-version.sh + + - name: Lint Python + run: | + ruff check . + ruff format --check . + + - name: Check Go formatting + run: | + unformatted="$(git ls-files -z '*.go' | xargs -0 gofmt -s -l)" + if [ -n "$unformatted" ]; then + echo "::error::gofmt is required for:" + echo "$unformatted" + exit 1 + fi + + - name: Build + run: ./dev.sh build + + - name: Vet + run: go vet ./kittens/file_manager/ + + - name: Test + run: go test --tags testing ./kittens/file_manager/ + + - name: Smoke test the binaries + run: | + ./kitty/launcher/kitty --version + ./kitty/launcher/kitten --version + + release: + needs: [check] + # makepkg on the Arch host: an Arch container cannot be used because the + # pacman database uses ':' in epoch directory names, which some runner disks + # reject, and the host already has the package dependencies installed. + runs-on: arch-host + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + + - name: Read the version file + id: version + run: echo "version=$(./packaging/check-version.sh)" >> "$GITHUB_OUTPUT" + + - name: Build the Arch package + id: package + run: | + set -euo pipefail + # makepkg creates src/ and pkg/ next to the PKGBUILD, so build in a + # scratch directory to leave the checkout untouched. + work="$RUNNER_TEMP/fws-kitty-${{ steps.version.outputs.version }}" + rm -rf "$work" + mkdir -p "$work" + cp packaging/PKGBUILD "$work/" + cd "$work" + # Pin the build to the commit being released: main may already have + # moved on by the time makepkg clones the repository. + FWS_SOURCE_REF="commit=$GITHUB_SHA" \ + makepkg --noconfirm --nodeps --force --cleanbuild + asset="$(ls -1 ./*.pkg.tar.zst | grep -v -- '-debug-' | head -n 1)" + sha256sum "$asset" > "$asset.sha256" + cat "$asset.sha256" + echo "file=$work/$asset" >> "$GITHUB_OUTPUT" + echo "name=$asset" >> "$GITHUB_OUTPUT" + + - name: Publish the Gitea release + env: + RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }} + VERSION: ${{ steps.version.outputs.version }} + PACKAGE_NAME: ${{ steps.package.outputs.name }} + PACKAGE_FILE: ${{ steps.package.outputs.file }} + run: | + set -euo pipefail + api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY" + tag="v$VERSION" + auth="Authorization: token $RELEASE_TOKEN" + + release_id="$(curl -sS -H "$auth" "$api/releases/tags/$tag" | python3 -c ' + import json, sys + try: + print(json.load(sys.stdin).get("id") or "") + except Exception: + print("") + ')" + if [ -z "$release_id" ]; then + body="$(printf 'FWS-Kitty %s\n\nPaquet Arch du fork FWS-Kitty.\n\nInstallation :\n\n sudo pacman -U %s\n\nVérification du téléchargement :\n\n sha256sum -c %s.sha256\n' "$VERSION" "$PACKAGE_NAME" "$PACKAGE_NAME")" + payload="$(BODY="$body" TAG="$tag" VERSION="$VERSION" python3 -c ' + import json, os + print(json.dumps({ + "tag_name": os.environ["TAG"], + "name": "FWS-Kitty " + os.environ["VERSION"], + "body": os.environ["BODY"], + "draft": False, + "prerelease": False, + })) + ')" + release_id="$(curl -sS --fail-with-body -X POST -H "$auth" \ + -H 'Content-Type: application/json' -d "$payload" "$api/releases" \ + | python3 -c 'import json, sys; print(json.load(sys.stdin)["id"])')" + fi + echo "release_id=$release_id" + + # A re-run must replace its own artefacts instead of failing on them. + assets="$(curl -sS -H "$auth" "$api/releases/$release_id/assets")" + attach() { + file="$1" + name="$2" + asset_id="$(ASSETS="$assets" NAME="$name" python3 -c ' + import json, os + try: + assets = json.loads(os.environ["ASSETS"]) + except Exception: + assets = [] + print(next((a["id"] for a in assets if a.get("name") == os.environ["NAME"]), "")) + ')" + if [ -n "$asset_id" ]; then + curl -sS -X DELETE -H "$auth" "$api/releases/assets/$asset_id" -o /dev/null + fi + curl -sS --fail-with-body -X POST -H "$auth" \ + -F "attachment=@$file" "$api/releases/$release_id/assets?name=$name" -o /dev/null + echo "attached $name" + } + attach "$PACKAGE_FILE" "$PACKAGE_NAME" + attach "$PACKAGE_FILE.sha256" "$PACKAGE_NAME.sha256" + + - name: Push the package to repo.laxacube.ch + env: + REPO_TOKEN: ${{ secrets.REPO_TOKEN }} + PACKAGE_NAME: ${{ steps.package.outputs.name }} + PACKAGE_FILE: ${{ steps.package.outputs.file }} + run: | + set -euo pipefail + if [ -z "${REPO_TOKEN:-}" ]; then + echo "::warning::REPO_TOKEN is not set: the release exists but repo.laxacube.ch was not updated." + exit 0 + fi + curl -sS --fail-with-body -X POST https://repo.laxacube.ch/api/packages \ + -H "Authorization: Bearer $REPO_TOKEN" \ + -H "X-Filename: $PACKAGE_NAME" \ + -H 'Content-Type: application/octet-stream' \ + --data-binary "@$PACKAGE_FILE" + echo + # The index is rebuilt server-side, so wait for the package before + # reporting success. + url="https://repo.laxacube.ch/x86_64/$PACKAGE_NAME" + for _ in 1 2 3 4 5 6; do + if curl -fsSI "$url" > /dev/null; then + echo "published $url" + exit 0 + fi + sleep 5 + done + echo "::error::the upload was accepted but $url is not served yet" + exit 1 diff --git a/.gitignore b/.gitignore index 25c9b09..2fc55dd 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ /.venv /tags /build/ +# makepkg output: built locally and published by the release workflow, never +# committed (the artefacts are large binaries that are reproducible from a tag). +/packaging/*.pkg.tar.zst* +/packaging/*.tar.gz /fonts/ /shaders/ /linux-package/ diff --git a/README.md b/README.md index 2180ae5..27f5c95 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,25 @@ réaffecte `_branch`) : _branch=feat/file-manager-panel ``` +### Publication automatique + +`version`, à la racine, est la source de vérité des releases : il doit rester +égal à `version` dans `kitty/constants.py` et à `pkgver` dans +`packaging/PKGBUILD` (`packaging/check-version.sh` vérifie les trois et échoue +sinon). Un push sur `main` qui modifie `version` déclenche +`.gitea/workflows/package.yml` : lint, build, tests, paquet `makepkg`, release +Gitea `v` avec le paquet en pièce jointe, puis envoi à +`repo.laxacube.ch`. `.gitea/workflows/ci.yml` rejoue les mêmes contrôles sur +chaque PR et chaque push sur `main`. + +Pour reconstruire la même version amont (correctif de packaging), incrémentez +`pkgrel` dans `packaging/PKGBUILD` puis lancez le workflow à la main +(*Actions → Release → Run workflow*) : le paquet `0.50.0-3` remplace alors le +`0.50.0-2`. Une nouvelle version demande `version`, `kitty/constants.py` et +`pkgver`, avec `pkgrel=1`. La publication vers `repo.laxacube.ch` utilise le +secret `REPO_TOKEN` du dépôt, la release Gitea le secret `RELEASE_TOKEN` ; sans +`REPO_TOKEN` la release est créée mais le dépôt pacman n'est pas mis à jour. + La publication dans un dépôt pacman (`repo-add`, configuration client, automatisation) est détaillée dans `packaging/README.md`. diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 8d73949..f4f5948 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -2450,7 +2450,8 @@ lines is wrapped independently. opt( 'tab_title_template', - '"{fmt.fg.red}{bell_symbol}{activity_symbol}{exit_status_symbol}{secure_input_symbol}{fmt.fg.tab}{tab.last_focused_progress_percent}{tab.active_wd_abbreviated} {title}"', + '"{fmt.fg.red}{bell_symbol}{activity_symbol}{exit_status_symbol}{secure_input_symbol}' + '{fmt.fg.tab}{tab.last_focused_progress_percent}{tab.active_wd_abbreviated} {title}"', option_type='tab_title_template', long_text=""" A template to render the tab title. The default just renders the title with diff --git a/packaging/PKGBUILD b/packaging/PKGBUILD index 197ee78..61adbb3 100644 --- a/packaging/PKGBUILD +++ b/packaging/PKGBUILD @@ -12,7 +12,7 @@ pkgname=fws-kitty pkgver=0.50.0 -pkgrel=2 +pkgrel=3 pkgdesc='Fast, feature-rich, GPU based terminal (FWS fork with the file-manager kitten)' arch=('x86_64' 'aarch64') url='https://gitea.nocode-var.tech/FWS/FWS-Kitty' @@ -21,6 +21,10 @@ license=('GPL-3.0-only') # Replace main with the tag or commit to ship once the release is cut. _branch=main _repo='https://gitea.nocode-var.tech/FWS/FWS-Kitty.git' +# The CI sets FWS_SOURCE_REF=commit= so the package is built from the exact +# commit being released instead of whatever main points at by the time makepkg +# clones. A local build keeps following _branch. +_source_ref=${FWS_SOURCE_REF:-branch=$_branch} depends=( python harfbuzz zlib libpng lcms2 xxhash openssl @@ -43,7 +47,7 @@ provides=('kitty') conflicts=('kitty') source=( - "$pkgname::git+$_repo#branch=$_branch" + "$pkgname::git+$_repo#$_source_ref" "nerdfonts-symbols.tar.xz::https://github.com/ryanoasis/nerd-fonts/releases/download/v3.5.1/NerdFontsSymbolsOnly.tar.xz" ) sha256sums=('SKIP' '01172f37db8543edb102e5cb5c64101c9f4686630804d49b419aa07b23a69996') diff --git a/packaging/README.md b/packaging/README.md index 74fd18a..b267963 100644 --- a/packaging/README.md +++ b/packaging/README.md @@ -68,7 +68,32 @@ fonctionne pour héberger les fichiers, mais pacman a besoin d'URL stables pour `fws-kitty.db.tar.gz` et les `.pkg.tar.zst`, ce qu'un simple dossier servi par nginx (ou des assets de release) fournit directement. -Pour une publication automatique, il suffit d'enchaîner dans la CI : +## Publication automatique + +Le fichier `version`, à la racine du dépôt, déclenche tout : un push sur `main` +qui le modifie lance `.gitea/workflows/package.yml`, qui rejoue le lint, le +build et les tests, construit le paquet avec ce `PKGBUILD` depuis le commit +exact, crée la release Gitea `v` (paquet + empreinte SHA-256 en pièces +jointes) puis envoie le paquet à `repo.laxacube.ch`. + +Le workflow a besoin de deux secrets du dépôt : + +| Secret | Usage | +| --- | --- | +| `RELEASE_TOKEN` | créer la release et y attacher les fichiers | +| `REPO_TOKEN` | `POST https://repo.laxacube.ch/api/packages` | + +Sans `REPO_TOKEN`, la release est créée mais le dépôt pacman n'est pas mis à +jour (le workflow émet un avertissement). Pour reconstruire la même version +amont, incrémentez `pkgrel` ici et lancez le workflow manuellement ; le paquet +`0.50.0-3` remplace le `0.50.0-2` dans la base `fws.db` reconstruite côté +serveur. Le `PKGBUILD` lit `FWS_SOURCE_REF` (`commit=` depuis la CI) pour +construire le commit publié plutôt que la tête de `main`. + +`packaging/check-version.sh` vérifie avant le build que `version`, +`kitty/constants.py` et `pkgver` ci-dessus sont identiques. + +Pour publier à la main : ```sh makepkg -f --nodeps # ou -s avec un utilisateur autorisé à pacman diff --git a/packaging/check-version.sh b/packaging/check-version.sh new file mode 100755 index 0000000..4b3c21a --- /dev/null +++ b/packaging/check-version.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# The version file is the single source of truth for a release: it triggers the +# packaging workflow and names the tag and the Gitea release. The version is +# also duplicated where kitty and makepkg expect it, so this script checks they +# still agree and prints the version for the workflows to reuse: +# +# version="$(packaging/check-version.sh)" +# +# It runs on the CI runner and locally, before any build. +set -eu + +root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) +version=$(tr -d '[:space:]' < "$root/version") + +case "$version" in + ''|*[!0-9.]*|.*|*..*|*.) + echo "::error file=version::expected MAJOR.MINOR.PATCH, got '$version'" + exit 1 + ;; +esac +if [ "$(printf '%s' "$version" | awk -F. '{print NF}')" -ne 3 ]; then + echo "::error file=version::expected MAJOR.MINOR.PATCH, got '$version'" + exit 1 +fi + +# kitty reads its own version from this constant, and it ends up in the +# binaries and the man pages, so the release version must not drift from it. +constants=$(sed -n 's/^version: Version = Version(\([0-9]*\), \([0-9]*\), \([0-9]*\)).*/\1.\2.\3/p' "$root/kitty/constants.py" | head -n 1) +if [ "$constants" != "$version" ]; then + echo "::error file=kitty/constants.py::kitty reports '$constants' but the version file says '$version'" + exit 1 +fi + +# makepkg names the package from pkgver, so an out-of-date PKGBUILD would +# publish a package whose name does not match its release. +pkgver=$(sed -n 's/^pkgver=//p' "$root/packaging/PKGBUILD" | head -n 1) +if [ "$pkgver" != "$version" ]; then + echo "::error file=packaging/PKGBUILD::pkgver is '$pkgver' but the version file says '$version'" + exit 1 +fi + +printf '%s\n' "$version" diff --git a/version b/version new file mode 100644 index 0000000..564edf8 --- /dev/null +++ b/version @@ -0,0 +1 @@ +0.50.0