|
| 1 | +name: Publish AUR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + release_tag: |
| 7 | + description: "GitHub release tag to publish to AUR. Leave empty to use the latest release." |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + name: Publish gitmun-bin |
| 17 | + runs-on: ubuntu-22.04 |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Resolve release tag |
| 21 | + env: |
| 22 | + GH_TOKEN: ${{ github.token }} |
| 23 | + GH_REPO: ${{ github.repository }} |
| 24 | + INPUT_RELEASE_TAG: ${{ inputs.release_tag }} |
| 25 | + run: | |
| 26 | + set -euo pipefail |
| 27 | +
|
| 28 | + if [[ -n "${INPUT_RELEASE_TAG}" ]]; then |
| 29 | + RELEASE_TAG="${INPUT_RELEASE_TAG}" |
| 30 | + else |
| 31 | + RELEASE_TAG="$(gh release view --json tagName --jq '.tagName')" |
| 32 | + fi |
| 33 | +
|
| 34 | + if [[ -z "${RELEASE_TAG}" ]]; then |
| 35 | + echo "Could not resolve a release tag." >&2 |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | +
|
| 39 | + echo "RELEASE_TAG=${RELEASE_TAG}" >> "${GITHUB_ENV}" |
| 40 | + echo "Publishing AUR package from ${RELEASE_TAG}" |
| 41 | +
|
| 42 | + - name: Download AUR bundle |
| 43 | + env: |
| 44 | + GH_TOKEN: ${{ github.token }} |
| 45 | + GH_REPO: ${{ github.repository }} |
| 46 | + run: | |
| 47 | + set -euo pipefail |
| 48 | +
|
| 49 | + mkdir -p release-aur |
| 50 | + gh release download "${RELEASE_TAG}" \ |
| 51 | + --pattern 'gitmun-bin-aur-*.zip' \ |
| 52 | + --dir release-aur |
| 53 | +
|
| 54 | + mapfile -t bundles < <(find release-aur -maxdepth 1 -type f -name 'gitmun-bin-aur-*.zip' | sort) |
| 55 | + if [[ "${#bundles[@]}" -ne 1 ]]; then |
| 56 | + echo "Expected exactly one gitmun-bin AUR bundle, found ${#bundles[@]}." >&2 |
| 57 | + printf '%s\n' "${bundles[@]}" >&2 |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | +
|
| 61 | + echo "AUR_BUNDLE=${bundles[0]}" >> "${GITHUB_ENV}" |
| 62 | +
|
| 63 | + - name: Extract and validate AUR files |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | +
|
| 67 | + mkdir -p aur-files |
| 68 | + unzip -q "${AUR_BUNDLE}" -d aur-files |
| 69 | +
|
| 70 | + grep -qx "pkgname=gitmun-bin" aur-files/PKGBUILD |
| 71 | + grep -qx "pkgname = gitmun-bin" aur-files/.SRCINFO |
| 72 | +
|
| 73 | + expected_prefix="${{ github.server_url }}/${{ github.repository }}/releases/download/${RELEASE_TAG}" |
| 74 | + if ! grep -q "${expected_prefix}" aur-files/PKGBUILD; then |
| 75 | + echo "PKGBUILD source URL does not match ${expected_prefix}." >&2 |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + if ! grep -q "${expected_prefix}" aur-files/.SRCINFO; then |
| 79 | + echo ".SRCINFO source URL does not match ${expected_prefix}." >&2 |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Configure SSH |
| 84 | + env: |
| 85 | + AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }} |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | +
|
| 89 | + if [[ -z "${AUR_SSH_PRIVATE_KEY}" ]]; then |
| 90 | + echo "Missing AUR_SSH_PRIVATE_KEY secret." >&2 |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | +
|
| 94 | + mkdir -p "${HOME}/.ssh" |
| 95 | + chmod 700 "${HOME}/.ssh" |
| 96 | + printf '%s\n' "${AUR_SSH_PRIVATE_KEY}" > "${HOME}/.ssh/aur" |
| 97 | + chmod 600 "${HOME}/.ssh/aur" |
| 98 | + ssh-keyscan aur.archlinux.org >> "${HOME}/.ssh/known_hosts" |
| 99 | +
|
| 100 | + cat > "${HOME}/.ssh/config" <<'EOF' |
| 101 | + Host aur.archlinux.org |
| 102 | + User aur |
| 103 | + IdentityFile ~/.ssh/aur |
| 104 | + IdentitiesOnly yes |
| 105 | + StrictHostKeyChecking yes |
| 106 | + EOF |
| 107 | + chmod 600 "${HOME}/.ssh/config" |
| 108 | +
|
| 109 | + - name: Clone AUR repository |
| 110 | + run: git clone ssh://aur@aur.archlinux.org/gitmun-bin.git aur-repo |
| 111 | + |
| 112 | + - name: Update AUR repository |
| 113 | + run: | |
| 114 | + set -euo pipefail |
| 115 | +
|
| 116 | + cp aur-files/PKGBUILD \ |
| 117 | + aur-files/.SRCINFO \ |
| 118 | + aur-files/gitmun.install \ |
| 119 | + aur-files/LICENSE \ |
| 120 | + aur-files/LICENSE.gitmun \ |
| 121 | + aur-files/REUSE.toml \ |
| 122 | + aur-repo/ |
| 123 | +
|
| 124 | + cd aur-repo |
| 125 | + git config user.name "cst8t" |
| 126 | + git config user.email "actions@github.com" |
| 127 | +
|
| 128 | + git add PKGBUILD .SRCINFO gitmun.install LICENSE LICENSE.gitmun REUSE.toml |
| 129 | +
|
| 130 | + if git diff --cached --quiet --exit-code; then |
| 131 | + echo "AUR repository is already up to date." |
| 132 | + exit 0 |
| 133 | + fi |
| 134 | +
|
| 135 | + pkgver="$(sed -n 's/^pkgver=//p' PKGBUILD)" |
| 136 | + git commit -m "Update to ${pkgver}" |
| 137 | + git push origin HEAD:master |
0 commit comments