Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 59 additions & 46 deletions .github/workflows/aur-release.yml
Original file line number Diff line number Diff line change
@@ -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 <version>, fills in
# aur/PKGBUILD and pushes it with a fresh .SRCINFO to the AUR repository.
# A push whose <version>-<pkgrel> 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]
Expand All @@ -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:
Expand All @@ -56,61 +58,73 @@ 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
- name: Test build of the package
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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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 }}
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/discord-pr-merged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,34 @@ 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

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. 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).

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
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` | 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
Expand Down
8 changes: 3 additions & 5 deletions aur/PKGBUILD
Original file line number Diff line number Diff line change
@@ -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
Expand Down