#!/bin/bash # # Purpose : Build gnome-shell-extension-coredesktop from main on Gitea and # upload it to the [federated] pacman repo, where CoreDesktop's # update installs it from # # Needs GITEA_TOKEN: a Gitea access token with write access to packages # (Settings > Applications > Generate token, scope "package: Read and write") # for an account that can publish Federated_Computer's packages. set -euo pipefail SELF="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # RELEASE_REGISTRY points it at another registry, for testing REGISTRY="${RELEASE_REGISTRY:-https://gitea.federated.computer/api/packages/Federated_Computer/arch}" REPO=federated if [ -z "${GITEA_TOKEN:-}" ]; then echo "Set GITEA_TOKEN to a Gitea token with write access to packages, e.g.:" >&2 echo " GITEA_TOKEN=... make release" >&2 exit 1 fi # The package is built from main on Gitea, not from this folder. Say so if # they differ, so a release doesn't quietly leave out local work. TOP="$(git -C "$SELF" rev-parse --show-toplevel 2> /dev/null || true)" if [ -n "$TOP" ]; then if [ -n "$(git -C "$TOP" status --porcelain --untracked-files=no)" ]; then echo "Note: you have uncommitted changes. The release is built from main on Gitea, without them." fi if git -C "$TOP" fetch --quiet origin main 2> /dev/null \ && [ "$(git -C "$TOP" rev-parse HEAD)" != "$(git -C "$TOP" rev-parse FETCH_HEAD)" ]; then echo "Note: this checkout isn't at origin/main. The release is built from origin/main." fi fi OUT="$(mktemp -d)" trap 'rm -rf "$OUT"' EXIT echo "Building the package from main..." # -C starts from a fresh source tree, so nothing from an earlier build gets in. # --nodeps: the package only copies files, so building doesn't need its # runtime dependencies (gnome-shell), which the release workflow's container # doesn't have. (cd "$SELF" && PKGDEST="$OUT" makepkg --force --cleanbuild --nodeps) PKG="$(find "$OUT" -maxdepth 1 -name '*.pkg.tar.zst' | head -n 1)" if [ -z "$PKG" ]; then echo "makepkg didn't produce a package." >&2 exit 1 fi echo "Uploading $(basename "$PKG") to [$REPO]..." STATUS="$(curl -sS -o "$OUT/response" -w '%{http_code}' -X PUT \ -H "Authorization: token $GITEA_TOKEN" \ --upload-file "$PKG" "$REGISTRY/$REPO")" case "$STATUS" in 201) echo "Released $(basename "$PKG"). CoreDesktop's next update installs it." ;; 409) # The release workflow sets this: re-running it for a commit that's already # released isn't a failure if [ -n "${RELEASE_EXISTING_OK:-}" ]; then echo "[$REPO] already has $(basename "$PKG"); nothing to do." exit 0 fi echo "[$REPO] already has this version. Commit and push a change to main to release a new one." >&2 exit 1 ;; 401|403) echo "Gitea refused the upload ($STATUS): check that GITEA_TOKEN is valid and can write packages." >&2 exit 1 ;; *) echo "The upload failed with HTTP $STATUS:" >&2 cat "$OUT/response" >&2 echo >&2 exit 1 ;; esac