diff --git a/.github/workflows/aur-release.yml b/.github/workflows/aur-release.yml new file mode 100644 index 0000000..72c4236 --- /dev/null +++ b/.github/workflows/aur-release.yml @@ -0,0 +1,235 @@ +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. +# +# 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. +on: + push: + branches: [main] + +# Never two releases at once; a newer push waits instead of cancelling +concurrency: + group: aur-release + cancel-in-progress: false + +jobs: + ci: + uses: ./.github/workflows/ci.yml + + release: + needs: ci + runs-on: ubuntu-24.04 + container: archlinux:latest + permissions: + contents: write # pushing the version tag + outputs: + publish: ${{ steps.version.outputs.publish }} + version: ${{ steps.version.outputs.pkgver }}-${{ steps.version.outputs.pkgrel }} + 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 + + - uses: actions/checkout@v5 + with: + fetch-depth: 0 # tags, to see whether this version is already tagged + + - name: Set up SSH for the AUR + env: + AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }} + run: | + [ -n "$AUR_SSH_PRIVATE_KEY" ] || { echo "::error::The AUR_SSH_PRIVATE_KEY secret is not set"; exit 1; } + # Explicit paths: in a container job HOME is not the home directory ssh uses + install -dm700 /etc/aur-ssh + printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > /etc/aur-ssh/key + chmod 600 /etc/aur-ssh/key + # Pinned host key (SHA256:RFzBCUItH9LZS0cKB5UE6ceAYhBD5C8GeOBip8Z11+4, as on the Arch wiki) + echo 'aur.archlinux.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuBKrPzbawxA/k2g6NcyV5jmqwJ2s+zpgZGZ7tpLIcN' > /etc/aur-ssh/known_hosts + echo "GIT_SSH_COMMAND=ssh -F /dev/null -i /etc/aur-ssh/key -o IdentitiesOnly=yes -o UserKnownHostsFile=/etc/aur-ssh/known_hosts -o StrictHostKeyChecking=yes" >> "$GITHUB_ENV" + git config --global --add safe.directory '*' + + - name: Decide what to release + id: version + run: | + git clone "$AUR_REPO" aur-repo + + 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 + + # 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 + 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" + else + tag_exists=false + fi + + { + echo "pkgver=$pkgver" + echo "pkgrel=$pkgrel" + echo "publish=$publish" + echo "tag_exists=$tag_exists" + } >> "$GITHUB_OUTPUT" + + # 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" + sed -e "s/^pkgver=.*/pkgver=$PKGVER/" \ + -e 's|^source=.*|source=("${pkgname}-${pkgver}.tar.gz")|' \ + aur/PKGBUILD > /home/builder/pkg/PKGBUILD + chown -R builder /home/builder/pkg + + # vmime is an AUR dependency, so pacman cannot install it + sudo -u builder bash -euo pipefail -c ' + cd ~ + git clone https://aur.archlinux.org/vmime.git + # A split package: vmime and vmime-libonly conflict, so install only vmime + (cd vmime && makepkg -s --noconfirm && + sudo pacman -U --noconfirm "$(makepkg --packagelist | grep "/vmime-[0-9]")") + cd pkg && makepkg -si --noconfirm + ' + # Every library must come from an installed package, not from the build tree + if ldd /usr/bin/email_client | grep -E 'not found|/home/'; then + echo "::error::The packaged email_client is missing libraries"; exit 1 + fi + + - name: Tag the release + if: steps.version.outputs.publish == 'true' && steps.version.outputs.tag_exists == 'false' + env: + PKGVER: ${{ steps.version.outputs.pkgver }} + run: | + git tag "$PKGVER" "$GITHUB_SHA" + git push origin "refs/tags/$PKGVER" + + - name: Publish to the AUR + 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) + + sed -e "s/^pkgver=.*/pkgver=$PKGVER/" \ + -e "s/^sha256sums=.*/sha256sums=('$sum')/" \ + aur/PKGBUILD > aur-repo/PKGBUILD + # makepkg refuses to run as root + install -d -o builder /home/builder/srcinfo + cp aur-repo/PKGBUILD /home/builder/srcinfo/ + (cd /home/builder/srcinfo && sudo -u builder makepkg --printsrcinfo) > aur-repo/.SRCINFO + + cd aur-repo + 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" \ + -m "From ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}" + git push origin HEAD:master + + # One message per release attempt: success when a new version reached the + # AUR, failure when the CI or the release broke. Nothing when there was + # nothing new to release. + notify: + needs: [ci, release] + if: >- + always() && (needs.release.outputs.publish == 'true' + || contains(fromJSON('["failure", "cancelled"]'), needs.ci.result) + || contains(fromJSON('["failure", "cancelled"]'), needs.release.result)) + runs-on: ubuntu-latest + permissions: {} + steps: + - name: Send Discord message + env: + WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} + CI_RESULT: ${{ needs.ci.result }} + RELEASE_RESULT: ${{ needs.release.result }} + VERSION: ${{ needs.release.outputs.version }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} + SHORT_SHA: ${{ github.sha }} + run: | + if [ -z "$WEBHOOK" ]; then + echo "::warning::DISCORD_WEBHOOK_URL secret is not set, skipping" + exit 0 + fi + + if [ "$CI_RESULT" = success ] && [ "$RELEASE_RESULT" = success ]; then + payload=$(jq -n --arg version "$VERSION" --arg run "$RUN_URL" '{ + username: "Release Alarm πŸ“¦", + allowed_mentions: { parse: [] }, + content: "πŸš¨πŸš¨πŸŽ‰πŸŽŠ **NOWA WERSJA W AUR!** πŸŽŠπŸŽ‰πŸš¨πŸš¨\nπŸ“¦βœ¨πŸ₯³πŸΎ Release poszedΕ‚! 🍾πŸ₯³βœ¨πŸ“¦", + embeds: [{ + title: ("email-client " + $version), + url: "https://aur.archlinux.org/packages/email-client", + color: 3066993, + description: "πŸŽŠπŸš€ Gotowe do instalacji: `yay -S email-client` πŸ”₯βœ¨πŸŽ‰", + fields: [ + { name: "πŸ”§ Workflow", value: ("[logi](" + $run + ")"), inline: true } + ] + }] + }') + else + if [ "$CI_RESULT" != success ]; then + stage="CI" + else + stage="Release" + fi + payload=$(jq -n --arg stage "$stage" --arg run "$RUN_URL" \ + --arg commit "$COMMIT_URL" --arg sha "${SHORT_SHA:0:7}" --arg version "$VERSION" '{ + username: "Release Alarm πŸ“¦", + allowed_mentions: { parse: [] }, + content: (if $stage == "CI" then "🚨❌🚨 **CI NA MAIN NIE PRZESZŁO** 🚨❌🚨" else "🚨❌🚨 **RELEASE DO AUR NIE POSZEDŁ** 🚨❌🚨" end), + embeds: [{ + title: ("PadΕ‚o na etapie: " + $stage), + url: $run, + color: 15158332, + description: "🧯 AUR bez zmian. SzczegΓ³Ε‚y w logach workflow πŸ‘†πŸ”", + fields: ([ + { name: "πŸ“Œ Commit", value: ("[`" + $sha + "`](" + $commit + ")"), inline: true } + ] + (if $version != "-" and $version != "" then + [{ name: "πŸ“¦ Wersja", value: $version, inline: true }] else [] end)) + }] + }') + fi + + curl --fail-with-body -sS \ + -H "Content-Type: application/json" \ + -d "$payload" \ + "$WEBHOOK" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfb04c9..54bac25 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,13 @@ name: CI # Every push to any branch, plus pull requests (needed for PRs from forks, -# whose pushes do not run workflows in this repository) +# whose pushes do not run workflows in this repository). Pushes to `main` are +# tested by aur-release.yml, which calls this workflow before releasing. on: push: + branches-ignore: [main] pull_request: + workflow_call: # A newer push to the same branch or PR cancels the older, now outdated run; # on main every commit is tested to the end diff --git a/.github/workflows/discord-pr-merged.yml b/.github/workflows/discord-pr-merged.yml new file mode 100644 index 0000000..a3f6709 --- /dev/null +++ b/.github/workflows/discord-pr-merged.yml @@ -0,0 +1,69 @@ +name: Discord PR merged + +# Announces every pull request merged into main on the team's Discord channel. +# pull_request_target so that PRs from forks also have access to the webhook +# secret; it is safe here because the job never checks out or runs PR code. +on: + pull_request_target: + types: [closed] + branches: [main] + +permissions: {} + +jobs: + notify: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: Send Discord message + env: + WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_URL }} + # 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 }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_AUTHOR_AVATAR: ${{ github.event.pull_request.user.avatar_url }} + MERGED_BY: ${{ github.event.pull_request.merged_by.login }} + HEAD_BRANCH: ${{ github.event.pull_request.head.label }} + ADDITIONS: ${{ github.event.pull_request.additions }} + DELETIONS: ${{ github.event.pull_request.deletions }} + run: | + if [ -z "$WEBHOOK" ]; then + echo "::warning::DISCORD_WEBHOOK_URL secret is not set, skipping" + exit 0 + fi + + payload=$(jq -n \ + --arg number "$PR_NUMBER" \ + --arg title "$PR_TITLE" \ + --arg url "$PR_URL" \ + --arg author "$PR_AUTHOR" \ + --arg avatar "$PR_AUTHOR_AVATAR" \ + --arg merged_by "$MERGED_BY" \ + --arg branch "$HEAD_BRANCH" \ + --arg additions "$ADDITIONS" \ + --arg deletions "$DELETIONS" \ + '{ + username: "Merge Alarm 🚨", + allowed_mentions: { parse: [] }, + content: "πŸš¨πŸš¨πŸŽ‰πŸŽŠ **NOWY MERGE DO MAIN!** πŸŽŠπŸŽ‰πŸš¨πŸš¨\n✨πŸ₯³πŸΎ Leci na produkcjΔ™! 🍾πŸ₯³βœ¨", + embeds: [{ + title: ("#" + $number + " " + $title), + url: $url, + color: 16766720, + author: { name: $author, icon_url: $avatar }, + description: ("πŸŽ‰πŸŽŠ Brawo, **" + $author + "**! Kod juΕΌ na `main` πŸ”₯πŸš€βœ¨"), + fields: [ + { name: "🌿 Branch", value: ("`" + $branch + "`"), inline: true }, + { name: "βœ… ZmergowaΕ‚(a)", value: $merged_by, inline: true }, + { name: "πŸ“ˆ Zmiany", value: ("+" + $additions + " / -" + $deletions), inline: true } + ] + }] + }') + + curl --fail-with-body -sS \ + -H "Content-Type: application/json" \ + -d "$payload" \ + "$WEBHOOK" diff --git a/CMakeLists.txt b/CMakeLists.txt index 4956436..3e39042 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22) project(email_client LANGUAGES CXX - VERSION 1.0.0 + VERSION 2.1.0 ) set(CMAKE_CXX_STANDARD 20) diff --git a/aur/PKGBUILD b/aur/PKGBUILD index 12166da..6f1b734 100644 --- a/aur/PKGBUILD +++ b/aur/PKGBUILD @@ -1,8 +1,14 @@ # 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. + pkgname=email-client -pkgver=2.0.0 +pkgver=0.0.0 pkgrel=1 pkgdesc="A CLI email client for Arch Linux" arch=('x86_64') @@ -16,6 +22,7 @@ depends=( 'icu' 'gnutls' 'ncurses' + 'gpm' 'libffi' 'sqlite' 'libxml2' @@ -24,46 +31,25 @@ depends=( 'vmime' ) -# Build Dependencies +# Build Dependencies (git: CMake fetches the bundled libraries with it) makedepends=( - 'base-devel' 'cmake' - 'make' - 'gcc' 'git' 'pkgconf' ) -# Sources and Checksums -# WARN: PIN THESE BACK BEFORE PUSHING PKGBUILD TO AUR -# source=("https://github.com/Student-Team-Projects/Email-Client/archive/refs/tags/${pkgver}.tar.gz") -# sha256sums=('TODO!') - -source=("http://127.0.0.1:8000/${pkgver}.tar.gz") +source=("${pkgname}-${pkgver}.tar.gz::https://github.com/Student-Team-Projects/Email-Client/archive/refs/tags/${pkgver}.tar.gz") sha256sums=('SKIP') -prepare() { - cd "$srcdir" || exit 1 - tar xzvf "${pkgver}.tar.gz" -} - build() { - cd "$srcdir" || exit 1 - mkdir -p build - cd build || exit 1 - - cmake -DCMAKE_BUILD_TYPE=Release \ + cmake -S "Email-Client-${pkgver}" -B build \ + -DCMAKE_BUILD_TYPE=Release \ -DEXTERNAL_SQLITE=ON \ -DEXTERNAL_LIBXML2=ON \ - -DEXTERNAL_VMIME=ON .. - make + -DEXTERNAL_VMIME=ON + cmake --build build --parallel "$(nproc)" } package() { - cd "$srcdir/build" || exit 1 - - # Install the email client binary - install -Dm755 "email_client" "$pkgdir/usr/bin/email_client" - - # TODO: Consider adding manpages (e.g via scdoc ;) + install -Dm755 build/email_client "$pkgdir/usr/bin/email_client" }