Skip to content

Commit 0da3355

Browse files
committed
build: implement versioning system
set target tag of dependency in `version.properties`, 'latest' is accepted.
1 parent 118522f commit 0da3355

3 files changed

Lines changed: 67 additions & 18 deletions

File tree

.github/workflows/build.yaml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,33 @@ jobs:
2424
with:
2525
fetch-depth: 1
2626

27-
- name: download kpatch-next binaries (latest release)
27+
- name: Load versions from version.properties
28+
run: |
29+
grep -v '^#' version.properties | sed -e 's/ *= */=/g' -e 's/"//g' >> $GITHUB_ENV
30+
31+
- name: download kpatch-next binaries
2832
run: |
2933
mkdir -p module/bin
30-
gh release download -R KernelSU-Next/KPatch-Next -p "kpatch-android" -p "kptools-android" -p "kpimg-linux" -D module/bin
34+
TAG="${{ env['kpatch-next'] }}"
35+
ARGS=("-R" "KernelSU-Next/KPatch-Next" "-p" "kpatch-android" "-p" "kptools-android" "-p" "kpimg-linux" "-D" "module/bin")
36+
if [ "$TAG" != "latest" ]; then
37+
gh release download "$TAG" "${ARGS[@]}"
38+
else
39+
gh release download "${ARGS[@]}"
40+
fi
3141
mv module/bin/kpatch-android module/bin/kpatch
3242
mv module/bin/kptools-android module/bin/kptools
3343
mv module/bin/kpimg-linux module/bin/kpimg
3444
3545
- name: Download magiskboot binary
3646
run: |
37-
TAG=$(gh release list -R topjohnwu/Magisk -L 1 --json tagName --jq '.[0].tagName')
38-
gh release download "$TAG" -R topjohnwu/Magisk -p "Magisk*.apk" -O magisk.apk
47+
TAG="${{ env.magiskboot }}"
48+
ARGS=("-R" "topjohnwu/Magisk" "-p" "Magisk*.apk" "-O" "magisk.apk")
49+
if [ "$TAG" != "latest" ]; then
50+
gh release download "$TAG" "${ARGS[@]}"
51+
else
52+
gh release download "${ARGS[@]}"
53+
fi
3954
unzip -p magisk.apk 'lib/arm64-v8a/libmagiskboot.so' > module/bin/magiskboot
4055
rm magisk.apk
4156

build.sh

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,61 @@ cd webui
1212
npm run build || npm install && npm run build
1313
cd ..
1414

15-
download_bin() {
16-
local suffix="$1"
17-
local target="$2"
18-
local url=$(echo "$RELEASE_JSON" | jq -r ".assets[] | select(.name | endswith(\"$suffix\")) | .browser_download_url")
15+
# Read versions from version.properties
16+
get_ver() {
17+
[ -f version.properties ] && grep "^$1[[:space:]]*=" version.properties | cut -d'=' -f2 | xargs | sed 's/^"//;s/"$//'
18+
}
19+
20+
download_assets() {
21+
local repo="$1"
22+
local tag="$2"
23+
shift 2
24+
local patterns=("$@")
25+
26+
local url="https://api.github.com/repos/$repo/releases"
27+
if [[ "$tag" == "latest" ]]; then
28+
url="$url/latest"
29+
else
30+
url="$url/tags/$tag"
31+
fi
32+
33+
local release_json=$(curl -s "$url")
1934

20-
echo "Downloading $target from $url"
21-
curl -L "$url" -o "module/bin/$target"
35+
for pattern in "${patterns[@]}"; do
36+
local regex="${pattern//\*/.*}"
37+
local asset_data=$(echo "$release_json" | jq -r ".assets[] | select(.name | test(\"$regex\")) | .name + \"\t\" + .browser_download_url" | head -n 1)
38+
if [[ -z "$asset_data" ]]; then
39+
echo "Error: Could not find asset matching $pattern in $repo $tag"
40+
continue
41+
fi
42+
local asset_name=$(echo "$asset_data" | cut -f1)
43+
local download_url=$(echo "$asset_data" | cut -f2)
44+
echo "Downloading $asset_name from $download_url"
45+
curl -L "$download_url" -o "module/bin/$asset_name"
46+
done
2247
}
2348

49+
VERSION_KPATCH_NEXT=$(get_ver "kpatch-next")
50+
VERSION_KPATCH_NEXT="${VERSION_KPATCH_NEXT:-latest}"
51+
VERSION_MAGISKBOOT=$(get_ver "magiskboot")
52+
VERSION_MAGISKBOOT="${VERSION_MAGISKBOOT:-latest}"
53+
2454
# Fetch KPatch-Next binaries
2555
if [[ ! -f "module/bin/kpatch" || ! -f "module/bin/kpimg" || ! -f "module/bin/kptools" ]]; then
26-
URL="https://api.github.com/repos/KernelSU-Next/KPatch-Next/releases"
27-
RELEASE_JSON=$(curl -s "$URL" | jq '.[0]')
56+
download_assets "KernelSU-Next/KPatch-Next" "$VERSION_KPATCH_NEXT" "kpatch-android" "kpimg-linux" "kptools-android"
2857

29-
download_bin "kpatch-android" "kpatch"
30-
download_bin "kpimg-linux" "kpimg"
31-
download_bin "kptools-android" "kptools"
58+
mv module/bin/kpatch-android module/bin/kpatch
59+
mv module/bin/kptools-android module/bin/kptools
60+
mv module/bin/kpimg-linux module/bin/kpimg
3261
fi
3362

3463
# Fetch magiskboot
3564
if [[ ! -f "module/bin/magiskboot" ]]; then
36-
URL="https://api.github.com/repos/topjohnwu/Magisk/releases"
37-
RELEASE_JSON=$(curl -s "$URL" | jq '.[0]')
38-
download_bin "Magisk*.apk" "magiskboot"
65+
download_assets "topjohnwu/Magisk" "$VERSION_MAGISKBOOT" "Magisk*.apk"
66+
67+
APK=$(ls module/bin/Magisk*.apk | head -n 1)
68+
unzip -p "$APK" 'lib/arm64-v8a/libmagiskboot.so' > "module/bin/magiskboot"
69+
rm "$APK"
3970
fi
4071

4172
# zip module

version.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# KPatch-Next module dependencies version config
2+
kpatch-next="latest"
3+
magiskboot="v30.6"

0 commit comments

Comments
 (0)