diff --git a/.gitea/workflows/package.yml b/.gitea/workflows/package.yml new file mode 100644 index 00000000..4aea4a12 --- /dev/null +++ b/.gitea/workflows/package.yml @@ -0,0 +1,65 @@ +# Build the Arch package from build-aux/arch/PKGBUILD on every push to main and +# publish it to the [federated] pacman repo on this Gitea, where CoreDesktop +# installs and updates it from. pkgver counts commits, so every push is a new +# version. Gitea signs the package and the repo database with the repo's key. +# +# Needs a PACKAGE_TOKEN secret: a token with write:package scope from a user +# who can publish Federated_Computer's packages. +name: package + +on: + push: + branches: [main] + workflow_dispatch: + +env: + REPO_URL: https://gitea.federated.computer/api/packages/Federated_Computer/arch/federated + +jobs: + package: + runs-on: ubuntu-latest + container: archlinux:latest + steps: + # nodejs is for actions/checkout itself + - name: Install tools + run: pacman -Syu --noconfirm --needed base-devel git nodejs + + # All the history, as pkgver counts the commits + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # makepkg won't run as root. It installs the dependencies with sudo. + - name: Add a build user + run: | + useradd -m builder + echo 'builder ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/builder + chown -R builder "$GITHUB_WORKSPACE" + + # The PKGBUILD clones main from Gitea, which may have moved on since this + # push. Build this checkout at this commit instead. + - name: Build the package + run: | + mkdir /build + cp build-aux/arch/PKGBUILD /build/ + echo "source=(\"federated-calendar::git+file://$GITHUB_WORKSPACE#commit=$GITHUB_SHA\")" >> /build/PKGBUILD + chown -R builder /build + su builder -c "cd /build && makepkg --syncdeps --noconfirm" + + # Not the federated-calendar-debug package makepkg also makes. + # A run that's tried again finds its version already there: Gitea answers + # 409 Conflict, and the package is published, so that isn't a failure. + - name: Publish the package + env: + PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }} + run: | + pkg=$(ls /build/federated-calendar-[0-9]*.pkg.tar.zst) + echo "Uploading ${pkg##*/}..." + status=$(curl -sS -o /tmp/response -w '%{http_code}' \ + -H "Authorization: token $PACKAGE_TOKEN" \ + --upload-file "$pkg" "$REPO_URL") + case $status in + 201) echo "Published." ;; + 409) echo "This version is already published." ;; + *) echo "Upload failed with HTTP $status:"; cat /tmp/response; exit 1 ;; + esac