-
Notifications
You must be signed in to change notification settings - Fork 2
296 lines (268 loc) · 10.8 KB
/
Copy pathbuild.yml
File metadata and controls
296 lines (268 loc) · 10.8 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: Build Sub-Store module
on:
workflow_dispatch:
inputs:
abi:
description: '目标 ABI (all=全部 4 架构)'
default: all
type: choice
options: [all, arm64-v8a, armeabi-v7a, x86_64, x86]
version:
description: 基础版本号 (留空则取 git tag, 如 v1.0.0)
default: ''
node-version:
description: '内置 node 版本 (留空取最新 LTS, 如 22.14.0)'
default: 'lts'
push:
branches: ['dev'] # dev 推送 → canary 构建
tags: ['v*']
permissions:
contents: write
jobs:
metadata:
runs-on: ubuntu-latest
outputs:
abi-matrix: ${{ steps.meta.outputs.abi-matrix }}
version: ${{ steps.meta.outputs.version }}
build-type: ${{ steps.meta.outputs.build-type }}
is-tag: ${{ steps.meta.outputs.is-tag }}
is-prerelease: ${{ steps.meta.outputs.is-prerelease }}
publish-update-json: ${{ steps.meta.outputs.publish-update-json }}
steps:
- id: meta
shell: bash
run: |
if [ "${{ inputs.abi || 'all' }}" = "all" ]; then
echo 'abi-matrix=["arm64-v8a","armeabi-v7a","x86_64","x86"]' >> "$GITHUB_OUTPUT"
else
printf 'abi-matrix=["%s"]\n' "${{ inputs.abi }}" >> "$GITHUB_OUTPUT"
fi
tag="${GITHUB_REF_NAME:-}"
version="${{ inputs.version }}"
if [ -z "$version" ] && [[ "$GITHUB_REF" == refs/tags/v* ]]; then
version="$tag" # 发布构建: 用 tag 名
fi
# canary (main 推送/手动) 未指定版本时留空 → build.sh git describe 取最近 tag
echo "version=$version" >> "$GITHUB_OUTPUT"
is_tag=false
is_prerelease=false
publish_update_json=false
build_type=release
# 手动运行或 main/dev 推送视为 canary 构建; hotfix 属于稳定版修订,alpha/beta/rc 才算预发布。
if [ "${{ github.event_name }}" = "workflow_dispatch" ] \
|| [ "${{ github.ref }}" = "refs/heads/main" ] \
|| [ "${{ github.ref }}" = "refs/heads/dev" ]; then
build_type=canary
elif [[ "$version" =~ -(alpha|beta|rc)([.-]|$) ]]; then
is_prerelease=true
build_type=prerelease
elif [[ "$version" == *-hotfix* ]]; then
build_type=hotfix
fi
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
is_tag=true
# SemVer prerelease tags look like v1.2.3-alpha.1. GitHub release
# gets marked prerelease, and gh-pages update JSON stays on stable.
if [ "$is_prerelease" = "false" ]; then
publish_update_json=true
fi
fi
echo "is-tag=$is_tag" >> "$GITHUB_OUTPUT"
echo "is-prerelease=$is_prerelease" >> "$GITHUB_OUTPUT"
echo "publish-update-json=$publish_update_json" >> "$GITHUB_OUTPUT"
echo "build-type=$build_type" >> "$GITHUB_OUTPUT"
webui:
needs: metadata
runs-on: ubuntu-latest
steps:
- name: Checkout WebUI repo
uses: actions/checkout@v7
with:
repository: Delusions6515/Sub-Store-Module-WebUI
path: Sub-Store-Module-WebUI
- name: WebUI commit hash
id: webui-hash
run: echo "hash=$(git -C Sub-Store-Module-WebUI rev-parse HEAD)" >> "$GITHUB_OUTPUT"
# dist 按 WebUI commit hash 缓存 (4 架构共享一份), hash 不变直接复用, 跳过 pnpm install + build
- name: Cache WebUI dist
id: webui-cache
uses: actions/cache@v6
with:
path: Sub-Store-Module-WebUI/dist
key: webui-dist-${{ steps.webui-hash.outputs.hash }}
- name: Setup pnpm
if: steps.webui-cache.outputs.cache-hit != 'true'
uses: pnpm/action-setup@v6
with:
version: 11.3.0
- name: Setup Node.js
if: steps.webui-cache.outputs.cache-hit != 'true'
uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
cache-dependency-path: Sub-Store-Module-WebUI/pnpm-lock.yaml
- name: Build WebUI
if: steps.webui-cache.outputs.cache-hit != 'true'
run: |
cd Sub-Store-Module-WebUI
pnpm install --frozen-lockfile
pnpm build
ls -lh dist/
- name: Upload WebUI artifact
uses: actions/upload-artifact@v7
with:
name: sub-store-webui-dist
path: Sub-Store-Module-WebUI/dist
if-no-files-found: error
build:
needs: [metadata, webui]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
abi: ${{ fromJSON(needs.metadata.outputs.abi-matrix) }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # 完整历史: versionCode 取 git 提交数 (ZygiskNext 风格)
- name: Download WebUI artifact
uses: actions/download-artifact@v8
with:
name: sub-store-webui-dist
path: webui-dist
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y zip unzip xz-utils
# 组件缓存 (bin/ 由 build.sh 自动补齐); 键含 ABI 与 ref, 新 tag 自动刷新,
# 强制刷新可删除 Actions 缓存 (Caches 页) 或清空 bin/ 后重跑。
- name: Cache bin/
uses: actions/cache@v6
with:
path: bin
key: components-${{ runner.os }}-${{ matrix.abi }}
- name: Build module
env:
TARGET_ABI: ${{ matrix.abi }}
BUILD_TYPE: ${{ needs.metadata.outputs.build-type }}
WEBUI_DIST_DIR: ${{ github.workspace }}/webui-dist
NODE_VERSION: ${{ inputs.node-version }}
run: |
./build.sh "${{ needs.metadata.outputs.version }}"
ls -lh build/*.zip
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: sub-store-module-${{ matrix.abi }}
path: build/*.zip
if-no-files-found: error
release:
needs: [metadata, build]
if: needs.metadata.outputs.is-tag == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Generate release notes
env:
TAG: ${{ github.ref_name }}
BUILD_TYPE: ${{ needs.metadata.outputs.build-type }}
run: |
args=(--tag "$TAG" --build-type "$BUILD_TYPE")
[ "$BUILD_TYPE" = "release" ] && args+=(--stable-only)
{
python3 gen-changelog.py "${args[@]}"
printf '\n构建记录: %s/%s/actions/runs/%s\n' \
"${{ github.server_url }}" "${{ github.repository }}" "${{ github.run_id }}"
} > release-notes.md
cat release-notes.md
- name: Create or update release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
PRERELEASE: ${{ needs.metadata.outputs.is-prerelease }}
run: |
args=(--title "Sub-Store for Android $TAG")
[ "$PRERELEASE" = "true" ] && args+=(--prerelease --latest=false)
if gh release view "$TAG" >/dev/null 2>&1; then
gh release view "$TAG" --json body --jq .body > current-release-notes.md
awk '
BEGIN {
while ((getline line < "release-notes.md") > 0) replacement = replacement line ORS
close("release-notes.md")
}
!seen++ && $0 !~ /^##[[:space:]]+What.s Changed[[:space:]]*$/ { printf "%s\n", replacement }
/^##[[:space:]]+What.s Changed[[:space:]]*$/ {
if (!found) printf "%s", replacement
found = 1
in_changed = 1
next
}
in_changed && /^##[[:space:]]/ { in_changed = 0 }
!in_changed { print }
END { if (!seen) printf "%s", replacement }
' current-release-notes.md > merged-release-notes.md
gh release edit "$TAG" "${args[@]}" --notes-file merged-release-notes.md
else
gh release create "$TAG" "${args[@]}" --notes-file release-notes.md
fi
gh release upload "$TAG" dist/*.zip --clobber
# 发布 update JSON (各架构分开), 供管理器检测稳定版更新
# module.prop 的 updateJson 指向 gh-pages 分支上的 update-<abi>.json
update-json:
needs: [metadata, release]
if: needs.metadata.outputs.publish-update-json == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Generate update JSON (各架构分开) + CHANGELOG.md
env:
TAG: ${{ github.ref_name }}
BUILD_TYPE: ${{ needs.metadata.outputs.build-type }}
run: |
VER="${TAG#v}" # version 不带 v, 与 module.prop 保持一致
CODE=$(git rev-list HEAD --count)
SHA=$(git rev-parse --short HEAD)
# 生成到独立目录 json-out/, 避免与后续 gh-pages checkout 的 untracked 文件冲突
mkdir -p json-out
for abi in arm64-v8a armeabi-v7a x86_64 x86; do
# zipUrl 文件名里的构建类型与 release 资产的命名对齐 (release/hotfix)
ZIP="sub-store-module-${VER}-${CODE}-${SHA}-${BUILD_TYPE}-${abi}.zip"
cat > "json-out/update-${abi}.json" <<JSON
{
"version": "$VER",
"versionCode": $CODE,
"zipUrl": "https://github.com/Delusions6515/Sub-Store-Module/releases/download/$TAG/$ZIP",
"changelog": "https://raw.githubusercontent.com/Delusions6515/Sub-Store-Module/gh-pages/CHANGELOG.md"
}
JSON
done
# CHANGELOG.md: 最近 4 个版本 (稳定/hotfix 计数, 排除 alpha/beta/rc)
python3 gen-changelog.py --stable-only --with-hotfix > json-out/CHANGELOG.md
ls -l json-out/
- name: Publish to gh-pages branch
env:
TAG: ${{ github.ref_name }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git fetch origin gh-pages:gh-pages 2>/dev/null; then
git checkout gh-pages
else
# 首次: gh-pages 不存在, 用 orphan 分支创建 (清空索引只提交 JSON)
git checkout --orphan gh-pages
git rm -rf --cached . >/dev/null 2>&1 || git rm -rf . >/dev/null 2>&1 || true
fi
cp json-out/update-*.json json-out/CHANGELOG.md .
git add update-*.json CHANGELOG.md
if git commit -m "update json + changelog: $TAG"; then
git push origin gh-pages
else
echo "update json 无变化, 跳过推送"
fi