-
Notifications
You must be signed in to change notification settings - Fork 5
86 lines (70 loc) · 3.33 KB
/
publish_version.yml
File metadata and controls
86 lines (70 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Update Version JSON
on:
release:
types: [published]
permissions:
contents: write
jobs:
deploy-version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate version.json with Changelog
env:
TAG_NAME: ${{ github.event.release.tag_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_BODY: ${{ github.event.release.body }}
run: |
VERSION=${TAG_NAME#v}
DATE=$(date +'%Y-%m-%d')
mkdir -p public
# 1. Get all assets in JSON
ASSETS=$(gh release view "$TAG_NAME" --json assets -q '.assets')
# 2. Identify ARM64 asset (Case-Insensitive)
URL_ARM64=$(echo "$ASSETS" | jq -r 'map(select(.name | ascii_downcase | contains("arm64"))) | .[0].url // ""')
NAME_ARM64=$(echo "$ASSETS" | jq -r 'map(select(.name | ascii_downcase | contains("arm64"))) | .[0].name // ""')
# 3. Identify X64 asset (Case-Insensitive)
URL_X64=$(echo "$ASSETS" | jq -r 'map(select(.name | ascii_downcase | (contains("x64") or contains("amd64")))) | .[0].url // ""')
NAME_X64=$(echo "$ASSETS" | jq -r 'map(select(.name | ascii_downcase | (contains("x64") or contains("amd64")))) | .[0].name // ""')
# If no explicit x64 found, take the first .zip/exe that isn't ARM64
if [ -z "$URL_X64" ]; then
URL_X64=$(echo "$ASSETS" | jq -r 'map(select((.name | ascii_downcase | contains("arm64") | not) and (.name | test("\\.(zip|exe)$"; "i")))) | .[0].url // ""')
NAME_X64=$(echo "$ASSETS" | jq -r 'map(select((.name | ascii_downcase | contains("arm64") | not) and (.name | test("\\.(zip|exe)$"; "i")))) | .[0].name // ""')
fi
SHA_X64=""
SHA_ARM64=""
# Download and Hash X64
if [ -n "$NAME_X64" ]; then
gh release download "$TAG_NAME" -p "$NAME_X64" -O x64_pkg
SHA_X64=$(sha256sum x64_pkg | awk '{print $1}')
fi
# Download and Hash ARM64
if [ -n "$NAME_ARM64" ]; then
gh release download "$TAG_NAME" -p "$NAME_ARM64" -O arm64_pkg
SHA_ARM64=$(sha256sum arm64_pkg | awk '{print $1}')
fi
# Fallback URL for legacy clients (pointing to X64)
URL=$URL_X64
jq -n \
--arg v "$VERSION" \
--arg u "$URL" \
--arg u_x64 "$URL_X64" \
--arg u_arm "$URL_ARM64" \
--arg sha_x64 "$SHA_X64" \
--arg sha_arm "$SHA_ARM64" \
--arg d "$DATE" \
--arg c "$RELEASE_BODY" \
'{version: $v, url: $u, url_x64: $u_x64, url_arm64: $u_arm, sha256_x64: $sha_x64, sha256_arm64: $sha_arm, date: $d, changelog: $c}' \
> public/version.json
echo "=== Generated JSON Content ==="
cat public/version.json
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
force_orphan: false
keep_files: true
publish_branch: gh-pages
commit_message: "Auto-update version.json to ${{ github.event.release.tag_name }}"