forked from xingguangcuican6666/ABK
-
Notifications
You must be signed in to change notification settings - Fork 0
368 lines (321 loc) · 13.5 KB
/
Copy pathget-manager.yml
File metadata and controls
368 lines (321 loc) · 13.5 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
name: GetManager
permissions:
contents: write # Allow writing to repository contents (for pushing tags)
actions: read # Allows triggering actions
on:
workflow_call: # This allows this workflow to be called from another workflow
inputs:
kernelsu_variant:
required: true
type: string
ksu_branch:
required: false
type: string
default: Stable(标准)
custom_ref:
required: false
type: string
outputs:
susVer:
description: "The fetched SUSFS version number"
value: ${{ jobs.get_ksu_manager.outputs.susVer }}
ksuVer:
description: "The calculated KSU version number"
value: ${{ jobs.get_ksu_manager.outputs.ksuVer }}
jobs:
get_ksu_manager:
if: inputs.kernelsu_variant != 'None'
runs-on: ubuntu-latest
outputs:
# 输出1: KSU版本号
ksuVer: ${{ steps.get_version.outputs.kversion }}
# 输出2: SUSFS版本号
susVer: ${{ steps.get_version.outputs.sversion }}
env:
CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
CCACHE_NOHASHDIR: "true"
CCACHE_HARDLINK: "true"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: 🧐 Debug Workflow Caller Context
run: |
echo "==================== DEBUG CONTEXT ===================="
echo " "
echo "EVENT NAME: ${{ github.event_name }}"
echo " "
echo "--- CALLER INFORMATION ---"
echo " - Caller Repository: ${{ github.caller_repository }}"
echo " - Caller Workflow: ${{ github.caller_workflow }}"
echo " - Caller User: ${{ github.triggering_actor }}"
echo " "
echo "--- WORKFLOW & JOB INFORMATION ---"
echo " - Current Workflow: ${{ github.workflow }}"
echo " - Current Job ID: ${{ github.job }}"
echo " - Current Run ID: ${{ github.run_id }}"
echo " - Current Run Number:${{ github.run_number }}"
echo " "
echo "--- GIT REFERENCE INFORMATION ---"
echo " - Git Ref: ${{ github.ref }}"
echo " - Ref Type: ${{ github.ref_type }}"
echo " "
echo "======================================================="
- name: 安装依赖
run: |
sudo apt-get update
sudo apt-get install -y git curl jq unzip
- uses: actions/checkout@v6
with:
sparse-checkout: |
.github/scripts
- name: 确定 KernelSU 分支
if: inputs.kernelsu_variant != 'None'
id: ksu-branch
env:
KSU_VARIANT: ${{ inputs.kernelsu_variant }}
KSU_BRANCH: ${{ inputs.ksu_branch }}
CUSTOM_REF: ${{ inputs.custom_ref }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: bash .github/scripts/resolve-ksu-ref.sh
- name: 获取 KSU & SUSFS 版本
id: get_version
run: |
if [ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]; then
echo "This is the SukiSU variant"
git clone https://github.com/SukiSU-Ultra/SukiSU-Ultra.git KernelSU
elif [ "${{ inputs.kernelsu_variant }}" == "ReSukiSU" ]; then
echo "This is the ReSukiSU variant"
git clone https://github.com/ReSukiSU/ReSukiSU.git KernelSU
elif [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then
echo "This is the Official"
git clone https://github.com/tiann/KernelSU.git KernelSU
else
echo "Unknown variant"
exit 1
fi
VAR=$([[ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]] && echo 700 || echo 200)
cd KernelSU
git fetch origin "$BRANCH"
git checkout "$BRANCH"
# 计算KSU版本号
KSU_GIT_VERSION=$(git rev-list --count HEAD)
if [ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]; then
KSU_VERSION=$((40000 + KSU_GIT_VERSION - 2815))
elif [ "${{ inputs.kernelsu_variant }}" == "ReSukiSU" ]; then
KSU_VERSION=$((30700 + KSU_GIT_VERSION))
elif [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then
KSU_VERSION=$((30000 + KSU_GIT_VERSION))
fi
echo $KSU_VERSION
echo "KSU_VERSION=$KSU_VERSION" >> $GITHUB_ENV
# 计算SUSFS版本号
INFO="https://gitlab.com/simonpunk/susfs4ksu/-/raw/gki-android14-6.1/ksu_module_susfs/module.prop\?ref_type\=heads"
SUS_VERSION=$(curl -s $INFO | awk -F '=' '$1 == "version" { print $2 }')
echo $SUS_VERSION
# 导出这两个值给release
echo "kversion=$KSU_VERSION" >> $GITHUB_OUTPUT
echo "sversion=$SUS_VERSION" >> $GITHUB_OUTPUT
- name: 添加 KernelSU
id: add_KSU
continue-on-error: true
run: |
set -euo pipefail
resolve_ref_to_sha() {
local repo="$1"
local ref="$2"
local sha=""
# 尝试当作 branch
sha="$(curl -fsSL \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${repo}/branches/${ref}" \
| jq -r '.commit.sha // empty')"
if [ -n "$sha" ]; then
echo "$sha"
return
fi
echo "::error::无法解析 $ref 为 SHA"
exit 1
}
download_tag_release_apk() {
local repo="$1"
local tag="$2"
local variant="$3"
local release_json apk_name apk_url
echo "从 $repo releases/${tag} 获取 $variant Manager APK..."
release_json="$(curl -fsSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${repo}/releases/tags/${tag}")"
apk_name="$(echo "$release_json" | jq -r '
(.assets | map(select(((.name | ascii_downcase) | endswith(".apk")) and ((.name | ascii_downcase) | contains("release")))) | .[0].name // empty) as $release_apk |
if $release_apk != "" then $release_apk
else (.assets | map(select((.name | ascii_downcase) | endswith(".apk"))) | .[0].name // empty)
end
')"
apk_url="$(echo "$release_json" | jq -r --arg name "$apk_name" '.assets[] | select(.name == $name) | .browser_download_url')"
if [ -z "$apk_name" ] || [ -z "$apk_url" ]; then
echo "::error::${repo} ${tag} release 中未找到 APK 资源"
echo "$release_json" | jq -r '.assets[]?.name'
exit 1
fi
mkdir -p "manager-artifacts/${variant}"
echo "下载 $apk_name"
curl -fL -o "manager-artifacts/${variant}/${apk_name}" "$apk_url"
}
download_manager_for_repo() {
local repo="$1"
local variant="$2"
local sha="$BRANCH"
if ! [[ "$sha" =~ ^[A-Fa-f0-9]{40}$ ]]; then
sha="$(resolve_ref_to_sha "$repo" "$sha")"
BRANCH="$sha"
fi
echo "→ Download manager for ${repo} at head_sha=${sha}"
GITHUB_REPOSITORY="${{ github.repository }}" \
GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
bash .github/scripts/download-manager-from-actions.sh \
"$repo" "$sha" "manager-artifacts/${variant}"
}
case "${{ inputs.kernelsu_variant }}" in
"Official")
if [[ "$BRANCH" =~ ^[Vv]?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
download_tag_release_apk "tiann/KernelSU" "$BRANCH" "Official"
else
download_manager_for_repo "tiann/KernelSU" "Official"
fi
;;
"SukiSU")
if [[ "$BRANCH" =~ ^[Vv]?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
download_tag_release_apk "SukiSU-Ultra/SukiSU-Ultra" "$BRANCH" "SukiSU"
else
download_manager_for_repo "SukiSU-Ultra/SukiSU-Ultra" "SukiSU"
fi
;;
"ReSukiSU")
# ReSukiSU has no release APKs; Actions build-manager (fallback to main latest in script).
download_manager_for_repo "ReSukiSU/ReSukiSU" "ReSukiSU"
;;
*)
echo "::error::未知 KernelSU 变体: ${{ inputs.kernelsu_variant }}"
exit 1
;;
esac
if ! find manager-artifacts -type f -name '*.apk' -print -quit | grep -q .; then
echo "::error::未下载到任何 Manager APK"
find manager-artifacts -maxdepth 3 -type f -print || true
exit 1
fi
- name: 添加 SUSFS 模块
id: add_SUSFS
continue-on-error: true
run: |
BUILD_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/sidex15/susfs4ksu-module/actions/workflows/build.yml/runs?status=success" |
jq -r '.workflow_runs[0].id')
ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/sidex15/susfs4ksu-module/actions/runs/$BUILD_ID/artifacts")
DOWNLOAD_URL=$(echo "$ARTIFACTS" | jq -r '.artifacts[0].archive_download_url')
NAME=$(echo "$ARTIFACTS" | jq -r '.artifacts[0].name')
echo "SUSFS_NAME=$NAME" >> $GITHUB_ENV
NAME="susfs-$NAME.zip"
echo $DOWNLOAD_URL
echo $NAME
# 下载 Manager 文件
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o "$NAME" "$DOWNLOAD_URL"
echo "$NAME 文件已下载.zip"
# 解压 artifact zip 获取里面的模块文件
mkdir -p susfs-module
unzip "$NAME" -d susfs-temp
# 检查解压后的内容:如果是散装文件则打包成 zip
cd susfs-temp
if ls *.zip 1>/dev/null 2>&1; then
# 里面已经是 zip 文件,直接移动
mv *.zip ../susfs-module/
else
# 是散装文件,打包成 zip
zip -r "../susfs-module/ksu_module_susfs.zip" .
fi
cd ..
rm -rf susfs-temp "$NAME"
- name: Notify on failure
if: steps.add_KSU.outcome == 'failure'
run: echo "下载CI构建的KSU失败!"
- name: 上传APK
if: steps.add_KSU.outcome == 'success'
uses: actions/upload-artifact@v6
with:
name: ${{ inputs.kernelsu_variant }}-Manager(${{ env.KSU_VERSION }})
path: |
**/*.apk
- name: 上传SUSFS模块
if: steps.add_SUSFS.outcome == 'success'
uses: actions/upload-artifact@v6
with:
name: susfs-${{ env.SUSFS_NAME }}
path: ./susfs-module/*
upload_other_modules:
if: ${{ inputs.use_ntsync || inputs.use_networking }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 合并启用功能的模块
run: |
echo "=== 开始合并扩展模块 ==="
ls -la modules/ || echo "modules 目录不存在"
ENABLE_FEATURES=()
if [ "${{ inputs.use_networking }}" = "true" ]; then
ENABLE_FEATURES+=("ipset")
fi
if [ "${{ inputs.use_ntsync }}" = "true" ]; then
ENABLE_FEATURES+=("ntsync")
fi
echo "当前启用功能: ${ENABLE_FEATURES[*]}"
PROP="modules/main/module.prop"
cat > "$PROP" << EOF
id=abk_extension
name=ABK-Extension
version=1.2.0
versionCode=10020
EOF
AUTHORS=""
DESC=""
for feature in "${ENABLE_FEATURES[@]}"; do
if [ -f "modules/$feature/module.prop" ]; then
A=$(grep '^author=' "modules/$feature/module.prop" | cut -d'=' -f2- | sed 's/^[[:space:]]*//')
D=$(grep '^description=' "modules/$feature/module.prop" | cut -d'=' -f2- | sed 's/^[[:space:]]*//')
[ -n "$A" ] && AUTHORS="${AUTHORS}${A}, "
[ -n "$D" ] && DESC="${DESC}${D}; "
fi
done
[ -n "$AUTHORS" ] && echo "author=${AUTHORS%, }" >> "$PROP"
[ -n "$DESC" ] && echo "description=${DESC%; }" >> "$PROP"
echo "module.prop 合并完成"
for feature in "${ENABLE_FEATURES[@]}"; do
[ -d "modules/$feature" ] || continue
echo "正在合并模块: $feature"
find "modules/$feature" -type f ! -name "module.prop" | while read -r src; do
rel="${src#modules/$feature/}"
dst="modules/main/$rel"
mkdir -p "$(dirname "$dst")"
if [ ! -f "$dst" ]; then
cp -a "$src" "$dst"
echo " 复制: $feature/$rel"
else
echo " 追加: $feature/$rel"
echo "" >> "$dst"
echo "# ========== 来自 $feature ==========" >> "$dst"
cat "$src" >> "$dst"
fi
done
done
echo "=== 合并完成 ==="
echo "最终 modules/main 内容:"
ls -R modules/main/
- name: 上传扩展模块
uses: actions/upload-artifact@v6
with:
name: abk_extension
path: modules/main/*
if-no-files-found: error