Repository navigation
feat(ci): publish stable releases to the AUR as cap-bin #3160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Wraient
wants to merge
20
commits into
CapSoftware:main
Choose a base branch
from
Wraient:feat/aur-publish
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+204
−7
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
045d6c5
feat(ci): publish stable releases to the AUR as cap-bin
Wraient ffc34f8
fix(ci): bump pkgrel when the AUR recipe changes for the same release
Wraient 8b2e5ee
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient 7ff42ba
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient c6a5c1e
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient e28542d
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient ffcaa68
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient 1955c49
fix(ci): validate AUR pkgrel as a plain integer before shell arithmetic
Wraient cc1a107
Merge remote-tracking branch 'origin/main' into HEAD
Wraient e409909
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient 5bd0775
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient b94a80b
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient d3cec7a
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient fe94454
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient 7f9438d
Merge remote-tracking branch 'origin/main' into HEAD
Wraient 14dd970
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient 06132c7
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient 8b66dd9
Merge origin/main into feat/aur-publish
Wraient d9ac6ae
Merge remote-tracking branch 'origin/main' into feat/aur-publish
Wraient 072b2d8
Merge origin/main into feat/aur-publish
Wraient File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| name: "publish-aur" | ||
|
|
||
| # Publishes each stable release to the AUR as cap-bin. The PKGBUILD is the one | ||
| # scripts/build-linux-arch-package.sh builds the release's own pacman package | ||
| # from, pointed at the release's CrabNebula deb, so the two stay identical. | ||
| # | ||
| # Release events run this file from the tagged commit; for a tag that predates | ||
| # it, dispatch it from main with that tag. Pushing needs the AUR_SSH_PRIVATE_KEY | ||
| # secret of an AUR account that maintains cap-bin. Without it the job still | ||
| # builds the package and uploads the PKGBUILD as an artifact. | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag: | ||
| description: "Published stable release tag, e.g. cap-v0.6.1" | ||
| required: true | ||
| type: string | ||
|
|
||
| concurrency: | ||
| group: publish-aur | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| aur: | ||
| if: ${{ github.event_name == 'workflow_dispatch' || (startsWith(github.event.release.tag_name, 'cap-v') && !github.event.release.prerelease) }} | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 30 | ||
| env: | ||
| TAG: ${{ inputs.tag || github.event.release.tag_name }} | ||
| ARCH_IMAGE: archlinux:base-devel@sha256:68bfc3b0d277b08a99101dc9b94aaa03e5ae70cf1b4fb965c03b2b87b915760d | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Resolve release deb | ||
| id: release | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| set -euo pipefail | ||
| VERSION="${TAG#cap-v}" | ||
| if [[ "$TAG" != cap-v* || ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo "::error::'$TAG' is not a stable cap-v{x.y.z} release tag." | ||
| exit 1 | ||
| fi | ||
| RELEASE="$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isDraft,isPrerelease,body)" | ||
| if [[ "$(jq -r '.isDraft or .isPrerelease' <<< "$RELEASE")" != false ]]; then | ||
| echo "::error::$TAG is not a published stable release." | ||
| exit 1 | ||
| fi | ||
| DEB_URL="$(jq -r '.body | capture("<!--\\s*DOWNLOADS_JSON\\s*(?<downloads>\\{[^}]+\\})\\s*-->").downloads | fromjson | .["linux-deb"] // empty' <<< "$RELEASE")" | ||
| if [[ ! "$DEB_URL" =~ ^https://cdn\.crabnebula\.app/asset/[0-9A-Za-z]+$ ]]; then | ||
| echo "::error::$TAG has no CrabNebula linux-deb link in its DOWNLOADS_JSON." | ||
| exit 1 | ||
| fi | ||
| { | ||
| echo "version=$VERSION" | ||
| echo "deb_url=$DEB_URL" | ||
| } >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Build AUR package | ||
| shell: bash | ||
| env: | ||
| DEB_URL: ${{ steps.release.outputs.deb_url }} | ||
| VERSION: ${{ steps.release.outputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p "$RUNNER_TEMP/deb" "$RUNNER_TEMP/aur-package" | ||
| curl -fsSL --retry 5 --retry-all-errors -o "$RUNNER_TEMP/deb/Cap.deb" "$DEB_URL" | ||
| docker run --rm --network none \ | ||
| --env CAP_PACKAGE_UID="$(id -u)" \ | ||
| --volume "$GITHUB_WORKSPACE:/source:ro" \ | ||
| --volume "$RUNNER_TEMP/deb:/input:ro" \ | ||
| --volume "$RUNNER_TEMP/aur-package:/output" \ | ||
| "$ARCH_IMAGE" \ | ||
| bash -c 'useradd --uid "$CAP_PACKAGE_UID" --create-home cap-package && runuser -u cap-package -- bash /source/scripts/build-linux-arch-package.sh /input/Cap.deb /output "$1"' \ | ||
| bash "$DEB_URL" | ||
| PKGVER="$(awk -F ' = ' '$1 == "\tpkgver" { print $2 }' "$RUNNER_TEMP/aur-package/.SRCINFO")" | ||
| if [[ "$PKGVER" != "$VERSION" ]]; then | ||
| echo "::error::The linux-deb link holds Cap $PKGVER, not $VERSION." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Upload AUR package files | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: aur-cap-bin-${{ steps.release.outputs.version }} | ||
| path: | | ||
| ${{ runner.temp }}/aur-package/PKGBUILD | ||
| ${{ runner.temp }}/aur-package/.SRCINFO | ||
| include-hidden-files: true | ||
| overwrite: true | ||
| if-no-files-found: error | ||
|
|
||
| - name: Push to the AUR | ||
| shell: bash | ||
| env: | ||
| AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }} | ||
| VERSION: ${{ steps.release.outputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ -z "$AUR_SSH_PRIVATE_KEY" ]]; then | ||
| echo "::warning::AUR_SSH_PRIVATE_KEY is not set, so cap-bin $VERSION was built but not pushed to the AUR." | ||
| exit 0 | ||
| fi | ||
| install -d -m 700 "$HOME/.ssh" | ||
| printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > "$HOME/.ssh/aur" | ||
| chmod 600 "$HOME/.ssh/aur" | ||
| echo "aur.archlinux.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuBKrPzbawxA/k2g6NcyV5jmqwJ2s+zpgZGZ7tpLIcN" > "$HOME/.ssh/known_hosts" | ||
| export GIT_SSH_COMMAND="ssh -i $HOME/.ssh/aur -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes" | ||
| PACKAGE="$RUNNER_TEMP/aur-package" | ||
| PKGBASE="$(awk -F ' = ' '$1 == "pkgbase" { print $2 }' "$PACKAGE/.SRCINFO")" | ||
| AUR="$RUNNER_TEMP/aur" | ||
| git -c init.defaultBranch=master clone "ssh://aur@aur.archlinux.org/$PKGBASE.git" "$AUR" | ||
| version_of() { | ||
| awk -F ' = ' '$1 == "\tepoch" { epoch = $2 ":" } $1 == "\tpkgver" { pkgver = $2 } $1 == "\tpkgrel" { pkgrel = $2 } END { print epoch pkgver "-" pkgrel }' "$1" | ||
| } | ||
| upstream_of() { | ||
| awk -F ' = ' '$1 == "\tepoch" { epoch = $2 ":" } $1 == "\tpkgver" { pkgver = $2 } END { print epoch pkgver }' "$1" | ||
| } | ||
| pkgrel_of() { | ||
| awk -F ' = ' '$1 == "\tpkgrel" { print $2 }' "$1" | ||
| } | ||
| if [[ -f "$AUR/.SRCINFO" ]]; then | ||
| CURRENT="$(version_of "$AUR/.SRCINFO")" | ||
| NEW="$(version_of "$PACKAGE/.SRCINFO")" | ||
| if (( $(docker run --rm --network none "$ARCH_IMAGE" vercmp "$NEW" "$CURRENT") < 0 )); then | ||
| echo "::notice::The AUR already has $PKGBASE $CURRENT, which is newer than $NEW." | ||
| exit 0 | ||
| fi | ||
| if [[ "$(upstream_of "$AUR/.SRCINFO")" == "$(upstream_of "$PACKAGE/.SRCINFO")" ]] && | ||
| ! cmp -s "$AUR/PKGBUILD" "$PACKAGE/PKGBUILD"; then | ||
| # Same upstream version but a changed recipe: installed users | ||
| # only upgrade on a higher pkgrel, so carry the AUR's forward. | ||
| # The AUR clone is not Cap-controlled, so never let its pkgrel | ||
| # reach shell arithmetic unvalidated: bash re-evaluates command | ||
| # substitutions inside $(( )), which would run attacker-chosen | ||
| # commands with AUR_SSH_PRIVATE_KEY in scope. Fail closed. | ||
| AUR_PKGREL="$(pkgrel_of "$AUR/.SRCINFO")" | ||
| if ! [[ "$AUR_PKGREL" =~ ^[0-9]+$ ]]; then | ||
| echo "::error::Refusing to publish: AUR .SRCINFO has non-numeric pkgrel: $AUR_PKGREL" >&2 | ||
| exit 1 | ||
| fi | ||
| NEW_PKGREL=$(( AUR_PKGREL + 1 )) | ||
| sed -i "s/^pkgrel=.*/pkgrel=$NEW_PKGREL/" "$PACKAGE/PKGBUILD" | ||
| sed -i "s/^\(\tpkgrel = \).*/\1$NEW_PKGREL/" "$PACKAGE/.SRCINFO" | ||
| echo "::notice::Recipe changed for $PKGBASE $VERSION, publishing as pkgrel $NEW_PKGREL." | ||
| fi | ||
| fi | ||
| cp "$PACKAGE/PKGBUILD" "$PACKAGE/.SRCINFO" "$AUR/" | ||
| cd "$AUR" | ||
| git add PKGBUILD .SRCINFO | ||
| if git diff --cached --quiet; then | ||
| echo "The AUR already has $PKGBASE $VERSION." | ||
| exit 0 | ||
| fi | ||
| git -c user.name="github-actions[bot]" -c user.email="41898282+github-actions[bot]@users.noreply.github.com" commit -m "Update to $(version_of .SRCINFO)" | ||
| git push origin HEAD:master | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-running
publish-aurafter changing the recipe can push different files with the same package version. The builder always writespkgrel=1, and this step allows equal versions whenever the files differ. For example, correctingdependsand dispatching the same release tag updates the AUR recipe, but installed users see no newer version to upgrade to.Increment
pkgrelfor same-release package changes, or reject changed recipes with an unchanged package version.Prompt To Fix With AI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ffc34f8. When the AUR already carries the same upstream version and the generated PKGBUILD differs, the push step now carries the AUR pkgrel forward by one in both the PKGBUILD and .SRCINFO before pushing, so a recipe-only change reaches installed users as an upgrade. Verified against a local bare repo standing in for the AUR: changed recipe at the same version publishes as 0.6.1-2, an identical re-run does nothing, a newer version still publishes at pkgrel 1, and an older version is still skipped.