Skip to content

Commit 9bc3cfd

Browse files
authored
Merge pull request #80 from huangdihd/fix/share-susfs-artifact
ci: reuse SUSFS archives across matrix builds
2 parents 3c07278 + 9a0d291 commit 9bc3cfd

2 files changed

Lines changed: 183 additions & 9 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# The build action fetches source archives with aria2c. For SUSFS specifically,
5+
# CI pre-downloads the resolved commit archives once and distributes them as a
6+
# GitHub Actions artifact. This shim serves those local archives while passing
7+
# every other aria2c invocation through unchanged.
8+
9+
args=("$@")
10+
out=""
11+
dir="."
12+
url=""
13+
14+
for ((i = 0; i < ${#args[@]}; i++)); do
15+
case "${args[$i]}" in
16+
-o|--out)
17+
if (( i + 1 < ${#args[@]} )); then
18+
out="${args[$((i + 1))]}"
19+
((i += 1))
20+
fi
21+
;;
22+
-d|--dir)
23+
if (( i + 1 < ${#args[@]} )); then
24+
dir="${args[$((i + 1))]}"
25+
((i += 1))
26+
fi
27+
;;
28+
http://*|https://*)
29+
url="${args[$i]}"
30+
;;
31+
esac
32+
done
33+
34+
susfs_prefix="https://gitlab.com/simonpunk/susfs4ksu/-/archive/"
35+
if [[ "$url" == "${susfs_prefix}"* ]]; then
36+
ref="${url#${susfs_prefix}}"
37+
ref="${ref%%/*}"
38+
archive="${GITHUB_WORKSPACE}/susfs-archives/susfs4ksu-${ref}.tar.gz"
39+
40+
if [[ -z "$out" ]]; then
41+
echo "::error::SUSFS aria2 shim could not determine the requested output filename" >&2
42+
exit 2
43+
fi
44+
45+
if [[ ! -s "$archive" ]]; then
46+
echo "::error::Shared SUSFS archive is missing for ref ${ref}: ${archive}" >&2
47+
exit 1
48+
fi
49+
50+
mkdir -p "$dir"
51+
cp -f "$archive" "$dir/$out"
52+
echo "✅ Reused shared SUSFS archive for ${ref}"
53+
exit 0
54+
fi
55+
56+
shim_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
57+
clean_path=""
58+
IFS=':' read -ra path_parts <<< "$PATH"
59+
for part in "${path_parts[@]}"; do
60+
[[ -z "$part" || "$part" == "$shim_dir" ]] && continue
61+
if [[ -z "$clean_path" ]]; then
62+
clean_path="$part"
63+
else
64+
clean_path+="${clean_path:+:}$part"
65+
fi
66+
done
67+
68+
real_aria2c="$(PATH="$clean_path" command -v aria2c || true)"
69+
if [[ -z "$real_aria2c" ]]; then
70+
echo "::error::aria2c is unavailable outside the SUSFS archive shim" >&2
71+
exit 127
72+
fi
73+
74+
exec "$real_aria2c" "$@"

‎.github/workflows/build-kernel-release.yml‎

Lines changed: 109 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,96 @@ jobs:
592592
retention-days: 1
593593
if-no-files-found: warn
594594

595+
prepare_susfs:
596+
name: Prepare SUSFS archives (download once)
597+
needs: set-op-model
598+
if: ${{ needs.set-op-model.outputs.active_gki_keys != '' }}
599+
runs-on: ubuntu-latest
600+
steps:
601+
- name: Download active SUSFS archives once
602+
env:
603+
ACTIVE_GKI_KEYS: ${{ needs.set-op-model.outputs.active_gki_keys }}
604+
SUSFS_HASH_ANDROID12_5_10: ${{ needs.set-op-model.outputs.susfs_hash_android12_5_10 }}
605+
SUSFS_HASH_ANDROID13_5_15: ${{ needs.set-op-model.outputs.susfs_hash_android13_5_15 }}
606+
SUSFS_HASH_ANDROID14_6_1: ${{ needs.set-op-model.outputs.susfs_hash_android14_6_1 }}
607+
SUSFS_HASH_ANDROID15_6_6: ${{ needs.set-op-model.outputs.susfs_hash_android15_6_6 }}
608+
SUSFS_HASH_ANDROID16_6_12: ${{ needs.set-op-model.outputs.susfs_hash_android16_6_12 }}
609+
run: |
610+
set -euo pipefail
611+
echo "::group::Download shared SUSFS archives"
612+
mkdir -p susfs-archives
613+
614+
declare -A hashes=(
615+
["android12-5.10"]="$SUSFS_HASH_ANDROID12_5_10"
616+
["android13-5.15"]="$SUSFS_HASH_ANDROID13_5_15"
617+
["android14-6.1"]="$SUSFS_HASH_ANDROID14_6_1"
618+
["android15-6.6"]="$SUSFS_HASH_ANDROID15_6_6"
619+
["android16-6.12"]="$SUSFS_HASH_ANDROID16_6_12"
620+
)
621+
declare -A seen=()
622+
623+
IFS=',' read -ra active_keys <<< "$ACTIVE_GKI_KEYS"
624+
for key in "${active_keys[@]}"; do
625+
ref="${hashes[$key]:-unknown}"
626+
if [[ ! "$ref" =~ ^[0-9a-f]{40}$ ]]; then
627+
echo "::error::Invalid resolved SUSFS hash '$ref' for $key"
628+
exit 1
629+
fi
630+
631+
if [[ -n "${seen[$ref]:-}" ]]; then
632+
echo "ℹ️ $key reuses SUSFS $ref; skipping duplicate download"
633+
continue
634+
fi
635+
seen[$ref]=1
636+
637+
archive="susfs-archives/susfs4ksu-${ref}.tar.gz"
638+
tmp="${archive}.part"
639+
url="https://gitlab.com/api/v4/projects/simonpunk%2Fsusfs4ksu/repository/archive.tar.gz?sha=${ref}&include_lfs_blobs=false"
640+
ok=0
641+
642+
for attempt in 1 2 3 4 5 6; do
643+
rm -f "$tmp"
644+
if curl -LfsS --connect-timeout 30 --max-time 180 \
645+
-H "User-Agent: Mozilla/5.0" "$url" -o "$tmp" \
646+
&& [ -s "$tmp" ] \
647+
&& tar -tzf "$tmp" >/dev/null 2>&1; then
648+
mv "$tmp" "$archive"
649+
ok=1
650+
echo "✅ Downloaded $key SUSFS $ref"
651+
break
652+
fi
653+
654+
echo "::warning::SUSFS download failed for $key (attempt $attempt/6); backing off..."
655+
sleep $(( attempt * 5 + RANDOM % 6 ))
656+
done
657+
658+
if [ "$ok" != 1 ]; then
659+
rm -f "$tmp"
660+
echo "::error::Failed to download SUSFS archive for $key ($ref)"
661+
exit 1
662+
fi
663+
done
664+
665+
echo "Prepared $(find susfs-archives -maxdepth 1 -name 'susfs4ksu-*.tar.gz' -type f | wc -l) unique SUSFS archive(s)"
666+
echo "::endgroup::"
667+
668+
- name: Upload shared SUSFS archives
669+
uses: actions/upload-artifact@v4
670+
with:
671+
name: susfs-archives
672+
path: susfs-archives/*.tar.gz
673+
retention-days: 1
674+
compression-level: 0
675+
if-no-files-found: error
676+
595677
build:
596678
name: build (${{ matrix.model }}, ${{ matrix.soc }}, ${{ matrix.branch }}, ${{ matrix.manifest }}, ${{ matrix.android_version }}, ${{ matrix.kernel_version }}, ${{ matrix.os_version }}, ${{ matrix.ksu_type }})
597-
needs: [set-op-model, mirror_toolchain, prepare_ccache]
679+
needs: [set-op-model, mirror_toolchain, prepare_ccache, prepare_susfs]
598680
if: |
599681
!cancelled() &&
600682
needs.set-op-model.result == 'success' &&
601-
(needs.mirror_toolchain.result == 'success' || needs.mirror_toolchain.result == 'skipped')
683+
(needs.mirror_toolchain.result == 'success' || needs.mirror_toolchain.result == 'skipped') &&
684+
(needs.prepare_susfs.result == 'success' || needs.prepare_susfs.result == 'skipped')
602685
runs-on: ubuntu-latest
603686
strategy:
604687
fail-fast: false
@@ -652,6 +735,22 @@ jobs:
652735
echo "[DEBUG] Ccache version : $(ccache --version | head -1)"
653736
echo "::endgroup::"
654737
738+
- name: Get shared SUSFS archives
739+
if: ${{ matrix.susfs }}
740+
uses: actions/download-artifact@v4
741+
with:
742+
name: susfs-archives
743+
path: susfs-archives
744+
745+
- name: Route SUSFS fetches to shared archive
746+
if: ${{ matrix.susfs }}
747+
shell: bash
748+
run: |
749+
set -euo pipefail
750+
chmod +x "$GITHUB_WORKSPACE/.github/scripts/susfs-archive-bin/aria2c"
751+
echo "$GITHUB_WORKSPACE/.github/scripts/susfs-archive-bin" >> "$GITHUB_PATH"
752+
echo "✅ SUSFS archive shim enabled for this matrix job"
753+
655754
- name: ♻️ Configure ccache (bounded)
656755
run: |
657756
echo "::group::Configure ccache environment"
@@ -900,16 +999,17 @@ jobs:
900999
merge-multiple: true
9011000
skip-decompress: true
9021001

903-
- name: 🧹 Exclude ccache binary from release staging
1002+
- name: 🧹 Exclude build helper artifacts from release staging
9041003
run: |
905-
# merge-multiple pulls every run artifact (including the shared
906-
# ccache-binary) into ./downloaded-artifacts. The ccache binary is a
907-
# build-time helper and must never become a release asset, so drop it
908-
# before notes generation / asset upload. The ccache download-once
909-
# mechanism (prepare_ccache job + ccache-binary artifact) is untouched.
1004+
# Shared build helpers must never become release assets. With
1005+
# skip-decompress=true, archived helpers are downloaded as <name>.zip.
9101006
find ./downloaded-artifacts -maxdepth 2 -type f -name ccache -delete
1007+
find ./downloaded-artifacts -maxdepth 2 -type f -name 'susfs4ksu-*.tar.gz' -delete
1008+
rm -f ./downloaded-artifacts/ccache-binary.zip
1009+
rm -f ./downloaded-artifacts/susfs-archives.zip
9111010
rm -rf ./downloaded-artifacts/ccache-binary
912-
echo "✅ ccache binary excluded from release staging"
1011+
rm -rf ./downloaded-artifacts/susfs-archives
1012+
echo "✅ build helper artifacts excluded from release staging"
9131013
9141014
- name: 📝 Generate Device List and Final Release Notes
9151015
id: generate-notes

0 commit comments

Comments
 (0)