Skip to content

Commit 0c101da

Browse files
committed
refactor: centralise KSU/SUSFS hash resolution via API and clean up action.yml
- trigger-release: fix ksu_type/ksu_ref to read from needs.set-op-model.outputs - SUSFS: replace git ls-remote with GitLab REST API (/repository/commits/{ref}), retry 3x, exit 1 on failure - action.yml: remove obsolete "unknown" fallback checks
1 parent 527a93a commit 0c101da

2 files changed

Lines changed: 36 additions & 41 deletions

File tree

.github/actions/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ runs:
718718
cd "$KERNEL_PLATFORM_FOLDER"
719719
echo "Adding KernelSU Next..."
720720
KSU_INPUT="${{ inputs.ksu_branch_or_hash }}"
721-
if [ -z "$KSU_INPUT" ] || [ "$KSU_INPUT" = "unknown" ]; then
721+
if [ -z "$KSU_INPUT" ]; then
722722
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -
723723
else
724724
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -s "$KSU_INPUT"
@@ -772,7 +772,7 @@ runs:
772772
cd "$KERNEL_PLATFORM_FOLDER"
773773
echo "Adding KernelSU..."
774774
KSU_INPUT="${{ inputs.ksu_branch_or_hash }}"
775-
if [ -z "$KSU_INPUT" ] || [ "$KSU_INPUT" = "unknown" ]; then
775+
if [ -z "$KSU_INPUT" ]; then
776776
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -
777777
else
778778
curl --fail --location --proto '=https' -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s "$KSU_INPUT"

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

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ jobs:
241241
242242
# SUSFS hash fetch
243243
SUSFS_REPO="https://gitlab.com/simonpunk/susfs4ksu.git"
244+
PROJECT_ID="simonpunk%2fsusfs4ksu"
244245
245246
declare -A default_branches=(
246247
["android12-5.10"]="gki-android12-5.10"
@@ -266,46 +267,40 @@ jobs:
266267
267268
echo "🔍 Resolving SUSFS hashes for: ${active_keys[*]:-none}"
268269
269-
# Function: resolves any input > 40-char hash or "unknown"
270-
resolve_to_hash() {
271-
local input="$1"
272-
local repo="$2"
273-
local default_branch="$3"
270+
declare -A susfs_hashes
271+
for key in "${active_keys[@]}"; do
272+
default_val="${default_branches[$key]}"
273+
user_val="${user_inputs[$key]:-$default_val}"
274274
275-
if [ -z "$input" ]; then
276-
local fetched
277-
fetched=$(timeout 30 git ls-remote "$repo" \
278-
"refs/heads/$default_branch" 2>/dev/null \
279-
| awk '{print $1}' | head -n1 || true)
280-
echo "${fetched:-unknown}"
281-
else
282-
local fetched
283-
fetched=$(timeout 30 git ls-remote "$repo" \
284-
"refs/heads/$input" "refs/tags/$input" 2>/dev/null \
285-
| awk '{print $1}' | head -n1 || true)
286-
if [ -n "$fetched" ]; then
287-
echo "$fetched"
288-
elif [[ "$input" =~ ^[0-9a-f]{40}$ ]]; then
289-
echo "$input"
290-
else
291-
echo "unknown"
275+
MAX_RETRIES=3
276+
RETRY_COUNT=0
277+
RETRY_DELAY=5
278+
resolved=""
279+
280+
until [ $RETRY_COUNT -ge $MAX_RETRIES ]; do
281+
# We query the commit endpoint which accepts Branch, Tag, or SHA
282+
RESULT=$(curl -s --fail "https://gitlab.com/api/v4/projects/${PROJECT_ID}/repository/commits/${user_val}")
283+
EXIT_CODE=$?
284+
285+
if [ $EXIT_CODE -eq 0 ] && [ -n "$RESULT" ]; then
286+
resolved=$(echo "$RESULT" | jq -r '.id')
287+
echo " ✅ Query for $key input field Success"
288+
break
292289
fi
290+
291+
RETRY_COUNT=$((RETRY_COUNT + 1))
292+
echo "::warning::GitLab API failed (Attempt $RETRY_COUNT/$MAX_RETRIES). Retrying..."
293+
sleep $RETRY_DELAY
294+
done
295+
296+
# Final Validation
297+
if [ -z "$resolved" ] || [ "$resolved" = "null" ]; then
298+
echo "::error::Could not resolve SUSFS ref '$user_val' for $key on GitLab."
299+
exit 1
293300
fi
294-
}
295-
296-
declare -A susfs_hashes
297-
for key in "${active_keys[@]}"; do
298-
user_val="${user_inputs[$key]:-}"
299-
default_branch="${default_branches[$key]:-}"
300-
resolved=$(resolve_to_hash "$user_val" "$SUSFS_REPO" "$default_branch")
301+
301302
susfs_hashes["$key"]="$resolved"
302-
if [ -z "$user_val" ] || [ "$user_val" = "next" ]; then
303-
echo " $key → (auto) $resolved"
304-
elif [ "$resolved" = "$user_val" ]; then
305-
echo " $key → (hash passthrough) $resolved"
306-
else
307-
echo " $key → (branch resolved) $resolved"
308-
fi
303+
echo " ✅ Resolved: $key → $resolved"
309304
done
310305
311306
# Write CSV list of active GKI versions
@@ -425,7 +420,7 @@ jobs:
425420
done
426421
427422
echo "" >> $GITHUB_STEP_SUMMARY
428-
echo "> **💡 Note:** Hashes are resolved at run time via git ls-remote on susfs4ksu." >> $GITHUB_STEP_SUMMARY
423+
echo "> **💡 Note:** Hashes are resolved at run time via API calls before builds start." >> $GITHUB_STEP_SUMMARY
429424
430425
# Add OOS restriction note for android-kernel filters
431426
if [[ "${{ inputs.op_model }}" == android*-*.* ]]; then
@@ -733,8 +728,8 @@ jobs:
733728
fi
734729
done
735730
736-
ksu_type="${{ fromJSON(steps.set-matrix.outputs.ksu_options_normalized)[0].type }}"
737-
ksu_ref="${{ fromJSON(steps.set-matrix.outputs.ksu_options_normalized)[0].hash }}"
731+
ksu_type="${{ fromJSON(needs.set-op-model.outputs.ksu_options_normalized)[0].type }}"
732+
ksu_ref="${{ fromJSON(needs.set-op-model.outputs.ksu_options_normalized)[0].hash }}"
738733
ksu_resolved_hash="${{ needs.set-op-model.outputs.ksu_resolved_hash }}"
739734
740735
OPTIMIZE_LEVEL="${{ inputs.optimize_level }}"

0 commit comments

Comments
 (0)