Commit 8b6c099ebb

8b6c099ebb46048057a41cf16cf07caf2985b490

parent: 73ba7bd488

Unsigned

Wraient <wraient.911@gmail.com> · 2026-04-18 16:34 UTC

ci: update ci/cd to update aur package on release

Layout: unified · split

.github/workflows/update-aur.yml +53 −24
@@ -4,11 +4,6 @@ on:
44 release:
55 types: [published]
66 workflow_dispatch:
7 inputs:
8 tag_name:
9 description: 'Release tag name (e.g., v1.2.3)'
10 required: true
11 type: string
127
138permissions:
149 contents: read
@@ -22,30 +17,50 @@ jobs:
2217 - name: Install dependencies
2318 run: |
2419 sudo apt-get update
25 sudo apt-get install -y curl git openssh-client makepkg
20 sudo apt-get install -y curl git jq openssh-client makepkg
2621
27 - name: Resolve release version and checksum
22 - name: Download release asset and compute SHA256
2823 id: release
24 env:
25 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2926 run: |
3027 set -euo pipefail
3128
32 if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
33 TAG_NAME="${{ github.event.inputs.tag_name }}"
34 else
29 if [ "${{ github.event_name }}" = "release" ]; then
3530 TAG_NAME="${{ github.event.release.tag_name }}"
31 RELEASE_API_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/${TAG_NAME}"
32 else
33 RELEASE_API_URL="https://api.github.com/repos/${{ github.repository }}/releases/latest"
34 fi
35
36 RELEASE_JSON="$(mktemp)"
37 curl -fsSL \
38 -H "Authorization: Bearer ${GH_TOKEN}" \
39 -H "Accept: application/vnd.github+json" \
40 "$RELEASE_API_URL" \
41 -o "$RELEASE_JSON"
42
43 TAG_NAME="$(jq -r '.tag_name // empty' "$RELEASE_JSON")"
44 ASSET_URL="$(jq -r '.assets[] | select(.name=="curd-linux-x86_64") | .browser_download_url' "$RELEASE_JSON" | head -n1)"
45
46 if [ -z "$TAG_NAME" ] || [ "$TAG_NAME" = "null" ]; then
47 echo "Could not resolve release tag from $RELEASE_API_URL"
48 rm -f "$RELEASE_JSON"
49 exit 1
3650 fi
3751
38 if [ -z "$TAG_NAME" ]; then
39 echo "Release tag is empty"
52 if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
53 echo "Release ${TAG_NAME} does not contain asset: curd-linux-x86_64"
54 rm -f "$RELEASE_JSON"
4055 exit 1
4156 fi
4257
4358 VERSION="${TAG_NAME#v}"
44 ASSET_URL="https://github.com/Wraient/curd/releases/download/${TAG_NAME}/curd-linux-x86_64"
45
4659 TMP_ASSET="$(mktemp)"
4760 curl -fL --retry 3 --retry-all-errors --connect-timeout 20 "$ASSET_URL" -o "$TMP_ASSET"
4861 SHA256="$(sha256sum "$TMP_ASSET" | awk '{print $1}')"
62
63 rm -f "$RELEASE_JSON"
4964 rm -f "$TMP_ASSET"
5065
5166 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
@@ -54,35 +69,48 @@ jobs:
5469
5570 - name: Configure SSH for AUR
5671 env:
57 AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY || secrets.AUR_SSH_KEY }}
72 AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
5873 run: |
5974 set -euo pipefail
6075
6176 if [ -z "${AUR_SSH_PRIVATE_KEY:-}" ]; then
62 echo "Missing secret: AUR_SSH_PRIVATE_KEY (or AUR_SSH_KEY)"
77 echo "Missing required secret: AUR_SSH_PRIVATE_KEY"
6378 exit 1
6479 fi
6580
6681 install -m 700 -d ~/.ssh
67 printf '%s\n' "$AUR_SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/aur_deploy
82 umask 077
83 printf '%s\n' "$AUR_SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/curd_aur_deploy
6884
69 if [ ! -s ~/.ssh/aur_deploy ]; then
85 if [ ! -s ~/.ssh/curd_aur_deploy ]; then
7086 echo "SSH key file is empty after writing secret"
7187 exit 1
7288 fi
7389
74 if ! ssh-keygen -y -f ~/.ssh/aur_deploy >/dev/null 2>&1; then
75 echo "Invalid SSH private key in secret (or key is passphrase-protected)"
90 KEY_HEADER="$(head -n1 ~/.ssh/curd_aur_deploy || true)"
91 case "$KEY_HEADER" in
92 "-----BEGIN OPENSSH PRIVATE KEY-----"|"-----BEGIN RSA PRIVATE KEY-----"|"-----BEGIN EC PRIVATE KEY-----"|"-----BEGIN DSA PRIVATE KEY-----"|"-----BEGIN PRIVATE KEY-----")
93 ;;
94 *)
95 echo "AUR_SSH_PRIVATE_KEY has an invalid private key header: $KEY_HEADER"
96 exit 1
97 ;;
98 esac
99
100 if ! ssh-keygen -y -f ~/.ssh/curd_aur_deploy > ~/.ssh/curd_aur_deploy.pub 2>/dev/null; then
101 echo "AUR_SSH_PRIVATE_KEY is not a valid, unencrypted SSH private key"
76102 exit 1
77103 fi
78104
79 chmod 600 ~/.ssh/aur_deploy
105 chmod 600 ~/.ssh/curd_aur_deploy
106 chmod 644 ~/.ssh/curd_aur_deploy.pub
80107 ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts
81108 chmod 644 ~/.ssh/known_hosts
109 echo "Validated deploy key format. Add the matching public key to the AUR account SSH keys."
82110
83111 - name: Clone AUR repository
84112 env:
85 GIT_SSH_COMMAND: ssh -i ~/.ssh/aur_deploy -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes
113 GIT_SSH_COMMAND: ssh -i ~/.ssh/curd_aur_deploy -o IdentitiesOnly=yes
86114 run: |
87115 set -euo pipefail
88116 git clone --depth 1 ssh://aur@aur.archlinux.org/curd.git aur-curd
@@ -102,7 +130,7 @@ jobs:
102130 - name: Commit and push to AUR
103131 working-directory: aur-curd
104132 env:
105 GIT_SSH_COMMAND: ssh -i ~/.ssh/aur_deploy -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes
133 GIT_SSH_COMMAND: ssh -i ~/.ssh/curd_aur_deploy -o IdentitiesOnly=yes
106134 run: |
107135 set -euo pipefail
108136
@@ -121,4 +149,5 @@ jobs:
121149 - name: Cleanup
122150 if: always()
123151 run: |
124 rm -f ~/.ssh/aur_deploy
152 rm -f ~/.ssh/curd_aur_deploy
153 rm -f ~/.ssh/curd_aur_deploy.pub