Files
FWS-DiskCleaner/.gitea/workflows/package.yml
T
BlackAngelTV 26c9658f0b
package / package (push) Failing after 3s
version / print-version (push) Successful in 2s
chore: add repository baseline with Gitea CI
The repository needs its ignore rules, a version file and the workflows
that turn a version bump into a signed Arch package published to
repo.laxacube.ch.
2026-11-26 18:14:36 +01:00

166 lines
6.6 KiB
YAML

name: package
on:
push:
branches: [main]
# Only a version change produces a release; other commits stay off this path.
paths: [version]
workflow_dispatch:
permissions:
contents: write
# Releases are ordered: a second run waits instead of racing for the same tag.
concurrency:
group: package
cancel-in-progress: false
jobs:
package:
# Arch containers cannot be stored on the NTFS runner disk: pacman's local
# database uses ':' in epoch directory names, which NTFS rejects. The package
# is therefore built by makepkg on the Arch host itself.
runs-on: arch-host
env:
REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
# makepkg writes the keyring it imports into; the job keeps it out of the
# checkout and removes it with the runner's temporary directory.
GNUPGHOME: ${{ runner.temp }}/gnupg
steps:
- uses: actions/checkout@v4
- name: Read the version file
id: version
run: |
set -euo pipefail
version="$(tr -d '[:space:]' < version)"
if [ -z "$version" ]; then
echo "::error file=version::the version file is empty"
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Import the package signing key
if: env.GPG_PRIVATE_KEY != ''
run: |
set -euo pipefail
mkdir -p "$GNUPGHOME"
chmod 700 "$GNUPGHOME"
printf '%s' "$GPG_PRIVATE_KEY" | base64 -d | gpg --batch --import
gpg --batch --list-secret-keys --keyid-format=long
- name: Build the Arch package
id: package
run: |
set -euo pipefail
version='${{ steps.version.outputs.version }}'
work="$RUNNER_TEMP/build"
rm -rf "$work"
mkdir -p "$work"
cp PKGBUILD version "$work/"
git archive --format=tar.gz --prefix="fws-diskcleaner-$version/" \
-o "$work/fws-diskcleaner-$version.tar.gz" HEAD
# makepkg needs the PKGBUILD, the version file it reads and the source
# tarball in one directory; the runner's checkout stays untouched.
cd "$work"
# The packager and the signing key live in makepkg's configuration, and
# makepkg has no command-line flag for either.
conf="$work/makepkg.conf"
cp /etc/makepkg.conf "$conf"
printf 'PACKAGER="%s"\n' 'BlackAngelTVdev <dami.scoot3@gmail.com>' >> "$conf"
sign=()
if gpg --batch --list-secret-keys 2>/dev/null | grep -q '^sec'; then
gpgkey="$(gpg --batch --with-colons --list-secret-keys \
| awk -F: '/^fpr:/{print $10; exit}')"
printf 'GPGKEY="%s"\n' "$gpgkey" >> "$conf"
sign=(--sign)
else
echo "::warning::no signing key available, releasing an unsigned package"
fi
makepkg --config "$conf" --noconfirm --nodeps --force --cleanbuild "${sign[@]}"
asset="$(ls -1 ./*.pkg.tar.zst | grep -v -- '-debug-' | head -1)"
echo "file=$work/${asset##*/}" >> "$GITHUB_OUTPUT"
echo "name=${asset##*/}" >> "$GITHUB_OUTPUT"
if [ -f "${asset}.sig" ]; then
echo "sig=$work/${asset##*/}.sig" >> "$GITHUB_OUTPUT"
fi
- name: Verify the signature
if: steps.package.outputs.sig != ''
env:
PACKAGE_FILE: ${{ steps.package.outputs.file }}
SIGNATURE: ${{ steps.package.outputs.sig }}
run: |
set -euo pipefail
gpg --batch --verify "$SIGNATURE" "$PACKAGE_FILE"
- name: Create the release and attach the artefacts
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
PACKAGE_FILE: ${{ steps.package.outputs.file }}
PACKAGE_NAME: ${{ steps.package.outputs.name }}
SIGNATURE: ${{ steps.package.outputs.sig }}
run: |
set -euo pipefail
api="$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY"
version='${{ steps.version.outputs.version }}'
tag="v$version"
auth="Authorization: token $GITEA_TOKEN"
release_id="$(curl -sS -H "$auth" "$api/releases/tags/$tag" | jq -r 'if type == "object" then (.id // empty) else empty end')"
if [ -z "$release_id" ]; then
body="FWS-DiskCleaner $version
Arch package: \`$PACKAGE_NAME\`
Signature: \`$PACKAGE_NAME.sig\`, key \`fws-package-signing.asc\`
Verify the download with:
\`\`\`
gpg --verify $PACKAGE_NAME.sig $PACKAGE_NAME
\`\`\`"
release_id="$(curl -sS --fail-with-body -X POST -H "$auth" -H 'Content-Type: application/json' \
-d "$(jq -n --arg tag "$tag" --arg name "FWS-DiskCleaner $version" \
--arg body "$body" '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')" \
"$api/releases" | jq -r '.id')"
fi
# A re-run must not fail on its own previous asset, so an asset with the
# same name is replaced rather than duplicated.
previous="$(curl -sS -H "$auth" "$api/releases/$release_id/assets")"
attach() {
local file="$1" name="$2" id
id="$(jq -r --arg n "$name" '.[] | select(.name == $n) | .id' <<<"$previous")"
if [ -n "$id" ]; then
curl -sS -X DELETE -H "$auth" "$api/releases/assets/$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"
if [ -n "$SIGNATURE" ]; then
attach "$SIGNATURE" "$PACKAGE_NAME.sig"
attach packaging/fws-package-signing.asc fws-package-signing.asc
fi
- name: Publish to repo.laxacube.ch
if: env.REPO_TOKEN != ''
env:
PACKAGE_FILE: ${{ steps.package.outputs.file }}
PACKAGE_NAME: ${{ steps.package.outputs.name }}
run: |
set -euo pipefail
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
- 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"