From 3d35845df35ea54897b36c0c008de96d31623fce Mon Sep 17 00:00:00 2001 From: 5ec1cff Date: Mon, 27 Jan 2025 14:09:45 +0800 Subject: [PATCH] ci: build lkm only if needed while building manager --- .github/workflows/build-lkm.yml | 33 ++++++----- .github/workflows/build-manager.yml | 72 ++++++++++++++++++++++++ .github/workflows/gki-kernel-mock.yml | 79 +++++++++++++++++++++++++++ .github/workflows/ksud.yml | 21 +++++-- 4 files changed, 188 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/gki-kernel-mock.yml diff --git a/.github/workflows/build-lkm.yml b/.github/workflows/build-lkm.yml index 5798b897..bfe0e904 100644 --- a/.github/workflows/build-lkm.yml +++ b/.github/workflows/build-lkm.yml @@ -1,17 +1,23 @@ name: Build LKM for KernelSU on: - push: - branches: ["main", "ci", "checkci"] - paths: - - ".github/workflows/build-lkm.yml" - - 'kernel/**' - pull_request: - branches: ["main"] - paths: - - ".github/workflows/build-lkm.yml" - - 'kernel/**' workflow_call: + inputs: + upload: + required: false + type: boolean + default: false + description: "Whether to upload to branch" + secrets: + # username:github_pat + TOKEN: + required: true workflow_dispatch: + inputs: + upload: + required: false + type: boolean + default: false + description: "Whether to upload to branch" jobs: build-lkm: strategy: @@ -35,6 +41,7 @@ jobs: - version: "android15-6.6" sub_level: 57 os_patch_level: 2024-12 + # uses: ./.github/workflows/gki-kernel-mock.yml when debugging uses: ./.github/workflows/gki-kernel.yml with: version: ${{ matrix.version }} @@ -43,10 +50,10 @@ jobs: os_patch_level: ${{ matrix.os_patch_level }} build_lkm: true - push-to-branch: needs: [build-lkm] runs-on: ubuntu-latest + if: ${{ inputs.upload }} steps: - name: Download all workflow run artifacts uses: actions/download-artifact@v4 @@ -58,10 +65,10 @@ jobs: cd bin git config --global init.defaultBranch lkm git init - git remote add origin https://${{ github.actor }}:${{ secrets.TOKEN }}@github.com/${{ github.repository }} + git remote add origin https://${{ secrets.TOKEN }}@github.com/${{ github.repository }} git config --local user.name "github-actions[bot]" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" find . -type f git add . - git commit -m "Upload LKM" + git commit -m "Upload LKM from ${{ github.sha }}" -m "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" git push --force --set-upstream origin lkm diff --git a/.github/workflows/build-manager.yml b/.github/workflows/build-manager.yml index 7f69f02f..672a8b7a 100644 --- a/.github/workflows/build-manager.yml +++ b/.github/workflows/build-manager.yml @@ -12,9 +12,79 @@ on: paths: - 'manager/**' workflow_call: + workflow_dispatch: + inputs: + build_lkm: + required: true + type: choice + default: "auto" + options: + - "true" + - "false" + - "auto" + description: "Whether to build lkm" + upload_lkm: + required: true + type: boolean + default: false + description: "Whether to upload lkm" jobs: + check-build-lkm: + runs-on: ubuntu-latest + outputs: + build_lkm: ${{ steps.check-build.outputs.build_lkm }} + upload_lkm: ${{ steps.check-build.outputs.upload_lkm }} + steps: + - name: check build + id: check-build + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ "${{ inputs.build_lkm }}" != "auto" ]; then + kernel_changed="${{ inputs.build_lkm }}" + else + kernel_changed=true + mkdir tmp + cd tmp + git config --global init.defaultBranch bot + git config --global user.name 'Bot' + git config --global user.email 'bot@github.5ec1cff.io' + git init . + git remote add origin https://github.com/${{ github.repository }} + CURRENT_COMMIT="${{ github.event.head_commit.id }}" + git fetch origin $CURRENT_COMMIT --depth=1 + git fetch origin lkm --depth=1 + LKM_COMMIT="$(git log --format=%B -n 1 origin/lkm | head -n 1)" + LKM_COMMIT="${LKM_COMMIT#Upload LKM from }" + LKM_COMMIT=$(echo "$LKM_COMMIT" | tr -d '[:space:]') + echo "LKM_COMMIT=$LKM_COMMIT" + git fetch origin "$LKM_COMMIT" --depth=1 + git diff --quiet "$LKM_COMMIT" "$CURRENT_COMMIT" -- kernel :!kernel/setup.sh .github/workflows/build-lkm.yml .github/workflows/build-kernel-*.yml && kernel_changed=false + cd .. + rm -rf tmp + fi + if [ "${{ github.event_name }}" == "push" ] && [ "${{ github.ref }}" == 'refs/heads/main' ]; then + need_upload=true + elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + need_upload="${{ inputs.upload_lkm }}" + else + need_upload=false + fi + echo "kernel changed: $kernel_changed" + echo "need upload: $need_upload" + echo "build_lkm=$kernel_changed" >> "$GITHUB_OUTPUT" + echo "upload_lkm=$need_upload" >> "$GITHUB_OUTPUT" + + build-lkm: + needs: check-build-lkm + uses: ./.github/workflows/build-lkm.yml + if: ${{ needs.check-build-lkm.outputs.build_lkm == 'true' }} + with: + upload: ${{ needs.check-build-lkm.outputs.upload_lkm == 'true' }} + secrets: inherit + build-ksud: + if: ${{ always() }} + needs: [ check-build-lkm, build-lkm ] strategy: matrix: include: @@ -27,8 +97,10 @@ jobs: target: ${{ matrix.target }} os: ${{ matrix.os }} pack_lkm: true + pull_lkm: ${{ needs.check-build-lkm.outputs.build_lkm != 'true' }} build-manager: + if: ${{ always() }} needs: build-ksud runs-on: ubuntu-latest defaults: diff --git a/.github/workflows/gki-kernel-mock.yml b/.github/workflows/gki-kernel-mock.yml new file mode 100644 index 00000000..205d1d0e --- /dev/null +++ b/.github/workflows/gki-kernel-mock.yml @@ -0,0 +1,79 @@ +name: GKI Kernel Build + +on: + workflow_call: + inputs: + version: + required: true + type: string + description: > + Output directory of gki, + for example: android12-5.10 + version_name: + required: true + type: string + description: > + With SUBLEVEL of kernel, + for example: android12-5.10.66 + tag: + required: true + type: string + description: > + Part of branch name of common kernel manifest, + for example: android12-5.10-2021-11 + os_patch_level: + required: false + type: string + description: > + Patch level of common kernel manifest, + for example: 2021-11 + default: 2022-05 + patch_path: + required: false + type: string + description: > + Directory name of .github/patches/ + for example: 5.10 + use_cache: + required: false + type: boolean + default: true + embed_ksud: + required: false + type: string + default: ksud-aarch64-linux-android + description: > + Artifact name of prebuilt ksud to be embedded + for example: ksud-aarch64-linux-android + debug: + required: false + type: boolean + default: false + build_lkm: + required: false + type: boolean + default: false + secrets: + BOOT_SIGN_KEY: + required: false + CHAT_ID: + required: false + BOT_TOKEN: + required: false + MESSAGE_THREAD_ID: + required: false + +jobs: + mock_build: + name: Mock build ${{ inputs.version_name }} + runs-on: ubuntu-latest + steps: + - name: Create mocking ko + run: | + echo "${{ inputs.version }}_kernelsu.ko" > ${{ inputs.version }}_kernelsu.ko + - name: Upload LKM + uses: actions/upload-artifact@v4 + if: ${{ inputs.build_lkm == true }} + with: + name: ${{ inputs.version }}-lkm + path: ./*_kernelsu.ko diff --git a/.github/workflows/ksud.yml b/.github/workflows/ksud.yml index 1a5da98a..7d1ea16c 100644 --- a/.github/workflows/ksud.yml +++ b/.github/workflows/ksud.yml @@ -9,6 +9,10 @@ on: required: false type: string default: ubuntu-latest + pull_lkm: + required: false + type: boolean + default: true pack_lkm: required: false type: boolean @@ -25,18 +29,27 @@ jobs: with: fetch-depth: 0 - - name: Download Pre-built LKMs - if: ${{ inputs.pack_lkm }} + - name: Pull lkms from branch + if: ${{ inputs.pack_lkm && inputs.pull_lkm }} uses: actions/checkout@v4 with: ref: lkm path: lkm - - name: Prepare LKM fies - if: ${{ inputs.pack_lkm }} + - name: Download lkms from artifacts + if: ${{ inputs.pack_lkm && !inputs.pull_lkm }} + uses: actions/download-artifact@v4 + + - name: Prepare LKM files + if: ${{ inputs.pack_lkm && inputs.pull_lkm }} run: | cp lkm/*_kernelsu.ko ./userspace/ksud/bin/aarch64/ + - name: Prepare LKM files + if: ${{ inputs.pack_lkm && !inputs.pull_lkm }} + run: | + cp android*-lkm/*_kernelsu.ko ./userspace/ksud/bin/aarch64/ + - name: Setup rustup run: | rustup update stable