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:
4 release: 4 release:
5 types: [published] 5 types: [published]
6 workflow_dispatch: 6 workflow_dispatch:
7 inputs:
8 tag_name:
9 description: 'Release tag name (e.g., v1.2.3)'
10 required: true
11 type: string
12 7
13permissions: 8permissions:
14 contents: read 9 contents: read
@@ -22,30 +17,50 @@ jobs:
22 - name: Install dependencies 17 - name: Install dependencies
23 run: | 18 run: |
24 sudo apt-get update 19 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
26 21
27 - name: Resolve release version and checksum 22 - name: Download release asset and compute SHA256
28 id: release 23 id: release
24 env:
25 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29 run: | 26 run: |
30 set -euo pipefail 27 set -euo pipefail
31 28
32 if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then 29 if [ "${{ github.event_name }}" = "release" ]; then
33 TAG_NAME="${{ github.event.inputs.tag_name }}"
34 else
35 TAG_NAME="${{ github.event.release.tag_name }}" 30 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
36 fi 50 fi
37 51
38 if [ -z "$TAG_NAME" ]; then 52 if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" = "null" ]; then
39 echo "Release tag is empty" 53 echo "Release ${TAG_NAME} does not contain asset: curd-linux-x86_64"
54 rm -f "$RELEASE_JSON"
40 exit 1 55 exit 1
41 fi 56 fi
42 57
43 VERSION="${TAG_NAME#v}" 58 VERSION="${TAG_NAME#v}"
44 ASSET_URL="https://github.com/Wraient/curd/releases/download/${TAG_NAME}/curd-linux-x86_64"
45
46 TMP_ASSET="$(mktemp)" 59 TMP_ASSET="$(mktemp)"
47 curl -fL --retry 3 --retry-all-errors --connect-timeout 20 "$ASSET_URL" -o "$TMP_ASSET" 60 curl -fL --retry 3 --retry-all-errors --connect-timeout 20 "$ASSET_URL" -o "$TMP_ASSET"
48 SHA256="$(sha256sum "$TMP_ASSET" | awk '{print $1}')" 61 SHA256="$(sha256sum "$TMP_ASSET" | awk '{print $1}')"
62
63 rm -f "$RELEASE_JSON"
49 rm -f "$TMP_ASSET" 64 rm -f "$TMP_ASSET"
50 65
51 echo "version=$VERSION" >> "$GITHUB_OUTPUT" 66 echo "version=$VERSION" >> "$GITHUB_OUTPUT"
@@ -54,35 +69,48 @@ jobs:
54 69
55 - name: Configure SSH for AUR 70 - name: Configure SSH for AUR
56 env: 71 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 }}
58 run: | 73 run: |
59 set -euo pipefail 74 set -euo pipefail
60 75
61 if [ -z "${AUR_SSH_PRIVATE_KEY:-}" ]; then 76 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"
63 exit 1 78 exit 1
64 fi 79 fi
65 80
66 install -m 700 -d ~/.ssh 81 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
68 84
69 if [ ! -s ~/.ssh/aur_deploy ]; then 85 if [ ! -s ~/.ssh/curd_aur_deploy ]; then
70 echo "SSH key file is empty after writing secret" 86 echo "SSH key file is empty after writing secret"
71 exit 1 87 exit 1
72 fi 88 fi
73 89
74 if ! ssh-keygen -y -f ~/.ssh/aur_deploy >/dev/null 2>&1; then 90 KEY_HEADER="$(head -n1 ~/.ssh/curd_aur_deploy || true)"
75 echo "Invalid SSH private key in secret (or key is passphrase-protected)" 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"
76 exit 1 102 exit 1
77 fi 103 fi
78 104
79 chmod 600 ~/.ssh/aur_deploy 105 chmod 600 ~/.ssh/curd_aur_deploy
106 chmod 644 ~/.ssh/curd_aur_deploy.pub
80 ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts 107 ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts
81 chmod 644 ~/.ssh/known_hosts 108 chmod 644 ~/.ssh/known_hosts
109 echo "Validated deploy key format. Add the matching public key to the AUR account SSH keys."
82 110
83 - name: Clone AUR repository 111 - name: Clone AUR repository
84 env: 112 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
86 run: | 114 run: |
87 set -euo pipefail 115 set -euo pipefail
88 git clone --depth 1 ssh://aur@aur.archlinux.org/curd.git aur-curd 116 git clone --depth 1 ssh://aur@aur.archlinux.org/curd.git aur-curd
@@ -102,7 +130,7 @@ jobs:
102 - name: Commit and push to AUR 130 - name: Commit and push to AUR
103 working-directory: aur-curd 131 working-directory: aur-curd
104 env: 132 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
106 run: | 134 run: |
107 set -euo pipefail 135 set -euo pipefail
108 136
@@ -121,4 +149,5 @@ jobs:
121 - name: Cleanup 149 - name: Cleanup
122 if: always() 150 if: always()
123 run: | 151 run: |
124 rm -f ~/.ssh/aur_deploy 152 rm -f ~/.ssh/curd_aur_deploy
153 rm -f ~/.ssh/curd_aur_deploy.pub