name: Kernel Build Process permissions: contents: write actions: write on: workflow_call: inputs: branch: required: true type: string build_type: required: false type: string susfs: required: true type: string bbg: required: true type: string unicodefix: required: true type: string zeromount: required: true type: string nomount: required: true type: string ksun: required: true type: string droidspace: required: true type: string ntsync: required: true type: string bbrv3: required: true type: string cache: required: true type: string ipv6_nat: required: true type: string optimization: required: true type: string ttl: required: true type: string jobs: build-samsung-gki: name: "${{ inputs.branch }}" runs-on: ubuntu-latest strategy: fail-fast: false steps: - name: Checkout Repository uses: actions/checkout@v5 - name: Store branch as env variable run: BRANCH=${{ inputs.branch }} && echo "BRANCH=$BRANCH" >> $GITHUB_ENV - name: get kernel version before cloning uses: ./.github/actions/kernel-info - name: Free Disk Space if: true uses: endersonmenezes/free-disk-space@v3 # Use @main for latest, @v3 for stable with: remove_android: true remove_dotnet: true remove_haskell: true remove_tool_cache: true remove_swap: true remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*" remove_packages_one_command: true remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle" rm_cmd: "rmz" # Use 'rmz' for faster deletion (default: 'rm') rmz_version: "3.1.1" # Required when rm_cmd is 'rmz' testing: false - name: Setup more Swap (for LTO) uses: thejerrybao/setup-swap-space@v1 # or pierotofy/set-swap-space with: swap-size-gb: 25 # 10-24 GB is common for heavy LTO # swap-space-path: /mnt/swapfile # optional - name: Parse branch for cache keys if: inputs.cache == 'true' && inputs.build_type == 'make' uses: ./.github/actions/parse-branch # - name: set up bazel cache dir # if: inputs.build_type == 'Bazel' && inputs.cache == 'true' # run: | # BCACHE_DIR="${{ github.workspace }}/.cache/bazel-disk-kernel" # mkdir -p "$BCACHE_DIR" # echo "BCACHE_DIR=$BCACHE_DIR" >> $GITHUB_ENV # - name: set up bazel cache # if: inputs.build_type == 'Bazel' && inputs.cache == 'true' # uses: actions/cache@v6 # with: # path: ${{ env.BCACHE_DIR }} # key: bcache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.FULL_BRANCH }} # restore-keys: | # bcache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.FULL_BRANCH }} - name: Install ccache if: inputs.cache == 'true' && inputs.build_type == 'make' run: sudo apt-get update && sudo apt-get install -y ccache - name: Export ccache + determinism if: inputs.cache == 'true' && inputs.build_type == 'make' run: | CACHE_DIR="${{ github.workspace }}/.ccache" mkdir -p "$CACHE_DIR" CCACHE_LOG="${{ github.workspace }}/ccache.log" SETTINGS=( "CCACHE_DIR=$CACHE_DIR" "CCACHE_MAXSIZE=12G" "CCACHE_COMPILERCHECK=content" "CCACHE_BASEDIR=${GITHUB_WORKSPACE}" "CCACHE_NOHASHDIR=true" "CCACHE_IGNOREOPTIONS=-sysroot* -fdebug-prefix-map=* -fmacro-prefix-map=*" "CCACHE_COMPRESS=true" "CCACHE_COMPRESSLEVEL=8" "CCACHE_DIRECT=true" "CCACHE_FILE_CLONE=true" "CCACHE_INODE_CACHE=true" "CCACHE_IS_KERNEL_COMPILING=true" "CCACHE_UMASK=002" "KBUILD_BUILD_TIMESTAMP=2026-01-01" "CCACHE_SLOPPINESS=file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale,file_stat_matches" ) for setting in "${SETTINGS[@]}"; do export "$setting" echo "$setting" >> $GITHUB_ENV done if ccache --help 2>&1 | grep -q 'depend_mode'; then export CCACHE_DEPEND=true echo "CCACHE_DEPEND=true" >> "$GITHUB_ENV" fi - name: restore ccache if: inputs.cache == 'true' && inputs.build_type == 'make' uses: actions/cache@v6 with: path: ${{ env.CCACHE_DIR }} key: ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }} restore-keys: | ccache-${{ runner.os }}-${{ inputs.build_type }}-${{ env.BASE_BRANCH }} ccache-${{ runner.os }}-${{ inputs.build_type }}- - name: Ensure ccache is used if: inputs.cache == 'true' && inputs.build_type == 'make' run: | echo "/usr/lib/ccache" >> $GITHUB_PATH echo "CC='ccache clang'" >> $GITHUB_ENV echo "CXX='ccache clang++'" >> $GITHUB_ENV - name: Set CONFIG Environment Variable run: | # Set CONFIG dynamically based on inputs values CONFIG="$BRANCH-$ANDROID_VERSION_$KERNEL_VERSION" # Set CONFIG as an environment variable for future steps echo "CONFIG=$CONFIG" >> $GITHUB_ENV - name: dependencies uses: ./.github/actions/dependencies - name: Download Kernel uses: ./.github/actions/clone-kernel - name: Set Path Environment Variables uses: ./.github/actions/env-variables - name: Extract all tar.xz files and delete them run: | cd "$CONFIG" find . -type f -name '*.tar.xz' -print0 | while IFS= read -r -d '' file; do echo "Extracting $file" tar -xf "$file" rm "$file" done - name: Add KernelSU-Next if: inputs.ksun == 'true' uses: ./.github/actions/ksun with: susfs: ${{ inputs.susfs }} - name: Add SUSFS if: inputs.susfs == 'true' uses: ./.github/actions/susfs-patches - name: Add Zeromount if: inputs.susfs == 'true' && inputs.zeromount == 'true' uses: ./.github/actions/zeromount - name: add nomount if: inputs.nomount == 'true' uses: ./.github/actions/nomount - name: Add BBG if: inputs.bbg == 'true' uses: ./.github/actions/bbg - name: Add unicodefix if: inputs.unicodefix == 'true' uses: ./.github/actions/unicode - name: Add droidspace support if: inputs.droidspace == 'true' uses: ./.github/actions/droidspaces - name: Add ntsync if: inputs.ntsync == 'true' uses: ./.github/actions/ntsync - name: Add bbrv3 if: inputs.bbrv3 == 'true' uses: ./.github/actions/bbrv3 - name: Add IP-SET and IPv6_NAT support if: inputs.ipv6_nat == 'true' uses: ./.github/actions/IPv6_NAT - name: Add TTL support if: inputs.ttl == 'true' uses: ./.github/actions/TTL - name: add optimization patches if: inputs.optimization == 'true' uses: ./.github/actions/optimization - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices if: ${{ env.KERNEL_VER == '6.6' }} uses: ./.github/actions/6.6-fix - name: temp fix for m55 bootloop maybe if: inputs.branch == 'SM-M556B-Oneui8' uses: ./.github/actions/m55-fix - name: Set Kernel Configuration Variables if: inputs.ksun == 'true' uses: ./.github/actions/configs - name: Change Kernel Name and clean dirty uses: ./.github/actions/kernel-name - name: remove protected exports uses: ./.github/actions/abi-export - name: Set file name if: inputs.ksun == 'true' uses: ./.github/actions/file-name with: ksun: ${{ inputs.ksun }} susfs: ${{ inputs.susfs }} zeromount: ${{ inputs.zeromount }} nomount: ${{ inputs.nomount }} bbg: ${{ inputs.bbg }} bbrv3: ${{ inputs.bbrv3 }} droidspaces: ${{ inputs.droidspace }} ntsync: ${{ inputs.ntsync }} ipv6_nat: ${{ inputs.ipv6_nat }} ttl: ${{ inputs.ttl }} unicodefix: ${{ inputs.unicodefix }} # - name: ensure bazel cache is set to be used # if: inputs.build_type == 'Bazel' && inputs.cache == 'true' # uses: ./.github/actions/use-bazcache - name: change variables to ccache if: inputs.cache == 'true' && inputs.build_type == 'make' uses: ./.github/actions/use-ccache - name: enable FULL LTO uses: ./.github/actions/lto - name: Build uses: ./.github/actions/build with: build_type: ${{ inputs.build_type }} - name: clean up ccache if: inputs.cache == 'true' && inputs.build_type == 'make' run: ccache -c - name: ccache stats if: inputs.cache == 'true' && inputs.build_type == 'make' run: ccache -s -v || ccache -s # - name: bazel cache stats # if: inputs.cache == 'true' && inputs.build_type == 'Bazel' # run: bazel analyze-profile profile.json - name: Prepare AnyKernel3 uses: ./.github/actions/ak3zip-prep - name: Upload AnyKernel3 Artifacts id: upload_ak3 uses: actions/upload-artifact@v6 with: name: ${{ env.FILE_NAME }}-AnyKernel3 path: | ./AnyKernel3/** compression-level: 9 - name: Scan and collect patch rejects if: ${{ always() }} run: | set -e CONFIG_DIR="$CONFIG" REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects" mkdir -p "$REJECTS_DIR" # Find all .rej files under the configuration directory mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej') REJ_COUNT=${#REJS[@]} echo "Found $REJ_COUNT .rej files under $CONFIG_DIR" echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV if [ "$REJ_COUNT" -gt 0 ]; then for REJ in "${REJS[@]}"; do # Relative path from $CONFIG REL="${REJ#"$CONFIG_DIR"/}" DEST="$REJECTS_DIR/$REL" mkdir -p "$(dirname "$DEST")" cp "$REJ" "$DEST" # Copy the associated original file alongside the .rej ORIG="${REJ%.rej}" if [ -f "$ORIG" ]; then ORIG_DEST="$REJECTS_DIR/${REL%.rej}" mkdir -p "$(dirname "$ORIG_DEST")" cp "$ORIG" "$ORIG_DEST" fi echo "$REL" >> "$REJECTS_DIR/index.txt" done fi - name: Generate Build Summary if: ${{ always() }} run: | # Create build summary file for inclusion in Misc artifact echo "# Kernel Build Summary" > build_summary.md # Add build variant header echo "## ${{ env.FILE_NAME }}" >> build_summary.md # Add build info echo "## Build Information" >> build_summary.md echo "- **Android Version**: ${{ inputs.android_version }}" >> build_summary.md echo "- **Kernel Version**: ${{ inputs.kernel_version }}.${{ inputs.sub_level }}" >> build_summary.md echo "- **BBG**: Installed" >> build_summary.md echo "" >> build_summary.md # Get KernelSU-Next commit if [ -d "$CONFIG/KernelSU-Next" ]; then cd "$CONFIG/KernelSU-Next" KSUN_COMMIT=$(git rev-parse HEAD) KSUN_URL="https://github.com/WildKernels/KernelSU-Next/commit/$KSUN_COMMIT" echo "- **KernelSU-Next**: [$KSUN_COMMIT]($KSUN_URL)" >> "$GITHUB_WORKSPACE/build_summary.md" cd "$GITHUB_WORKSPACE" else echo "- **KernelSU-Next**: not present" >> build_summary.md fi # Get Baseband-guard commit if [ -d "$CONFIG/Baseband-guard" ]; then cd "$CONFIG/Baseband-guard" BBG_COMMIT=$(git rev-parse HEAD) BBG_URL="https://github.com/vc-teahouse/Baseband-guard/commit/$BBG_COMMIT" echo "- **Baseband-guard**: [$BBG_COMMIT]($BBG_URL)" >> "$GITHUB_WORKSPACE/build_summary.md" cd "$GITHUB_WORKSPACE" else echo "- **Baseband-guard**: not present" >> build_summary.md fi # Get SUSFS4KSU commit if [ -d "$GITHUB_WORKSPACE/susfs4ksu" ]; then cd "$GITHUB_WORKSPACE/susfs4ksu" SUSFS_COMMIT=$(git rev-parse HEAD) SUSFS_URL="https://gitlab.com/simonpunk/susfs4ksu/-/commit/$SUSFS_COMMIT" echo "- **SUSFS4KSU (v2.1.0)**: [$SUSFS_COMMIT]($SUSFS_URL)" >> "$GITHUB_WORKSPACE/build_summary.md" cd "$GITHUB_WORKSPACE" else echo "- **SUSFS4KSU (v2.1.0)**: not present" >> build_summary.md fi echo "" >> build_summary.md # Add artifact summary with presence verification echo "## Build Artifacts" >> build_summary.md # Verify AnyKernel3 contents - check if kernel Image was actually copied (indicates successful build) if [ -d "AnyKernel3" ] && [ -f "AnyKernel3/Image" ]; then AK3_STATUS="✅" else AK3_STATUS="❌" fi echo "- **AnyKernel3**: $AK3_STATUS ${{ env.FILE_NAME }}-AnyKernel3" >> build_summary.md echo "### Misc (uploaded files)" >> build_summary.md FILES_PRESENT=0 for f in "${{ env.FILE_NAME }}-Image" "${{ env.FILE_NAME }}-Image.gz" "${{ env.FILE_NAME }}-Image.lz4" "${{ env.FILE_NAME }}-boot.img" "${{ env.FILE_NAME }}-boot-gz.img" "${{ env.FILE_NAME }}-boot-lz4.img"; do if [ -f "$f" ]; then FILES_PRESENT=$((FILES_PRESENT+1)); fi done if [ "$FILES_PRESENT" -gt 0 ]; then MISC_STATUS="✅" else MISC_STATUS="❌" fi echo "- **Set**: $MISC_STATUS ${{ env.FILE_NAME }}-Misc" >> build_summary.md if [ "$MISC_STATUS" = "✅" ]; then echo " Included:" >> build_summary.md for f in "${{ env.FILE_NAME }}-Image" "${{ env.FILE_NAME }}-Image.gz" "${{ env.FILE_NAME }}-Image.lz4" "${{ env.FILE_NAME }}-boot.img" "${{ env.FILE_NAME }}-boot-gz.img" "${{ env.FILE_NAME }}-boot-lz4.img"; do if [ -f "$f" ]; then echo " - $f" >> build_summary.md fi done fi echo "### Diagnostics" >> build_summary.md echo "- **Rejected Patches**: ${{ env.FILE_NAME }}-Rejected-Patches" >> build_summary.md if [ -f patch-rejects/index.txt ]; then if [ -s patch-rejects/index.txt ]; then echo " Rejected files:" >> build_summary.md while IFS= read -r line; do echo " - $line" >> build_summary.md done < patch-rejects/index.txt else echo " Rejected file list is empty." >> build_summary.md fi else echo " No rejected patches found." >> build_summary.md fi