From 7b89ec89c0482053425c15e47279ae054cdfcf4d Mon Sep 17 00:00:00 2001 From: 5ec1cff <56485584+5ec1cff@users.noreply.github.com> Date: Thu, 29 Feb 2024 17:36:38 +0800 Subject: [PATCH] ci: support android 14 AVD (#1405) --- .github/manifests/android-14-avd.xml | 71 +++++++++ .github/workflows/avd-kernel.yml | 168 +++++++++++++++++++++ .github/workflows/build-kernel-a14-avd.yml | 27 ++++ 3 files changed, 266 insertions(+) create mode 100644 .github/manifests/android-14-avd.xml create mode 100644 .github/workflows/avd-kernel.yml create mode 100644 .github/workflows/build-kernel-a14-avd.yml diff --git a/.github/manifests/android-14-avd.xml b/.github/manifests/android-14-avd.xml new file mode 100644 index 00000000..db2a6c06 --- /dev/null +++ b/.github/manifests/android-14-avd.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.github/workflows/avd-kernel.yml b/.github/workflows/avd-kernel.yml new file mode 100644 index 00000000..d53722db --- /dev/null +++ b/.github/workflows/avd-kernel.yml @@ -0,0 +1,168 @@ +name: GKI Kernel Build + +on: + workflow_call: + inputs: + version_name: + required: true + type: string + description: > + With SUBLEVEL of kernel, + for example: android12-5.10.66 + debug: + required: false + type: boolean + default: true + manifest_name: + required: false + type: string + description: > + Local repo manifest xml path, + typically for AVD kernel build. + secrets: + BOOT_SIGN_KEY: + required: false + CHAT_ID: + required: false + BOT_TOKEN: + required: false + MESSAGE_THREAD_ID: + required: false + +jobs: + build: + name: Build ${{ inputs.version_name }} + runs-on: ubuntu-latest + env: + CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion" + CCACHE_NOHASHDIR: "true" + CCACHE_HARDLINK: "true" + steps: + - name: Maximize build space + uses: easimon/maximize-build-space@master + with: + root-reserve-mb: 8192 + temp-reserve-mb: 2048 + remove-dotnet: 'true' + remove-android: 'true' + remove-haskell: 'true' + remove-codeql: 'true' + + - uses: actions/checkout@v4 + with: + path: KernelSU + fetch-depth: 0 + + - name: Setup need_upload + id: need_upload + run: | + if [ ! -z "${{ secrets.BOT_TOKEN }}" ]; then + echo "UPLOAD=true" >> $GITHUB_OUTPUT + else + echo "UPLOAD=false" >> $GITHUB_OUTPUT + fi + + - name: Setup kernel source + run: | + echo "Free space:" + df -h + cd $GITHUB_WORKSPACE + sudo apt-get install repo -y + mkdir android-kernel && cd android-kernel + repo init --depth=1 -u "$GITHUB_WORKSPACE/KernelSU" -b main -m ".github/manifests/${{ inputs.manifest_name }}" --repo-rev=v2.16 + repo --version + repo --trace sync -c -j$(nproc --all) --no-tags + df -h + + - name: Setup KernelSU + env: + PATCH_PATH: ${{ inputs.patch_path }} + IS_DEBUG_KERNEL: ${{ inputs.debug }} + run: | + cd $GITHUB_WORKSPACE/android-kernel + echo "[+] KernelSU setup" + GKI_ROOT=$(pwd) + echo "[+] GKI_ROOT: $GKI_ROOT" + echo "[+] Copy KernelSU driver to $GKI_ROOT/common/drivers" + ln -sf $GITHUB_WORKSPACE/KernelSU/kernel $GKI_ROOT/common/drivers/kernelsu + echo "[+] Add KernelSU driver to Makefile" + DRIVER_MAKEFILE=$GKI_ROOT/common/drivers/Makefile + grep -q "kernelsu" $DRIVER_MAKEFILE || echo "obj-y += kernelsu/" >> $DRIVER_MAKEFILE + echo "[+] Apply KernelSU patches" + cd $GKI_ROOT/common/ && git apply $GITHUB_WORKSPACE/KernelSU/.github/patches/$PATCH_PATH/*.patch || echo "[-] No patch found" + + if [ "$IS_DEBUG_KERNEL" = "true" ]; then + echo "[+] Enable debug features for kernel" + echo "ccflags-y += -DCONFIG_KSU_DEBUG" >> $GITHUB_WORKSPACE/KernelSU/kernel/Makefile + fi + repo status + echo "[+] KernelSU setup done." + cd $GITHUB_WORKSPACE/KernelSU + VERSION=$(($(git rev-list --count HEAD) + 10200)) + echo "VERSION: $VERSION" + echo "kernelsu_version=$VERSION" >> $GITHUB_ENV + + - name: Setup ccache + if: inputs.use_cache == true + uses: hendrikmuhs/ccache-action@v1.2 + with: + key: gki-kernel-x86_64-avd-${{ inputs.version_name }} + max-size: 2G + save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + + - name: Make working directory clean to avoid dirty + working-directory: android-kernel + run: | + rm common/android/abi_gki_protected_exports_* || echo "No protected exports!" + git config --global user.email "bot@kernelsu.org" + git config --global user.name "KernelSUBot" + cd common/ && git add -A && git commit -a -m "Add KernelSU" + repo status + + - name: Build kernel + working-directory: android-kernel + run: | + if [ ! -z ${{ vars.EXPECTED_SIZE }} ] && [ ! -z ${{ vars.EXPECTED_HASH }} ]; then + export KSU_EXPECTED_SIZE=${{ vars.EXPECTED_SIZE }} + export KSU_EXPECTED_HASH=${{ vars.EXPECTED_HASH }} + fi + tools/bazel run --disk_cache=/home/runner/.cache/bazel --config=fast --config=stamp --lto=thin //common-modules/virtual-device:virtual_device_x86_64_dist -- --dist_dir=dist + NAME=kernel-x86_64-avd-${{ inputs.version_name }}-${{ env.kernelsu_version }} + mv dist/bzImage $NAME + echo "file_path=android-kernel/$NAME" >> $GITHUB_ENV + + - name: Upload Kernel + uses: actions/upload-artifact@v4 + with: + name: kernel-x86_64-avd-${{ inputs.version_name }}-${{ env.kernelsu_version }} + path: "${{ env.file_path }}" + + - name: Bot session cache + if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.ref_type == 'tag' + id: bot_session_cache + uses: actions/cache@v3 + with: + path: scripts/ksubot.session + key: ${{ runner.os }}-bot-session + + - name: Post to Telegram + if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.ref_type == 'tag' + env: + CHAT_ID: ${{ secrets.CHAT_ID }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + MESSAGE_THREAD_ID: ${{ secrets.MESSAGE_THREAD_ID }} + COMMIT_MESSAGE: ${{ github.event.head_commit.message }} + COMMIT_URL: ${{ github.event.head_commit.url }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + TITLE=kernel-x86_64-avd-${{ inputs.version_name }} + echo "[+] title: $TITLE" + export TITLE + export VERSION="${{ env.kernelsu_version }}" + echo "[+] Image to upload" + ls -l "${{ env.file_path }}" + if [ -n "${{ secrets.BOT_TOKEN }}" ]; then + pip3 install telethon==1.31.1 + python3 "$GITHUB_WORKSPACE/KernelSU/scripts/ksubot.py" "${{ env.file_path }}" + fi + diff --git a/.github/workflows/build-kernel-a14-avd.yml b/.github/workflows/build-kernel-a14-avd.yml new file mode 100644 index 00000000..ce8d0372 --- /dev/null +++ b/.github/workflows/build-kernel-a14-avd.yml @@ -0,0 +1,27 @@ +name: Build Kernel - Android 14 AVD +on: + push: + branches: ["main", "ci", "checkci"] + paths: + - ".github/workflows/build-kernel-a14.yml" + - ".github/workflows/avd-kernel.yml" + - ".github/workflows/manifests/android-14-avd.xml" + - "kernel/**" + pull_request: + branches: ["main"] + paths: + - ".github/workflows/build-kernel-a14-avd.yml" + - ".github/workflows/avd-kernel.yml" + - ".github/workflows/manifests/android-14-avd.xml" + - "kernel/**" + workflow_call: + workflow_dispatch: +jobs: + build-kernel: + if: github.event_name != 'pull_request' && github.ref != 'refs/heads/checkci' + uses: ./.github/workflows/avd-kernel.yml + secrets: inherit + with: + version_name: android-14 + manifest_name: android-14-avd.xml + debug: true