CI / check (push) Successful in 3m26s
The 0.1.7-1 release was built twice: the second run attached a package with a different sha256 under the same name, so the CDN kept serving bytes from the first build while the index announced the second, and pacman rejected the download as an invalid or corrupted package. The release now refuses to replace a published package whose checksum changed and asks for a pkgrel bump instead, and it verifies the sha256 of the served file after the upload rather than only its presence.
230 lines
9.6 KiB
YAML
230 lines
9.6 KiB
YAML
# Release pipeline. A change to the version file on main is the only thing that
|
|
# publishes: the package is built once from that exact commit, the checks run on
|
|
# that same build, and it is 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:
|
|
# A single job so the package is compiled only once: makepkg builds kitty and
|
|
# the Go tools, the checks below run on that build tree, and publishing comes
|
|
# last, so a release never pays for a second build of the same commit.
|
|
release:
|
|
runs-on: arch-host
|
|
defaults:
|
|
run:
|
|
shell: bash
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install the build dependencies
|
|
run: ./packaging/install-ci-deps.sh
|
|
|
|
- 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: 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. The source tree
|
|
# is kept (no --cleanbuild) so the checks below run in it instead of
|
|
# rebuilding the project a second time.
|
|
FWS_SOURCE_REF="commit=$GITHUB_SHA" \
|
|
makepkg --noconfirm --nodeps --force
|
|
echo "FWS_SRC=$work/src/fws-kitty" >> "$GITHUB_ENV"
|
|
# kitty's linux-package target installs straight into the staging root,
|
|
# so the built binaries live there rather than in the source tree.
|
|
echo "FWS_PKG=$work/pkg/fws-kitty" >> "$GITHUB_ENV"
|
|
# ls prints ./*, which must not leak into the asset name or the
|
|
# X-Filename header of the pacman upload.
|
|
asset="$(ls -1 ./*.pkg.tar.zst | grep -v -- '-debug-' | head -n 1)"
|
|
asset="${asset#./}"
|
|
sha256sum "$asset" > "$asset.sha256"
|
|
cat "$asset.sha256"
|
|
echo "file=$work/$asset" >> "$GITHUB_OUTPUT"
|
|
echo "name=$asset" >> "$GITHUB_OUTPUT"
|
|
|
|
# These import generated code and embedded data that only exist after a
|
|
# build, so they run in the makepkg tree above, not on the bare checkout.
|
|
- name: Vet the Go code
|
|
run: |
|
|
set -euo pipefail
|
|
cd "$FWS_SRC"
|
|
go vet ./kittens/file_manager/
|
|
|
|
- name: Test the Go code
|
|
run: |
|
|
set -euo pipefail
|
|
cd "$FWS_SRC"
|
|
go test --tags testing ./kittens/file_manager/
|
|
|
|
- name: Smoke test the binaries
|
|
env:
|
|
VERSION: ${{ steps.version.outputs.version }}
|
|
run: |
|
|
set -euo pipefail
|
|
"$FWS_PKG/usr/bin/kitty" --version
|
|
"$FWS_PKG/usr/bin/kitten" --version
|
|
# The release announces the fork version, not the kitty one.
|
|
"$FWS_PKG/usr/bin/kitty" --version | grep -qF "fws-kitty $VERSION"
|
|
|
|
- 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
|
|
# Without the token every API call answers 401 and the failure would
|
|
# look like a missing release instead of a missing secret.
|
|
if [ -z "${RELEASE_TOKEN:-}" ]; then
|
|
echo "::error::RELEASE_TOKEN is not set: cannot create the release."
|
|
exit 1
|
|
fi
|
|
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 pacman version is immutable: clients cache the package by name and
|
|
# repo.laxacube.ch serves it through a CDN, so a rebuild published
|
|
# under the same version leaves those caches holding bytes the index
|
|
# no longer matches, and pacman reports the file as corrupted. A
|
|
# re-run that rebuilds identical bytes stays allowed.
|
|
local_sha256="$(cut -d' ' -f1 "$PACKAGE_FILE.sha256")"
|
|
published_sha256=""
|
|
sha_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/$tag/$PACKAGE_NAME.sha256"
|
|
if curl -fsSL "$sha_url" -o "$RUNNER_TEMP/published.sha256"; then
|
|
published_sha256="$(cut -d' ' -f1 "$RUNNER_TEMP/published.sha256")"
|
|
fi
|
|
if [ -n "$published_sha256" ] && [ "$published_sha256" != "$local_sha256" ]; then
|
|
echo "::error::$PACKAGE_NAME is already published with sha256 $published_sha256 but this build is $local_sha256"
|
|
echo "::error::bump pkgrel in packaging/PKGBUILD so the rebuild is published as its own version"
|
|
exit 1
|
|
fi
|
|
|
|
# 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 and the file is served through a
|
|
# CDN, so a HEAD is not enough: the index and the file can disagree
|
|
# for as long as the CDN caches the previous build under this name,
|
|
# and the checksum is exactly what pacman verifies before installing.
|
|
url="https://repo.laxacube.ch/x86_64/$PACKAGE_NAME"
|
|
expected="$(cut -d' ' -f1 "$PACKAGE_FILE.sha256")"
|
|
for _ in 1 2 3 4 5 6; do
|
|
if [ "$(curl -fsSL "$url" | sha256sum | cut -d' ' -f1)" = "$expected" ]; then
|
|
echo "published $url"
|
|
exit 0
|
|
fi
|
|
sleep 5
|
|
done
|
|
echo "::error::$url does not serve this build (expected sha256 $expected)"
|
|
echo "::error::the CDN is probably still caching an older file under this name: purge it before re-running"
|
|
exit 1
|