Skip to content

Build OnePlus Kernel #20

Build OnePlus Kernel

Build OnePlus Kernel #20

name: Build OnePlus Kernel
permissions:
contents: write
actions: write
on:
workflow_dispatch:
inputs:
op_model:
description: 'Select the OnePlus kernels to build'
required: true
type: choice
options:
# OOS16
- OP15r_oos16
- OP15_oos16
- OP13_oos16
- OP13r_oos16
- OP13S_oos16
- OP13T_oos16
- OP12_oos16
- OP12r_oos16
- OP11_oos16
- OP11r_oos16
- OP-ACE-6T_oos16
- OP-ACE-6_oos16
- OP-ACE-5-PRO_oos16
- OP-ACE-5_oos16
- OP-ACE-5-ULTRA_oos16
- OP-ACE-5-RACE_oos16
- OP-ACE-3-PRO_oos16
- OP-ACE-3V_oos16
- OP-ACE-3_oos16
- OP-ACE-2-PRO_oos16
- OP-ACE-2_oos16
- OP-NORD-5_oos16
- OP-NORD-CE-5_oos16
- OP-NORD-4_oos16
- OP-NORD-4-CE_oos16
- OP-PAD-3-SM8750_oos16
- OP-PAD-2-PRO_oos16
- OP-PAD-2-MT6991_oos16
- OP-PAD-2-SM8650_oos16
- OP-PAD-PRO_oos16
- OP-PAD-MT6983_oos16
- OP-OPEN_oos16
- OP-PAD-GO-2_oos16
# OOS15
- OP13-CPH_oos15
- OP13-PJZ_oos15
- OP13r_oos15
- OP13S_oos15
- OP13T_oos15
- OP12_oos15
- OP12r_oos15
- OP11_oos15
- OP11r_oos15
- OP10t_oos15
- OP10pro_oos15
- OP10r_oos15
- OP-ACE-5-PRO_oos15
- OP-ACE-5_oos15
- OP-ACE-5-ULTRA_oos15
- OP-ACE-5-RACE_oos15
- OP-ACE-3-PRO_oos15
- OP-ACE-3V_oos15
- OP-ACE-3_oos15
- OP-ACE-2-PRO_oos15
- OP-ACE-2V_oos15
- OP-ACE-2_oos15
- OP-ACE-RACE_oos15
- OP-ACE_oos15
- OP-NORD-5_oos15
- OP-NORD-CE-5_oos15
- OP-NORD-4_oos15
- OP-NORD-4-CE_oos15
- OP-NORD-CE4-LITE_oos15
- OP-NORD-3_oos15
- OP-PAD-3-SM8750_oos15
- OP-PAD-3-MT6897_oos15
- OP-PAD-2-PRO_oos15
- OP-PAD-2-SM8650_oos15
- OP-PAD-PRO_oos15
- OP-PAD-MT6983_oos15
- OP-PAD-LITE_oos15
- OP-OPEN_oos15
# OOS14
- OP12_oos14
- OP11_oos14
- OP11r_oos14
- OP10pro_oos14
- OP10r_oos14
- OP-ACE-3-PRO_oos14
- OP-ACE-RACE_oos14
- OP-ACE_oos14
- OP-PAD-PRO_oos14
default: OP11_oos16
ksu_options:
description: 'Enter KernelSU build json'
required: true
type: string
default: '[{"type":"ksun","hash":"dev"}]'
optimize_level:
description: "Compiler optimization level"
required: true
type: choice
options: [O2, O3]
default: O2
clean_build:
description: 'Clean build (no ccache)'
type: boolean
default: false
android12-5_10_susfs_branch_or_commit:
description: 'Enter SusFS Branch or commit hash for android12-5.10'
type: string
default: ''
android13-5_15_susfs_branch_or_commit:
description: 'Enter SusFS Branch or commit hash for android13-5.15'
type: string
default: ''
android14-6_1_susfs_branch_or_commit:
description: 'Enter SusFS Branch or commit hash for android14-6.1'
type: string
default: ''
android15-6_6_susfs_branch_or_commit:
description: 'Enter SusFS Branch or commit hash for android15-6.6'
type: string
default: ''
android16-6_12_susfs_branch_or_commit:
description: 'Enter SusFS Branch or commit hash for android16-6.12'
type: string
default: ''
jobs:
set-op-model:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
device_count: ${{ steps.set-matrix.outputs.count }}
steps:
- name: 📥 Checkout Code (to access configs/)
uses: actions/checkout@v4
with:
ref: devices
sparse-checkout: |
configs/
sparse-checkout-cone-mode: false
- name: 🔍 Generate build matrix
id: set-matrix
shell: bash
run: |
set -euo pipefail
echo "::group::Matrix generation"
input="${{ github.event.inputs.op_model }}"
ksu_options_raw='${{ github.event.inputs.ksu_options }}'
if ! ksu_options_normalized=$(echo "$ksu_options_raw" | jq -c 'map(if .type then .type |= ascii_upcase | if .hash == null then if .type == "KSUN" then .hash = "dev" elif .type == "KSU" then .hash = "main" else .hash end else . end else error("No type found") end)' 2>&1); then
echo "::error::ksu_options validation failed: $ksu_options_normalized"
exit 1
fi
model_part="${input%_*}"
os_part="${input##*_}"
case "$os_part" in
oos14) config_dir="configs/oos14" ;;
oos15) config_dir="configs/oos15" ;;
oos16) config_dir="configs/oos16" ;;
*) echo "::error::Unknown OS part: $os_part"; exit 1 ;;
esac
if [[ ! -d "$config_dir" ]]; then
echo "::error::Config directory does not exist: $config_dir"
exit 1
fi
mapfile -t all_json_files < <(find "$config_dir/" -name "$model_part.json" -print0 2>/dev/null | xargs -0 -n1)
if [[ ${#all_json_files[@]} -eq 0 ]]; then
echo "::error::No config file found for model '$model_part' in '$config_dir/'"
exit 1
fi
echo "[" > matrix.json
for i in "${!all_json_files[@]}"; do
file="${all_json_files[$i]}"
if [ -f "$file" ]; then
jq -r '.' "$file" >> matrix.json
if [ $((i+1)) -lt ${#all_json_files[@]} ]; then
echo "," >> matrix.json
fi
fi
done
echo "]" >> matrix.json
os_version=$(echo "$os_part" | tr '[:lower:]' '[:upper:]')
echo "🔍 Parsing input: $input"
echo " Model part: $model_part"
echo " OS part: $os_version"
echo " Config dir: $config_dir"
jq_filter="map(select(.model == \"$model_part\" and .os_version == \"$os_version\"))"
filtered=$(jq -c "$jq_filter" matrix.json)
count=$(jq 'length' <<<"$filtered")
if [ "$count" -eq 0 ]; then
echo "::error::No config files found for model '$model_part' with OS version '$os_version' in '$config_dir'!"
exit 1
fi
merged_matrix=$(jq -n --argjson devices "$filtered" --argjson ksu_list "$ksu_options_normalized" '[ $devices[] as $dev | $ksu_list[] as $ksu | ($dev + {ksu_type: $ksu.type, ksu_hash: $ksu.hash}) ]')
final_count=$(echo "$merged_matrix" | jq -s length)
wrapped=$(jq -n --argjson items "$merged_matrix" '{ include: $items }')
echo "✅ Found $final_count device(s) to build"
echo ""
echo "Selected devices:"
jq -r '.[] | " - \(.model) (\(.os_version), \(.android_version)-\(.kernel_version), \(.ksu_type) - \(.ksu_hash))"' <<<"$merged_matrix"
echo "matrix=$(jq -c . <<< "$wrapped")" >> "$GITHUB_OUTPUT"
echo "count=$count" >> "$GITHUB_OUTPUT"
echo "::endgroup::"
- name: Upload build matrix
uses: actions/upload-artifact@v4
with:
name: build-matrix
path: matrix.json
retention-days: 1
- name: 📊 Build plan summary
run: |
ksu_options_raw='${{ github.event.inputs.ksu_options }}'
ksu_options_normalized=$(echo "$ksu_options_raw" | jq -c 'map(if .type then .type |= ascii_upcase | if .hash == null then if .type == "KSUN" then .hash = "dev" elif .type == "KSU" then .hash = "main" else .hash end else . end else error("No type found") end)' 2>&1)
# export KSU_OPTIONS="$ksu_options_normalized"
# cat >> $GITHUB_STEP_SUMMARY << 'EOF'
# ## 🎯 Build Plan
# **Target:** `${{ inputs.op_model }}`
# **Devices:** ${{ steps.set-matrix.outputs.count }}
# **Configuration:**
# - KSU Config: `"$KSU_OPTIONS"`
# - Optimization: `${{ inputs.optimize_level }}`
# - Clean Build/No Ccache: ${{ inputs.clean_build && '✅ Yes' || '❌ No' }}
# **SUSFS Configuration:**
# EOF
{
cat << 'EOF'
## 🎯 Build Plan
**Target:** ${{ inputs.op_model }}
**Devices:** ${{ steps.set-matrix.outputs.count }}
**Configuration:**
- KSU Config: `
EOF
# Inject the shell variable
printf '%s' "$ksu_options_normalized"
cat << 'EOF'
`
- Optimization: ${{ inputs.optimize_level }}
- Clean Build/No Ccache: ${{ inputs.clean_build && '✅ Yes' || '❌ No' }}
**SUSFS Configuration:**
EOF
} >> "$GITHUB_STEP_SUMMARY"
# Display SUSFS config for each kernel version
declare -A susfs_inputs=(
["android12-5.10"]="${{ inputs.android12-5_10_susfs_branch_or_commit }}"
["android13-5.15"]="${{ inputs.android13-5_15_susfs_branch_or_commit }}"
["android14-6.1"]="${{ inputs.android14-6_1_susfs_branch_or_commit }}"
["android15-6.6"]="${{ inputs.android15-6_6_susfs_branch_or_commit }}"
["android16-6.12"]="${{ inputs.android16-6_12_susfs_branch_or_commit }}"
)
for key in "android12-5.10" "android13-5.15" "android14-6.1" "android15-6.6" "android16-6.12"; do
value="${susfs_inputs[$key]}"
if [ -z "$value" ]; then
echo "- $key: 🔄 auto (\`gki-$key\`)" >> $GITHUB_STEP_SUMMARY
else
echo "- $key: 📌 \`$value\`" >> $GITHUB_STEP_SUMMARY
fi
done
echo "" >> $GITHUB_STEP_SUMMARY
echo "> **💡 Note:** Empty values auto-map to matching \`gki-androidX-Y.Z\` branches." >> $GITHUB_STEP_SUMMARY
# Add OOS restriction note for android-kernel filters
if [[ "${{ inputs.op_model }}" == android*-*.* ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "> **⚠️ Android-Kernel Filter:** Only OOS15 and OOS16 devices will be built for \`${{ inputs.op_model }}\`" >> $GITHUB_STEP_SUMMARY
fi
build:
name: build (${{ matrix.model }}, ${{ matrix.soc }}, ${{ matrix.branch }}, ${{ matrix.manifest }}, ${{ matrix.android_version }}, ${{ matrix.kernel_version }}, ${{ matrix.os_version }}, ${{ matrix.ksu_type }})
needs: set-op-model
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.set-op-model.outputs.matrix) }}
outputs:
ksun_ver: ${{ steps.build-stat.outputs.ksu_version }}
ksu_ver: ${{ steps.build-stat.outputs.ksu_version }}
steps:
- name: 🧹 Emergency Disk Cleanup
if: ${{ matrix.disk_cleanup }}
run: |
echo "::group::Disk Usage Before Cleanup"
df -h
echo "::endgroup::"
echo "::group::Removing Unnecessary Software"
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo apt-get clean
if command -v docker >/dev/null 2>&1; then
docker rmi $(docker images -q) 2>/dev/null || true
fi
echo "::endgroup::"
echo "::group::Disk Usage After Cleanup"
df -h
AVAIL=$(df -h / | awk 'NR==2 {print $4}')
echo "✅ Available space: $AVAIL"
echo "::endgroup::"
- name: Download Apache Arrow's util_free_space.sh
if: ${{ matrix.disk_cleanup }}
run: |
curl -L -o util_free_space.sh https://raw.githubusercontent.com/apache/arrow/main/ci/scripts/util_free_space.sh
chmod +x util_free_space.sh
./util_free_space.sh
- name: 🔍 Resolve SUSFS branch from inputs
id: susfs
shell: bash
if: ${{ matrix.susfs }}
run: |
set -euo pipefail
key="${{ matrix.android_version }}-${{ matrix.kernel_version }}"
echo "Looking up SUSFS branch for: $key"
# Map kernel version to input value
case "$key" in
"android12-5.10")
susfs_branch="${{ inputs.android12-5_10_susfs_branch_or_commit }}"
;;
"android13-5.15")
susfs_branch="${{ inputs.android13-5_15_susfs_branch_or_commit }}"
;;
"android14-6.1")
susfs_branch="${{ inputs.android14-6_1_susfs_branch_or_commit }}"
;;
"android15-6.6")
susfs_branch="${{ inputs.android15-6_6_susfs_branch_or_commit }}"
;;
"android16-6.12")
susfs_branch="${{ inputs.android16-6_12_susfs_branch_or_commit }}"
;;
*)
echo "::error::Unsupported kernel version: $key"
exit 1
;;
esac
# If empty, it will be auto-resolved to gki-* branch in the action
if [ -z "$susfs_branch" ]; then
echo "ℹ️ No custom SUSFS branch specified for $key"
echo " Will auto-select: gki-$key"
else
echo "✅ Using custom SUSFS branch for $key: '$susfs_branch'"
fi
echo "susfs_branch=$susfs_branch" >> "$GITHUB_OUTPUT"
- name: Install Minimal Dependencies
run: |
set -euo pipefail
echo "::group::Install dependencies"
sudo apt-get -o Acquire::Retries=3 update -qq
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
git curl ca-certificates build-essential clang lld flex bison \
libelf-dev libssl-dev libncurses-dev zlib1g-dev liblz4-tool \
libxml2-utils rsync unzip dwarves file python3 ccache jq bc dos2unix kmod libdw-dev elfutils
sudo apt-get clean
echo "✅ Dependencies installed"
echo "::endgroup::"
- name: 📦 Disk usage (pre-build)
run: |
echo "::group::Disk usage pre-build"
df -h /
du -sh "$GITHUB_WORKSPACE" 2>/dev/null || true
sudo rm -rf /tmp/* || true
echo "::endgroup::"
- name: ♻️ Configure ccache (bounded)
if: ${{ inputs.clean_build != true }}
run: |
if command -v ccache >/dev/null 2>&1; then
echo "::group::ccache configuration"
ccache -o max_size=1.0G
ccache -o compression=true
ccache -o compression_level=3
ccache -s
echo "::endgroup::"
fi
- name: 🧹 Prepare op_config_json (without KSU fields)
id: prepare_config
shell: bash
run: |
echo "config_json=$(jq -nc --argjson m '${{ toJSON(matrix) }}' '$m | del(.ksu_type, .ksu_hash)')" >> "$GITHUB_OUTPUT"
- name: 📥 Checkout Code (to access manifests/)
uses: actions/checkout@v4
with:
repository: WildKernels/OnePlus_KernelSU_SUSFS
ref: main
sparse-checkout: |
manifests/
sparse-checkout-cone-mode: false
- name: 🔨 Build Kernel
id: build
uses: WildKernels/OnePlus_KernelSU_SUSFS/.github/actions@main
with:
op_config_json: ${{ steps.prepare_config.outputs.config_json }}
ksu_type: ${{ matrix.ksu_type }}
ksu_branch_or_hash: ${{ matrix.ksu_hash }}
susfs_commit_hash_or_branch: ${{ steps.susfs.outputs.susfs_branch }}
optimize_level: ${{ inputs.optimize_level }}
clean: ${{ inputs.clean_build }}
- name: 📊 Build statistics
id: build-stat
if: always()
run: |
echo "::group::Build Statistics"
echo "Device: ${{ matrix.model }}"
echo "OS Version: ${{ matrix.os_version }}"
echo "Kernel: ${{ matrix.android_version }}-${{ matrix.kernel_version }}"
if [ "${{ matrix.susfs }}" = true ]; then
echo "SUSFS Branch: ${{ steps.susfs.outputs.susfs_branch }}"
fi
echo "Status: ${{ job.status }}"
if [ "${{ steps.build.outcome }}" = "success" ]; then
echo ""
echo "✅ Build completed successfully"
echo ""
echo "Outputs:"
echo " - Kernel: ${{ steps.build.outputs.kernel_version }}"
if [ "${{ matrix.ksu_type }}" = "KSUN" ]; then
echo " - KSU Next: v${{ steps.build.outputs.ksu_version }}"
echo "ksun_ver=${{ steps.build.outputs.ksu_version }}" >> "$GITHUB_OUTPUT"
echo "ksu_ver=" >> "$GITHUB_OUTPUT"
else
echo " - KSU: v${{ steps.build.outputs.ksu_version }}"
echo "ksun_ver=" >> "$GITHUB_OUTPUT"
echo "ksu_ver=${{ steps.build.outputs.ksu_version }}" >> "$GITHUB_OUTPUT"
fi
if [ "${{ matrix.susfs }}" = true ]; then
echo " - SUSFS: ${{ steps.build.outputs.susfs_version }}"
fi
echo " - Build time: ${{ steps.build.outputs.build_time }}s"
if [ "${{ inputs.clean_build }}" != "true" ]; then
echo " - ccache hit rate: ${{ steps.build.outputs.ccache_hit_rate }}"
echo " - ccache direct rate: ${{ steps.build.outputs.ccache_direct_rate }}"
else
echo " - ccache: disabled (clean build)"
fi
if [ -n "${{ steps.build.outputs.warnings }}" ]; then
echo " - Warnings: ${{ steps.build.outputs.warnings }}"
fi
else
echo "❌ Build failed"
fi
echo "::endgroup::"
- name: 📝 Job summary
if: always()
run: |
cat >> $GITHUB_STEP_SUMMARY << EOF
### ${{ matrix.model }} (${{ matrix.os_version }}) - ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }}
**Kernel:** ${{ matrix.android_version }}-${{ matrix.kernel_version }}
EOF
if [ "${{ matrix.susfs }}" = true ]; then
cat >> $GITHUB_STEP_SUMMARY << EOF
**SUSFS Branch:** \`${{ steps.susfs.outputs.susfs_branch || format('(auto: gki-{0}-{1})', matrix.android_version, matrix.kernel_version) }}\`
EOF
fi
if [ "${{ steps.build.outcome }}" = "success" ]; then
cat >> $GITHUB_STEP_SUMMARY << EOF
| Metric | Value |
|--------|-------|
| **Kernel** | ${{ steps.build.outputs.kernel_version }} |
EOF
if [ "${{ matrix.ksu_type }}" = "KSUN" ]; then
cat >> $GITHUB_STEP_SUMMARY << EOF
| **KSU Next** | v${{ steps.build.outputs.ksu_version }} |
EOF
else
cat >> $GITHUB_STEP_SUMMARY << EOF
| **KSU** | v${{ steps.build.outputs.ksu_version }} |
EOF
fi
if [ "${{ matrix.susfs }}" = true ]; then
cat >> $GITHUB_STEP_SUMMARY << EOF
| **SUSFS** | ${{ steps.build.outputs.susfs_version }} |
EOF
fi
cat >> $GITHUB_STEP_SUMMARY << EOF
| **Build Time** | ${{ steps.build.outputs.build_time }}s |
EOF
if [ "${{ inputs.clean_build }}" != "true" ]; then
cat >> $GITHUB_STEP_SUMMARY << EOF
| **ccache Hit Rate** | ${{ steps.build.outputs.ccache_hit_rate }} |
| **ccache Direct Rate** | ${{ steps.build.outputs.ccache_direct_rate }} |
EOF
fi
if [ -n "${{ steps.build.outputs.warnings }}" ]; then
echo "| **Warnings** | ${{ steps.build.outputs.warnings }} |" >> $GITHUB_STEP_SUMMARY
fi
cat >> $GITHUB_STEP_SUMMARY << EOF
**SHA256:** \`${{ steps.build.outputs.image_sha256 }}\`
EOF
fi
- name: 🧹 Final cleanup and space report
if: always()
run: |
echo "::group::Cleanup"
# Remove build artifacts but PRESERVE ccache
sudo rm -rf "$GITHUB_WORKSPACE/out" || true
sudo rm -rf "$GITHUB_WORKSPACE/build" || true
sudo rm -rf "$GITHUB_WORKSPACE/kernel/out" || true
sudo rm -rf "$GITHUB_WORKSPACE/.repo" || true
sudo rm -rf /tmp/* || true
# Show ccache stats (don't clear it!)
if command -v ccache >/dev/null 2>&1; then
echo ""
echo "📊 ccache statistics after build:"
ccache -s
echo ""
echo "💾 ccache preserved for next build"
fi
echo ""
echo "💽 Final disk usage:"
df -h /
echo "::endgroup::"