Skip to content

Commit

Permalink
CI: Opt (xiaoleGun#166)
Browse files Browse the repository at this point in the history
* fixup! CI: Do not remove the KernelSU repository included in kernel source

* CI: Fix typo

* CI: Use loops to execute repetitive statements

* Improve code readability and maintainability
  • Loading branch information
bxySo authored Jun 28, 2024
1 parent 1d62daf commit 20fadd0
Showing 1 changed file with 57 additions and 49 deletions.
106 changes: 57 additions & 49 deletions .github/workflows/build-kernel.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Build Kernel
on:

workflow_dispatch:

jobs:
Expand All @@ -15,47 +14,57 @@ jobs:
- uses: actions/checkout@v4
- name: Prepare Configuration
run: |
CONFIG_ENV=$(cat config.env | grep -w "CONFIG_ENV" | head -n 1 | cut -d "=" -f 2)
echo "KERNEL_SOURCE=$(cat $CONFIG_ENV | grep -w "KERNEL_SOURCE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "KERNEL_SOURCE_BRANCH=$(cat $CONFIG_ENV | grep -w "KERNEL_SOURCE_BRANCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "KERNEL_CONFIG=$(cat $CONFIG_ENV | grep -w "KERNEL_CONFIG" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "KERNEL_IMAGE_NAME=$(cat $CONFIG_ENV | grep -w "KERNEL_IMAGE_NAME" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ARCH=$(cat $CONFIG_ENV | grep -w "ARCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ADD_LOCALVERSION_TO_FILENAME=$(cat $CONFIG_ENV | grep -w "ADD_LOCALVERSION_TO_FILENAME" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "EXTRA_CMDS=$(cat $CONFIG_ENV | grep -w "EXTRA_CMDS" | head -n 1 | cut -d ":" -f 2)" >> $GITHUB_ENV
echo "USE_CUSTOM_CLANG=$(cat $CONFIG_ENV | grep -w "USE_CUSTOM_CLANG" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_CLANG_SOURCE=$(cat $CONFIG_ENV | grep -w "CUSTOM_CLANG_SOURCE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_CLANG_BRANCH=$(cat $CONFIG_ENV | grep -w "CUSTOM_CLANG_BRANCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_CMDS=$(cat $CONFIG_ENV | grep -w "CUSTOM_CMDS" | head -n 1 | cut -d ":" -f 2)" >> $GITHUB_ENV
echo "CLANG_BRANCH=$(cat $CONFIG_ENV | grep -w "CLANG_BRANCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CLANG_VERSION=$(cat $CONFIG_ENV | grep -w "CLANG_VERSION" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ENABLE_GCC_ARM64=$(cat $CONFIG_ENV | grep -w "ENABLE_GCC_ARM64" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ENABLE_GCC_ARM32=$(cat $CONFIG_ENV | grep -w "ENABLE_GCC_ARM32" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "USE_CUSTOM_GCC_64=$(cat $CONFIG_ENV | grep -w "USE_CUSTOM_GCC_64" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_GCC_64_SOURCE=$(cat $CONFIG_ENV | grep -w "CUSTOM_GCC_64_SOURCE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_GCC_64_BRANCH=$(cat $CONFIG_ENV | grep -w "CUSTOM_GCC_64_BRANCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_GCC_64_BIN=$(cat $CONFIG_ENV | grep -w "CUSTOM_GCC_64_BIN" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "USE_CUSTOM_GCC_32=$(cat $CONFIG_ENV | grep -w "USE_CUSTOM_GCC_32" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_GCC_32_SOURCE=$(cat $CONFIG_ENV | grep -w "CUSTOM_GCC_32_SOURCE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_GCC_32_BRANCH=$(cat $CONFIG_ENV | grep -w "CUSTOM_GCC_32_BRANCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_GCC_32_BIN=$(cat $CONFIG_ENV | grep -w "CUSTOM_GCC_32_BIN" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ENABLE_KERNELSU=$(cat $CONFIG_ENV | grep -w "ENABLE_KERNELSU" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "KERNELSU_TAG=$(cat $CONFIG_ENV | grep -w "KERNELSU_TAG" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ADD_KPROBES_CONFIG=$(cat $CONFIG_ENV | grep -w "ADD_KPROBES_CONFIG" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "DISABLE-LTO=$(cat $CONFIG_ENV | grep -w "DISABLE-LTO" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ADD_OVERLAYFS_CONFIG=$(cat $CONFIG_ENV | grep -w "ADD_OVERLAYFS_CONFIG" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "DISABLE_CC_WERROR=$(cat $CONFIG_ENV | grep -w "DISABLE_CC_WERROR" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "APPLY_KSU_PATCH=$(cat $CONFIG_ENV | grep -w "APPLY_KSU_PATCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "USE_CUSTOM_ANYKERNEL3=$(cat $CONFIG_ENV | grep -w "USE_CUSTOM_ANYKERNEL3" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_ANYKERNEL3_SOURCE=$(cat $CONFIG_ENV | grep -w "CUSTOM_ANYKERNEL3_SOURCE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "CUSTOM_ANYKERNEL3_BRANCH=$(cat $CONFIG_ENV | grep -w "CUSTOM_ANYKERNEL3_BRANCH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "ENABLE_CCACHE=$(cat $CONFIG_ENV | grep -w "ENABLE_CCACHE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "NEED_DTBO=$(cat $CONFIG_ENV | grep -w "NEED_DTBO" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "BUILD_BOOT_IMG=$(cat $CONFIG_ENV | grep -w "BUILD_BOOT_IMG" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "SOURCE_BOOT_IMAGE=$(cat $CONFIG_ENV | grep -w "SOURCE_BOOT_IMAGE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "KSU_EXPECTED_SIZE=$(cat $CONFIG_ENV | grep -w "KSU_EXPECTED_SIZE" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "KSU_EXPECTED_HASH=$(cat $CONFIG_ENV | grep -w "KSU_EXPECTED_HASH" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
echo "REMOVE_UNUSED_PACKAGES=$(cat $CONFIG_ENV | grep -w "REMOVE_UNUSED_PACKAGES" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
CONFIG_ENV=$(grep -w "CONFIG_ENV" config.env | head -n 1 | cut -d "=" -f 2)
CONFIG_LIST=(
KERNEL_SOURCE
KERNEL_SOURCE_BRANCH
KERNEL_CONFIG
KERNEL_IMAGE_NAME
ARCH
ADD_LOCALVERSION_TO_FILENAME
EXTRA_CMDS
USE_CUSTOM_CLANG
CUSTOM_CLANG_SOURCE
CUSTOM_CLANG_BRANCH
CUSTOM_CMDS
CLANG_BRANCH
CLANG_VERSION
ENABLE_GCC_ARM64
ENABLE_GCC_ARM32
USE_CUSTOM_GCC_64
CUSTOM_GCC_64_SOURCE
CUSTOM_GCC_64_BRANCH
CUSTOM_GCC_64_BIN
USE_CUSTOM_GCC_32
CUSTOM_GCC_32_SOURCE
CUSTOM_GCC_32_BRANCH
CUSTOM_GCC_32_BIN
ENABLE_KERNELSU
KERNELSU_TAG
ADD_KPROBES_CONFIG
DISABLE-LTO
ADD_OVERLAYFS_CONFIG
DISABLE_CC_WERROR
APPLY_KSU_PATCH
USE_CUSTOM_ANYKERNEL3
CUSTOM_ANYKERNEL3_SOURCE
CUSTOM_ANYKERNEL3_BRANCH
ENABLE_CCACHE
NEED_DTBO
BUILD_BOOT_IMG
SOURCE_BOOT_IMAGE
KSU_EXPECTED_SIZE
KSU_EXPECTED_HASH
REMOVE_UNUSED_PACKAGES
)
for CONFIG in "${CONFIG_LIST[@]}"; do
if [[ "$CONFIG" == "EXTRA_CMDS" || "$CONFIG" == "CUSTOM_CMDS" ]]; then
echo "$CONFIG=$(grep -w "$CONFIG" "$CONFIG_ENV" | head -n 1 | cut -d ":" -f 2)" >> $GITHUB_ENV
else
echo "$CONFIG=$(grep -w "$CONFIG" "$CONFIG_ENV" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
fi
done
- name: Remove unused packages
if: env.REMOVE_UNUSED_PACKAGES == 'true'
Expand Down Expand Up @@ -101,7 +110,7 @@ jobs:
tar -C clang-aosp/ -zxvf clang.tar.gz
else
git clone ${{ env.CUSTOM_CLANG_SOURCE }} -b ${{ env.CUSTOM_CLANG_BRANCH }} clang-aosp --depth=1
fi
fi
else
wget -O clang.zip ${{ env.CUSTOM_CLANG_SOURCE }}
mkdir clang-aosp
Expand Down Expand Up @@ -133,7 +142,7 @@ jobs:
if [ ${{ env.USE_CUSTOM_GCC_64 }} = true ]; then
if [[ ${{ env.CUSTOM_GCC_64_SOURCE }} =~ git ]]; then
if [[ ${{ env.CUSTOM_GCC_64_SOURCE }} == *'.tar.gz' ]]; then
wget -O gcc-64.tar.gz ${{ env.CUSTOM_CLANG_SOURCE }}
wget -O gcc-64.tar.gz ${{ env.CUSTOM_GCC_64_SOURCE }}
mkdir gcc-64
tar -C gcc-64/ -zxvf gcc-64.tar.gz
else
Expand All @@ -150,7 +159,7 @@ jobs:
if [ ${{ env.USE_CUSTOM_GCC_32 }} = true ]; then
if [[ ${{ env.CUSTOM_GCC_32_SOURCE }} =~ git ]]; then
if [[ ${{ env.CUSTOM_GCC_32_SOURCE }} == *'.tar.gz' ]]; then
wget -O gcc-32.tar.gz ${{ env.CUSTOM_CLANG_SOURCE }}
wget -O gcc-32.tar.gz ${{ env.CUSTOM_GCC_32_SOURCE }}
mkdir gcc-32
tar -C gcc-32/ -zxvf gcc-32.tar.gz
else
Expand Down Expand Up @@ -189,12 +198,11 @@ jobs:
echo "FORMAT_MKBOOTING=$(echo `tools/unpack_bootimg.py --boot_img=boot-source.img --format mkbootimg`)" >> $GITHUB_ENV
echo "HAVE_SOURCE_BOOT_IMAGE=true" >> $GITHUB_ENV
fi
- name: Setup KernelSU
if: env.ENABLE_KERNELSU == 'true'
run: |
cd $GITHUB_WORKSPACE/kernel_workspace/android-kernel
rm -rf KernelSU drivers/kernelsu
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s ${{ env.KERNELSU_TAG }}
KSU_VERSION=$(cd KernelSU && expr $(/usr/bin/git rev-list --count HEAD) + 10200)
echo "UPLOADNAME=-KernelSU_$KSU_VERSION" >> $GITHUB_ENV
Expand Down Expand Up @@ -271,7 +279,7 @@ jobs:
exit 1
fi
fi
- name: Make Anykernel3
if: env.CHECK_FILE_IS_OK == 'true' && env.USE_CUSTOM_ANYKERNEL3 != 'true'
run: |
Expand Down Expand Up @@ -322,7 +330,7 @@ jobs:
echo "Boot image is empty"
exit 1
fi
- name: Upload ${{ env.KERNEL_IMAGE_NAME }}
if: env.CHECK_FILE_IS_OK == 'true'
uses: actions/upload-artifact@v4
Expand Down

0 comments on commit 20fadd0

Please sign in to comment.