From 82f196bcc30ae7fbadf2f1e863c4f10c10b425b3 Mon Sep 17 00:00:00 2001 From: Staaaszek Date: Thu, 26 Nov 2026 11:00:59 +0100 Subject: [PATCH 1/2] Document the AUR release and the Discord notifications --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 8124f77..40247d6 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,37 @@ Conventions (see `tests/backend/html_parser_test.cpp` for an example): whose size was just checked. - Unit tests must not use the network or the user's config. +### Releases and notifications + +Every push to `main` (i.e. every merged pull request) runs +`.github/workflows/aur-release.yml`. After the CI passes, it compares the +version with the [AUR package](https://aur.archlinux.org/packages/email-client) +and releases only if it is newer: + +1. builds and installs the package from `aur/PKGBUILD` in an Arch container, +2. tags the commit with the version, e.g. `2.1.0`, +3. pushes the updated `PKGBUILD` and `.SRCINFO` to the AUR. + +The version is `project(VERSION)` in `CMakeLists.txt` plus `pkgrel` in +`aur/PKGBUILD`. To release: + +- new code: bump `VERSION` and set `pkgrel=1`, +- a packaging-only fix of the released version: bump `pkgrel` only (the + existing tag is packaged again, not the new commit). + +A merge without a version bump runs the CI and publishes nothing. + +The team's Discord channel gets a message for every PR merged into `main` +(`.github/workflows/discord-pr-merged.yml`) and one for every release: success +when the new version is on the AUR, an error when the CI or the release failed. + +Repository secrets (Settings → Secrets and variables → Actions): + +| Secret | Value | +|---|---| +| `AUR_SSH_PRIVATE_KEY` | Private SSH key whose public key is on the AUR account maintaining the package | +| `DISCORD_WEBHOOK_URL` | Discord webhook URL of the channel; without it the messages are skipped | + ## License This project is licensed under the GNU GPL version 3 (or later). See the From c52dee99c7884f78cd59357e6bba5f60c384d287 Mon Sep 17 00:00:00 2001 From: Staaaszek Date: Thu, 26 Nov 2026 11:08:30 +0100 Subject: [PATCH 2/2] Pick the release version from PR labels A PR labelled release:patch, release:minor or release:major bumps the last version tag when merged into main; the version no longer lives in CMakeLists.txt or as pkgrel in aur/PKGBUILD. Use the DISCORD_WEBHOOK secret that is actually set. --- .github/workflows/aur-release.yml | 105 +++++++++++++----------- .github/workflows/discord-pr-merged.yml | 4 +- CMakeLists.txt | 2 +- README.md | 29 +++---- aur/PKGBUILD | 8 +- 5 files changed, 78 insertions(+), 70 deletions(-) diff --git a/.github/workflows/aur-release.yml b/.github/workflows/aur-release.yml index 72c4236..915312a 100644 --- a/.github/workflows/aur-release.yml +++ b/.github/workflows/aur-release.yml @@ -1,13 +1,14 @@ name: AUR release -# Every push to `main` releases the version from project(VERSION) in -# CMakeLists.txt to the AUR: it tags the commit as , fills in -# aur/PKGBUILD and pushes it with a fresh .SRCINFO to the AUR repository. -# A push whose - is already on the AUR publishes nothing. +# Every push to `main` that comes from a PR labelled release:patch, +# release:minor or release:major releases a new version to the AUR: the last +# version tag (e.g. 2.1.0) is bumped accordingly, the commit is tagged with +# the result, and aur/PKGBUILD is filled in and pushed with a fresh .SRCINFO to +# the AUR repository. Pushes without such a label only run the CI. # # Needs the AUR_SSH_PRIVATE_KEY secret: the private SSH key whose public key is # set on the AUR account that maintains the package. The outcome of a release -# (or a failure of this workflow) is posted to Discord via DISCORD_WEBHOOK_URL. +# (or a failure of this workflow) is posted to Discord via DISCORD_WEBHOOK. on: push: branches: [main] @@ -27,18 +28,19 @@ jobs: container: archlinux:latest permissions: contents: write # pushing the version tag + pull-requests: read # the labels of the merged PR outputs: publish: ${{ steps.version.outputs.publish }} - version: ${{ steps.version.outputs.pkgver }}-${{ steps.version.outputs.pkgrel }} + version: ${{ steps.version.outputs.pkgver }} env: AUR_REPO: ssh://aur@aur.archlinux.org/email-client.git steps: - name: Install dependencies - run: pacman -Syu --noconfirm --needed base-devel git openssh sudo + run: pacman -Syu --noconfirm --needed base-devel git openssh sudo jq - uses: actions/checkout@v5 with: - fetch-depth: 0 # tags, to see whether this version is already tagged + fetch-depth: 0 # all tags, to find the last version - name: Set up SSH for the AUR env: @@ -56,45 +58,60 @@ jobs: - name: Decide what to release id: version + env: + GH_TOKEN: ${{ github.token }} run: | + semver='^[0-9]+\.[0-9]+\.[0-9]+$' git clone "$AUR_REPO" aur-repo + aur="" + [ -f aur-repo/.SRCINFO ] && aur=$(sed -n 's/^\tpkgver = //p' aur-repo/.SRCINFO) - pkgver=$(sed -n '/^project(/,/)/s/^ *VERSION *\([0-9.]*\).*/\1/p' CMakeLists.txt) - pkgrel=$(sed -n 's/^pkgrel=//p' aur/PKGBUILD) - [ -n "$pkgver" ] && [ -n "$pkgrel" ] || { echo "::error::Cannot read the version"; exit 1; } - new="$pkgver-$pkgrel" - - old="" - if [ -f aur-repo/.SRCINFO ]; then - old="$(sed -n 's/^\tpkgver = //p' aur-repo/.SRCINFO)-$(sed -n 's/^\tpkgrel = //p' aur-repo/.SRCINFO)" - fi - echo "AUR has ${old:-nothing}, this commit is $new" - - publish=true - if [ -n "$old" ]; then - case $(vercmp "$new" "$old") in - 0) publish=false - echo "::notice::$new is already on the AUR; bump project(VERSION) in CMakeLists.txt (or pkgrel in aur/PKGBUILD) to release" ;; - -1) echo "::error::$new is older than $old on the AUR"; exit 1 ;; - esac - fi + out() { + { echo "pkgver=$1"; echo "publish=$2"; echo "tag_exists=$3"; } >> "$GITHUB_OUTPUT" + } - # An existing tag is the released source of that version: a pkgrel bump - # republishes it unchanged, it does not move the tag to this commit - if tag=$(git rev-parse -q --verify "refs/tags/$pkgver^{commit}"); then + # A re-run of a release that already tagged this commit keeps its version + pkgver=$(git tag --points-at "$GITHUB_SHA" | grep -E "$semver" | sort -V | tail -1 || true) + if [ -n "$pkgver" ]; then tag_exists=true - [ "$tag" = "$GITHUB_SHA" ] || [ "$publish" = false ] || \ - echo "::warning::Tag $pkgver already exists on $tag, so it is packaged instead of this commit; bump project(VERSION) to release the new code" + echo "This commit is already tagged $pkgver" else tag_exists=false + labels=$(curl -fsSL --retry 3 \ + -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \ + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" \ + | jq -r '.[0].labels[]?.name') + bump="" + for level in patch minor major; do # the biggest one wins + grep -qx "release:$level" <<< "$labels" && bump=$level + done + if [ -z "$bump" ]; then + echo "::notice::No release:patch/minor/major label on the merged PR, nothing to release" + out "" false false + exit 0 + fi + + last=$(git tag -l | grep -E "$semver" | sort -V | tail -1 || true) + last=${last:-0.0.0} + # In case a newer version was published to the AUR by hand + if [[ "$aur" =~ $semver ]] && [ "$(vercmp "$aur" "$last")" -gt 0 ]; then + last=$aur + fi + IFS=. read -r major minor patch <<< "$last" + case $bump in + major) pkgver="$((major + 1)).0.0" ;; + minor) pkgver="$major.$((minor + 1)).0" ;; + patch) pkgver="$major.$minor.$((patch + 1))" ;; + esac + echo "release:$bump label: $last -> $pkgver" fi - { - echo "pkgver=$pkgver" - echo "pkgrel=$pkgrel" - echo "publish=$publish" - echo "tag_exists=$tag_exists" - } >> "$GITHUB_OUTPUT" + if [ "$aur" = "$pkgver" ]; then + echo "::notice::$pkgver is already on the AUR" + out "$pkgver" false "$tag_exists" + else + out "$pkgver" true "$tag_exists" + fi # Build the package from a local copy of the source before tagging, so a # broken package leaves neither a tag nor an AUR update behind @@ -102,15 +119,12 @@ jobs: if: steps.version.outputs.publish == 'true' env: PKGVER: ${{ steps.version.outputs.pkgver }} - TAG_EXISTS: ${{ steps.version.outputs.tag_exists }} run: | useradd -m builder echo 'builder ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/builder - ref=HEAD - [ "$TAG_EXISTS" = true ] && ref="refs/tags/$PKGVER" install -d -o builder /home/builder/pkg - git archive --prefix="Email-Client-$PKGVER/" -o "/home/builder/pkg/email-client-$PKGVER.tar.gz" "$ref" + git archive --prefix="Email-Client-$PKGVER/" -o "/home/builder/pkg/email-client-$PKGVER.tar.gz" HEAD sed -e "s/^pkgver=.*/pkgver=$PKGVER/" \ -e 's|^source=.*|source=("${pkgname}-${pkgver}.tar.gz")|' \ aur/PKGBUILD > /home/builder/pkg/PKGBUILD @@ -142,7 +156,6 @@ jobs: if: steps.version.outputs.publish == 'true' env: PKGVER: ${{ steps.version.outputs.pkgver }} - PKGREL: ${{ steps.version.outputs.pkgrel }} run: | url="https://github.com/Student-Team-Projects/Email-Client/archive/refs/tags/$PKGVER.tar.gz" sum=$(curl -fsSL --retry 5 --retry-all-errors "$url" | sha256sum | cut -d' ' -f1) @@ -159,7 +172,7 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add PKGBUILD .SRCINFO - git commit -m "Update to $PKGVER-$PKGREL" \ + git commit -m "Update to $PKGVER" \ -m "From ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}" git push origin HEAD:master @@ -177,7 +190,7 @@ jobs: steps: - name: Send Discord message env: - WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} + WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} CI_RESULT: ${{ needs.ci.result }} RELEASE_RESULT: ${{ needs.release.result }} VERSION: ${{ needs.release.outputs.version }} @@ -186,7 +199,7 @@ jobs: SHORT_SHA: ${{ github.sha }} run: | if [ -z "$WEBHOOK" ]; then - echo "::warning::DISCORD_WEBHOOK_URL secret is not set, skipping" + echo "::warning::DISCORD_WEBHOOK secret is not set, skipping" exit 0 fi diff --git a/.github/workflows/discord-pr-merged.yml b/.github/workflows/discord-pr-merged.yml index a3f6709..6cb6478 100644 --- a/.github/workflows/discord-pr-merged.yml +++ b/.github/workflows/discord-pr-merged.yml @@ -17,7 +17,7 @@ jobs: steps: - name: Send Discord message env: - WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} + WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} # Passed through env, never interpolated into the script, because # the PR title and author are controlled by whoever opened the PR PR_NUMBER: ${{ github.event.pull_request.number }} @@ -31,7 +31,7 @@ jobs: DELETIONS: ${{ github.event.pull_request.deletions }} run: | if [ -z "$WEBHOOK" ]; then - echo "::warning::DISCORD_WEBHOOK_URL secret is not set, skipping" + echo "::warning::DISCORD_WEBHOOK secret is not set, skipping" exit 0 fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e39042..c869998 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.22) +# The version is the git tag; the AUR release workflow picks it from PR labels project(email_client LANGUAGES CXX - VERSION 2.1.0 ) set(CMAKE_CXX_STANDARD 20) diff --git a/README.md b/README.md index 40247d6..c27eb60 100644 --- a/README.md +++ b/README.md @@ -94,23 +94,20 @@ Conventions (see `tests/backend/html_parser_test.cpp` for an example): ### Releases and notifications -Every push to `main` (i.e. every merged pull request) runs -`.github/workflows/aur-release.yml`. After the CI passes, it compares the -version with the [AUR package](https://aur.archlinux.org/packages/email-client) -and releases only if it is newer: +Releases are driven by labels on pull requests. When a PR labelled +`release:patch`, `release:minor` or `release:major` is merged into `main`, +`.github/workflows/aur-release.yml`, after the CI passes: -1. builds and installs the package from `aur/PKGBUILD` in an Arch container, -2. tags the commit with the version, e.g. `2.1.0`, -3. pushes the updated `PKGBUILD` and `.SRCINFO` to the AUR. +1. bumps the last version tag accordingly (e.g. `2.1.0` → `2.1.1` / `2.2.0` / `3.0.0`), +2. builds and installs the package from `aur/PKGBUILD` in an Arch container, +3. tags the merge commit with the new version, +4. pushes the updated `PKGBUILD` and `.SRCINFO` to the + [AUR package](https://aur.archlinux.org/packages/email-client). -The version is `project(VERSION)` in `CMakeLists.txt` plus `pkgrel` in -`aur/PKGBUILD`. To release: - -- new code: bump `VERSION` and set `pkgrel=1`, -- a packaging-only fix of the released version: bump `pkgrel` only (the - existing tag is packaged again, not the new commit). - -A merge without a version bump runs the CI and publishes nothing. +A PR without one of these labels only runs the CI. With several, the biggest +bump wins. The label can also be added after the merge: then re-run the +workflow run of the merge commit. Nothing has to be edited by hand; the +version lives only in the git tags. The team's Discord channel gets a message for every PR merged into `main` (`.github/workflows/discord-pr-merged.yml`) and one for every release: success @@ -121,7 +118,7 @@ Repository secrets (Settings → Secrets and variables → Actions): | Secret | Value | |---|---| | `AUR_SSH_PRIVATE_KEY` | Private SSH key whose public key is on the AUR account maintaining the package | -| `DISCORD_WEBHOOK_URL` | Discord webhook URL of the channel; without it the messages are skipped | +| `DISCORD_WEBHOOK` | Discord webhook URL of the channel; without it the messages are skipped | ## License diff --git a/aur/PKGBUILD b/aur/PKGBUILD index 6f1b734..4c5762e 100644 --- a/aur/PKGBUILD +++ b/aur/PKGBUILD @@ -1,11 +1,9 @@ # Please report maintenance problems to the project GitHub issue tracker # i.e. https://github.com/Student-Team-Projects/email-client/issues -# Published to the AUR by .github/workflows/aur-release.yml on every push to the -# `main` branch. pkgver and sha256sums are filled in by the workflow (pkgver -# comes from project(VERSION) in CMakeLists.txt), so do not edit them here. -# Bump pkgrel only for a packaging-only fix of an already released version, -# and reset it to 1 together with a version bump. +# Published to the AUR by .github/workflows/aur-release.yml when a PR labelled +# release:patch/minor/major is merged into `main`. pkgver and sha256sums are +# filled in by the workflow (pkgver is the new version tag), so do not edit them. pkgname=email-client pkgver=0.0.0