Skip to content

ZTC Kernel Build (RL) #44

ZTC Kernel Build (RL)

ZTC Kernel Build (RL) #44

Workflow file for this run

name: ZTC Kernel Build (RL)
permissions:
contents: write # Allow writing to repository contents (for pushing tags)
actions: write # Allows triggering actions
on:
workflow_dispatch: # This allows this workflow to be called from another workflow
jobs:
build-ztckernel:
runs-on: ubuntu-latest
outputs:
# 输出1: KSU版本号
ksuVer: ${{ steps.get_version.outputs.kversion }}
# 输出2: SUSFS版本号
susVer: ${{ steps.get_version.outputs.sversion }}
env:
CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
CCACHE_NOHASHDIR: "true"
CCACHE_HARDLINK: "true"
steps:
- name: Set Swap Space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 16
- name: Maximize Build Space
uses: AdityaGarg8/remove-unwanted-software@v5
with:
remove-dotnet: 'true' # Frees ~2 GB
remove-android: 'true' # Frees ~9 GB
remove-haskell: 'true' # Frees ~5.2 GB
remove-codeql: 'true' # Frees ~5.4 GB
remove-docker-images: 'true' # Frees ~3.2 GB
remove-large-packages: 'true' # Frees ~3.1 GB
remove-swapfile: 'false' # Frees ~4 GB
remove-cached-tools: 'false' # Avoid unless confirmed safe
verbose: 'true' # Enable detailed logging
- name: 设定 CONFIG 环境变量
run: |
# Set CONFIG dynamically based on inputs values
CONFIG="android12-5.10-lts"
# Set CONFIG as an environment variable for future steps
echo "CONFIG=$CONFIG" >> $GITHUB_ENV
echo "CONFIG set to: $CONFIG"
# Install ccache
- name: 安装 依赖
run: sudo apt update && sudo apt upgrade -y && sudo apt install -y ccache python3 git curl build-essential libssl-dev bison flex libelf-dev dwarves
- name: 配置 ccache
run: |
mkdir -p ~/.cache/bazel
ccache --version
ccache --max-size=2G
ccache --set-config=compression=true
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
- name: 配置 Git
run: |
git config --global user.name "zzh20188"
git config --global user.email "BuildGkiKernel@gmail.com"
- name: 安装仓库
run: |
# Install dependencies
mkdir -p ./git-repo
curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
chmod a+rx ./git-repo/repo
echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
- name: 克隆 AnyKernel3 和其他依赖项
run: |
echo "Cloning AnyKernel3 and other dependencies..."
ANYKERNEL_BRANCH="gki-2.0"
SUSFS_BRANCH="gki-android12-5.10"
# Debug print the branches
echo "Using branch for SUSFS: $SUSFS_BRANCH"
# Clone repositories using the branch names
git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
git clone https://github.com/WildPlusKernel/kernel_patches.git
# Sukisu的补丁仓库
git clone https://github.com/ShirkNeko/SukiSU_patch.git
# next修复补丁
git clone https://github.com/zzh20188/GKI_KernelSU_SUSFS.git zzh_patch
- name: 设置 CONFIG 环境变量
run: |
# Set CONFIG dynamically based on inputs values
CONFIG="android12-5.10-lts"
# Set CONFIG as an environment variable for future steps
echo "CONFIG=$CONFIG" >> $GITHUB_ENV
echo "CONFIG set to: $CONFIG"
- name: 初始化和同步内核源代码
run: |
echo "Creating folder for configuration: $CONFIG..."
mkdir -p "$CONFIG"
cd "$CONFIG"
# Initialize and sync kernel source
echo "Initializing and syncing kernel source..."
FORMATTED_BRANCH="android12-5.10-lts"
$REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH}
REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
# Sync repo and apply patches
sed -i '/name="kernel\/common"/d' .repo/manifests/default.xml
$REPO --version
$REPO --trace sync -c -j$(nproc --all)
rm -rf common
git clone https://github.com/ztc1997/android_gki_kernel_5.10_common.git -b android12-5.10-2024-11 --depth=1 common
# git clone https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86 -b mirror-goog-main-llvm-toolchain-source --depth=1 clang
curl -LSs "https://github.com/zzh20188/ZTC-Kenel-Build/releases/download/clang/clang-r563880.tar.gz" -o clang-r563880.tar.gz
mkdir prebuilts-master/clang/host/linux-x86/clang-r563880
tar -xzvf clang-r563880.tar.gz -C prebuilts-master/clang/host/linux-x86/clang-r563880
# ln -s "$(pwd)/clang/clang-r563880" "$(pwd)/prebuilts-master/clang/host/linux-x86/clang-r563880"
cd common
sed -i 's|^CLANG_PREBUILT_BIN=.*|CLANG_PREBUILT_BIN=prebuilts-master/clang/host/linux-x86/clang-r563880/bin|' build.config.common
- name: 添加 KernelSU
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
curl -LSs "https://raw.githubusercontent.com/SukiSU-Ultra/SukiSU-Ultra/main/kernel/setup.sh" | bash -s susfs-main
cd ./KernelSU
sed -i 's|\$(shell cd \$(srctree)/\$(src); \$(GIT_BIN) rev-parse --short=8 HEAD)|酷安mkppk|g' ./kernel/Makefile
- name: 获取 KSU & SUSFS 版本
id: get_version
run: |
echo "This is the SukiSU variant"
git clone https://github.com/SukiSU-Ultra/SukiSU-Ultra.git KernelSU
VAR=700
cd KernelSU
# 计算KSU版本号
KSU_GIT_VERSION=$(git rev-list --count HEAD)
KSU_VERSION=$((10000 + KSU_GIT_VERSION + VAR))
echo $KSU_VERSION
echo "KSU_VERSION=$KSU_VERSION" >> $GITHUB_ENV
# 计算SUSFS版本号
INFO="https://gitlab.com/simonpunk/susfs4ksu/-/raw/gki-android14-6.1/ksu_module_susfs/module.prop\?ref_type\=heads"
SUS_VERSION=$(curl -s $INFO | awk -F '=' '$1 == "version" { print $2 }')
echo $SUS_VERSION
# 导出这两个值给release
echo "kversion=$KSU_VERSION" >> $GITHUB_OUTPUT
echo "sversion=$SUS_VERSION" >> $GITHUB_OUTPUT
- name: 为 KernelSU 变体安装 SUSFS 补丁
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
echo "Applying SUSFS patches..."
# Copy SUSFS patches
cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-android12-5.10.patch ./common/
cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
cd ./KernelSU
echo "Applying SukiSU specific SUSFS patch..."
cd ../common
patch -p1 --fuzz=3 < 50_add_susfs_in_gki-android12-5.10.patch || true
- name: 应用新的HOOKS补丁
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG/common"
echo "Applying hooks for SukiSU..."
cp ../../kernel_patches/next/scope_min_manual_hooks_v1.4.patch ./
patch -p1 -F 3 < scope_min_manual_hooks_v1.4.patch
- name: 应用隐藏某特征的补丁
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG/common"
# Apply additional patch
cp ../../SukiSU_patch/69_hide_stuff.patch ./
patch -p1 -F 3 < 69_hide_stuff.patch
- name: 添加SUSFS配置设置
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
# echo "CONFIG_CC_HAVE_SHADOW_CALL_STACK=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_CC_HAS_BRANCH_PROT_PAC_RET=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_CC_HAS_SIGN_RETURN_ADDRESS=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_AS_HAS_CFI_NEGATE_RA_STATE=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_CC_HAS_BRANCH_PROT_PAC_RET_BTI=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_ARM64_AS_HAS_MTE=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_ARM64_MTE=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_CC_HAVE_STACKPROTECTOR_SYSREG=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_ARCH_SUPPORTS_SHADOW_CALL_STACK=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_SHADOW_CALL_STACK=y" >> ./common/arch/arm64/configs/gki_defconfig
# # clang
# echo "CONFIG_LTO=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_LTO_CLANG=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_HAS_LTO_CLANG=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_LTO_CLANG_FULL=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_CFI_CLANG=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_CFI_CLANG_SHADOW=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_TRIM_UNUSED_KSYMS=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_ARCH_USES_HIGH_VMA_FLAGS=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_HAVE_ARCH_KASAN_HW_TAGS=y" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_KASAN_HW_TAGS=y" >> ./common/arch/arm64/configs/gki_defconfig
# # MTK
# echo "CONFIG_MEDIATEK_CPUFREQ_DEBUG=m" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_MTK_IPI=m" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_MTK_TINYSYS_MCUPM_SUPPORT=m" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_MTK_MBOX=m" >> ./common/arch/arm64/configs/gki_defconfig
# echo "CONFIG_RPMSG_MTK=m" >> ./common/arch/arm64/configs/gki_defconfig
# 以上和此处是关闭一些疑似导致自动重启的配置
echo "Adding configuration settings to gki_defconfig..."
# Add KSU configuration settings
echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KPM=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_MANUAL_HOOK=y" >> ./common/arch/arm64/configs/gki_defconfig
# Add SUSFS configuration settings
echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
# Remove check_defconfig
sed -i 's/check_defconfig//' ./common/build.config.gki
# 用于debug config
tail -n 60 ./common/arch/arm64/configs/gki_defconfig
- name: 配置内核构时间/删除dirty字符
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
echo "5系:删除dirty字符串"
sed -i 's/-dirty//' ./common/scripts/setlocalversion
- name: Build with retry
run: |
set -e
set -x
cd "$CONFIG"
echo "Building the kernel..."
LTO=full BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh CC=clang || exit 1
- name: 修补 Image 文件 安卓12和安卓13(仅限sukisu)
run: |
echo "Patching Image file..."
cd "$CONFIG/out/android12-5.10/dist"
strings Image | grep "Linux version"
curl -LSs "https://raw.githubusercontent.com/ShirkNeko/SukiSU_patch/refs/heads/main/kpm/patch_linux" -o patch
chmod 777 patch
./patch
rm -rf Image
mv oImage Image
- name: 创建Bootimgs文件夹并复制镜像
run: |
echo "更改为配置目录: $CONFIG..."
mkdir bootimgs
echo "Creating bootimgs folder and copying images..."
cp ./$CONFIG/out/android12-5.10/dist/Image ./bootimgs
cp ./$CONFIG/out/android12-5.10/dist/Image.lz4 ./bootimgs
cp ./$CONFIG/out/android12-5.10/dist/Image ./
cp ./$CONFIG/out/android12-5.10/dist/Image.lz4 ./
# Create gzip of the Image file
gzip -n -k -f -9 ./Image > ./Image.gz
- name: 创建不同格式的ZIP文件
run: |
echo "Creating zip files for all formats..."
cd ./AnyKernel3
# Create and upload zip for each format
ZIP_NAME="ZTC-AnyKernel3.zip"
echo "Creating zip file: $ZIP_NAME..."
mv ../Image ./Image
- name: 添加 KernelSU
id: add_KSU
continue-on-error: true
run: |
echo "SukiSU..."
REPO="SukiSU-Ultra/SukiSU-Ultra"
FILENAME="build-manager.yml"
KSUM="manager"
# 初始化
NUMBER=0
DOWNLOAD_URL=""
echo "开始查找包含 'manager' 产物的构建..."
while true; do
echo "--------------------------------------------------"
echo "正在检查第 ${NUMBER} 个历史构建 (0代表最新)..."
if [ "$NUMBER" -ge 9 ]; then
echo "查找九次仍然失败,跳出循环。"
break
fi
# 1. 获取指定顺序的成功构建的ID
BUILD_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$REPO/actions/workflows/$FILENAME/runs?status=success" |
jq -r '.workflow_runs['"$NUMBER"'].id')
echo "找到构建 ID: $BUILD_ID"
ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$REPO/actions/runs/$BUILD_ID/artifacts")
result=$(echo "$ARTIFACTS" | jq -r '.artifacts[] | select(.name | contains("'"$KSUM"'")) | .name')
if [ -z "$result" ]; then
echo "没有找到包含 '$KSUM' 的项"
NUMBER=$((NUMBER + 1))
else
echo "$result"
DOWNLOAD_URL=$(echo "$ARTIFACTS" | jq -r '.artifacts[] | select(.name == "'"$KSUM"'") | .archive_download_url')
break
fi
done
# 下载 Manager 文件
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o "SUKISU-管理器(${{ env.KSU_VERSION }}).zip" "$DOWNLOAD_URL"
echo "Manager 文件已下载为:SUKISU-管理器(${{ env.KSU_VERSION }}).zip"
unzip *.zip
rm -rf *.zip
- name: 添加 SUSFS 模块
id: add_SUSFS
continue-on-error: true
run: |
BUILD_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/sidex15/susfs4ksu-module/actions/workflows/build.yml/runs?status=success" |
jq -r '.workflow_runs[0].id')
ARTIFACTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/sidex15/susfs4ksu-module/actions/runs/$BUILD_ID/artifacts")
DOWNLOAD_URL=$(echo "$ARTIFACTS" | jq -r '.artifacts[0].archive_download_url')
NAME=$(echo "$ARTIFACTS" | jq -r '.artifacts[0].name')
echo "SUSFS_NAME=$NAME" >> $GITHUB_ENV
NAME="susfs-$NAME.zip"
echo $DOWNLOAD_URL
echo $NAME
# 下载 Manager 文件
curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -o "$NAME" "$DOWNLOAD_URL"
echo "$NAME 文件已下载.zip"
echo "正在检查调用者: ${{ github.caller_workflow }}"
# 由用户调用或是由作者上传到release?
if [ "${{ github.workflow }}" == "ZTC Kernel Build (RL)" ]; then
echo "这是发布工作流"
mkdir -p susfs-module && mv $NAME susfs-module
else
echo "这是其他工作流"
mkdir -p susfs-module && unzip *.zip -d susfs-module
fi
- name: 上传编译资产 (仅 AK3)
uses: actions/upload-artifact@v4
with:
name: 5.10.226(${{ env.KSU_VERSION }})_Anykernel3
path: ./AnyKernel3/*
- name: 上传APK
uses: actions/upload-artifact@v4
with:
name: Sukisu-Manager(${{ env.KSU_VERSION }})
path: |
*.apk
- name: 上传SUSFS模块
uses: actions/upload-artifact@v4
with:
name: susfs-${{ env.SUSFS_NAME }}
path: ./susfs-module/*
trigger-release:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
needs:
- build-ztckernel
env:
REPO_OWNER: zzh20188
REPO_NAME: ZTC-Kernel-Build
RELEASE_NAME: "ZTC内核: SukiSU(${{ needs.build-ztckernel.outputs.ksuVer }}) & SUSFS ${{ needs.build-ztckernel.outputs.susVer }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NOTES: |
功能:
-> ZTC-Kernel 5.10.226
-> SukiSU(${{ needs.build-ztckernel.outputs.ksuVer }})
-> SUSFS ඞ ${{ needs.build-ztckernel.outputs.susVer }}
-> VFS Hooks v1.4
-> Magic Mount 支持
-> LineageOS 检测对抗
-> jit-zygote-cache 检测对抗
-> KPM 支持
点击下方 **【Assets】** 展开资源,底部还包含最新 **KSU管理器、CI构建SUSFS模块**
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Get the Latest Tag from GitHub
- name: 生成和创建新标签
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Fetch the latest tag from GitHub (this is the latest tag based on the GitHub API)
SUS_VERSION=${{ needs.build-ztckernel.outputs.susVer }}
LATEST_TAG=$(gh api repos/$REPO_OWNER/$REPO_NAME/tags --jq '.[0].name'| sed 's/-.*//')
echo $SUS_VERSION
echo $LATEST_TAG
# 判断是否相等
if [ "$SUS_VERSION" = "$LATEST_TAG" ]; then
echo "版本相等"
LATEST_TAG=$(gh api repos/$REPO_OWNER/$REPO_NAME/tags --jq '.[0].name')
else
echo "版本不相等"
LATEST_TAG="$SUS_VERSION-r0"
fi
NEW_TAG=$(echo "$LATEST_TAG" | awk -F'-r' '{suffix=$2; if (!suffix) suffix=0; suffix++; printf "%s-r%d", $1, suffix}')
# Output the new tag to be used
echo "New tag: $NEW_TAG"
# Set the new tag as an environment variable to be used in later steps
echo "NEW_TAG=${NEW_TAG}" >> $GITHUB_ENV
# Create the tag in the repository
git tag $NEW_TAG
git push --tags
# 下载 A12 的附件(仅当 A12 生成成功或输入为 true 或为空时)
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: ./downloaded-artifacts
# 如果 make_release 为 true,则创建 GitHub 发布并上传文件
- name: Create GitHub Release
uses: actions/create-release@v1
with:
tag_name: ${{ env.NEW_TAG }} # Use the generated tag for the release
prerelease: true # Mark the release as a pre-release
release_name: ${{ env.RELEASE_NAME }} # Pass the RELEASE_NAME to the action
body: ${{ env.RELEASE_NOTES }} # Pass the RELEASE_NOTES to the action
- name: 上传KSU管理器 & SUS模块
continue-on-error: true
run: |
echo "Uploading KSU管理器"
gh release upload ${{ env.NEW_TAG }} "./downloaded-artifacts/*Manager*/*"
gh release upload ${{ env.NEW_TAG }} "./downloaded-artifacts/susfs-*/*"
- name: 动态上传发布资产
run: |
ls -al ./downloaded-artifacts
echo "Uploading $file..."
cd ./downloaded-artifacts/*Anykernel3
zip -r -9 ./ZTC-KERNEL-ANYKERNEL3.zip .
gh release upload ${{ env.NEW_TAG }} ./ZTC-KERNEL-ANYKERNEL3.zip
# Display Files Uploaded
- name: Display Files Uploaded
run: |
echo "GitHub release created with the following files:"
ls ./downloaded-artifacts/**/*