ci(release): make the package upload idempotent and verified
version / print-version (push) Successful in 1s

repo.laxacube.ch serves a package name with immutable bytes, so a re-run
that uploaded a different build under the same name left pacman clients
downloading a file that no longer matched the repository index. The
upload now skips a version already published and checks the checksum of
the file served back after publishing.
This commit is contained in:
BlackAngelTV committed 2026-11-27 07:37:57 +01:00
1 parent 6a85eed786
commit 589b447569
1 file changed
+57 -4
+57 -4
View File
@@ -147,12 +147,39 @@ jobs:
fi
- name: Publish to repo.laxacube.ch
if: env.REPO_TOKEN != ''
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
PACKAGE_FILE: ${{ steps.package.outputs.file }}
PACKAGE_NAME: ${{ steps.package.outputs.name }}
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
# A pacman version is immutable: clients cache the package by its
# name, so a second build published under the same name leaves them
# disagreeing and pacman reports the download as corrupted. Once the
# repository serves the name there is nothing left to publish: a
# re-run is a no-op, and a changed build needs a pkgrel bump so it
# gets its own package name.
url="https://repo.laxacube.ch/x86_64/$PACKAGE_NAME"
local_sha256="$(sha256sum "$PACKAGE_FILE" | cut -d' ' -f1)"
repo_sha256=""
if curl -fsSL "$url" -o "$RUNNER_TEMP/repo.pkg" 2>/dev/null; then
repo_sha256="$(sha256sum "$RUNNER_TEMP/repo.pkg" | cut -d' ' -f1)"
fi
if [ -n "$repo_sha256" ]; then
if [ "$repo_sha256" = "$local_sha256" ]; then
echo "$PACKAGE_NAME is already published to repo.laxacube.ch, nothing to do"
else
echo "::warning::$PACKAGE_NAME is already published to repo.laxacube.ch with sha256 $repo_sha256, this build is $local_sha256 and is not published"
echo "::warning::bump pkgrel in PKGBUILD to publish this build under its own package name"
fi
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" \
@@ -160,6 +187,32 @@ jobs:
--data-binary "@$PACKAGE_FILE"
echo
- name: Warn when the upload token is missing
if: env.REPO_TOKEN == ''
run: echo "::warning::REPO_TOKEN is not set, the package was released but not published to repo.laxacube.ch"
# 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.
# A freshly accepted upload is not routable instantly, so an absent
# file is retried before giving up; different bytes are a real
# mismatch and fail at once, since that is what breaks pacman.
expected="$local_sha256"
code=000
for _ in $(seq 1 24); do
code="$(curl -sS -o "$RUNNER_TEMP/served.pkg" -w '%{http_code}' "$url" || true)"
if [ "$code" = 200 ]; then
served="$(sha256sum "$RUNNER_TEMP/served.pkg" | cut -d' ' -f1)"
if [ "$served" = "$expected" ]; then
echo "published $url"
exit 0
fi
echo "::error::$url serves sha256 $served instead of $expected"
echo "::error::the CDN is still caching another build under this name: purge it before re-running"
exit 1
fi
sleep 5
done
if [ "$code" = 404 ]; then
echo "::warning::$url is not visible yet; the repository accepted the upload, pacman will see it once the index is rebuilt"
exit 0
fi
echo "::error::$url answered HTTP $code after the upload"
exit 1