KernelSU: 使用手动hook #117
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 编译内核 | |
| on: | |
| push: | |
| branches: | |
| - dev/* | |
| - stable/* | |
| workflow_dispatch: | |
| env: | |
| AOSP_TOOLCHAIN_BRANCH: android16 | |
| AOSP_CLANG_VERSION: r547379 | |
| jobs: | |
| build: | |
| name: 编译内核 | |
| permissions: { contents: write } | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| device: | |
| - beryllium | |
| - dipper | |
| - equuleus | |
| - perseus | |
| - polaris | |
| - ursa | |
| steps: | |
| - name: 安装软件包 | |
| if: env.PACKAGES != '' | |
| env: | |
| PACKAGES: | |
| binutils-aarch64-linux-gnu | |
| binutils-arm-linux-gnueabi | |
| run: | | |
| sudo apt-get update -y -q | |
| sudo apt-get install -y -q ${{ env.PACKAGES }} | |
| - name: 安装make4.4.1-2 | |
| run: | | |
| curl -LSs http://ftp.debian.org/debian/pool/main/m/make-dfsg/make_4.4.1-2_amd64.deb -o make.deb | |
| sudo apt-get install -y -q ./make.deb | |
| rm ./make.deb | |
| - name: 同步仓库 | |
| uses: actions/checkout@main | |
| with: | |
| path: kernel | |
| - name: 缓存Clang | |
| id: cache-clang | |
| uses: actions/cache/restore@main | |
| with: | |
| path: clang | |
| key: clang-${{ env.AOSP_TOOLCHAIN_BRANCH }}-${{ env.AOSP_CLANG_VERSION }} | |
| - name: 下载Clang | |
| id: download_clang | |
| if: steps.cache-clang.outputs.cache-hit != 'true' | |
| run: | | |
| mkdir -p clang | |
| wget -c -t 10 "https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/${{ env.AOSP_TOOLCHAIN_BRANCH }}-release/clang-${{ env.AOSP_CLANG_VERSION }}.tar.gz" -O clang.tgz | |
| tar -zxvf clang.tgz -C clang/ | |
| - name: 保存Clang | |
| if: always() && steps.cache-clang.outputs.cache-hit != 'true' && steps.download_clang.outcome == 'success' | |
| uses: actions/cache/save@main | |
| with: | |
| path: clang | |
| key: clang-${{ env.AOSP_TOOLCHAIN_BRANCH }}-${{ env.AOSP_CLANG_VERSION }} | |
| - name: 缓存ccache | |
| uses: hendrikmuhs/ccache-action@main | |
| with: | |
| key: kernel-${{ matrix.device }} | |
| restore-keys: kernel-${{ matrix.device }} | |
| max-size: 5G | |
| - name: 编译 | |
| working-directory: kernel | |
| env: | |
| MAKE_ARGS: | |
| -j$(nproc --all) | |
| O=out | |
| LLVM=1 | |
| LLVM_IAS=1 | |
| CC="ccache clang" | |
| LD=ld.lld | |
| ARCH=arm64 | |
| CROSS_COMPILE=aarch64-linux-gnu- | |
| CROSS_COMPILE_ARM32=arm-linux-gnueabi- | |
| CONFIG_FILES: | |
| vendor/xiaomi/mi845_defconfig | |
| vendor/xiaomi/${{ matrix.device }}.config | |
| lxc.config | |
| run: | | |
| export PATH=$GITHUB_WORKSPACE/clang/bin:$PATH | |
| export KBUILD_BUILD_USER=${{ github.repository_owner }} | |
| export KBUILD_BUILD_HOST=github-runner | |
| export KBUILD_BUILD_TIMESTAMP=`date -u -d "@$(git log -1 --format=%at)" +"%a %b %d %H:%M:%S %Z %Y"` | |
| make ${{ env.MAKE_ARGS }} ${{ env.CONFIG_FILES }} all | |
| - name: 打包(AnyKernel3) | |
| run: | | |
| git clone https://github.com/osm0sis/AnyKernel3 --depth=1 ak3 | |
| cp kernel/out/arch/arm64/boot/Image.gz-dtb ak3/ | |
| cd ak3 | |
| cat >anykernel.sh <<EOF | |
| properties() { ' | |
| kernel.string=Kernel for ${{ matrix.device }} | |
| device.name1=${{ matrix.device }} | |
| do.devicecheck=1 | |
| '; } | |
| ramdisk_compression=auto | |
| patch_vbmeta_flag=auto | |
| is_slot_device=auto | |
| block=auto | |
| . tools/ak3-core.sh | |
| split_boot | |
| flash_boot | |
| EOF | |
| zip -qr9 Anykernel3-${{ matrix.device }}.zip * -x .git .github README.md *placeholder | |
| - name: 上传文件 | |
| uses: actions/upload-artifact@main | |
| with: | |
| name: kernel-${{ matrix.device }}-ak3 | |
| path: ak3/Anykernel3-${{ matrix.device }}.zip | |
| release: | |
| name: 发布 | |
| if: github.event_name == 'push' | |
| permissions: { contents: write } | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: 获取构建产物 | |
| uses: actions/download-artifact@main | |
| with: | |
| path: kernel | |
| pattern: kernel-* | |
| merge-multiple: true | |
| - name: 获取当前时间 | |
| id: time | |
| run: | | |
| NOW=$(date +%s) | |
| TIME_STR=$(TZ='Asia/Shanghai' date -d "@$NOW" +'%Y%m%d%H%M') | |
| echo "timestamp=$NOW" >> $GITHUB_OUTPUT | |
| echo "time=$TIME_STR" >> $GITHUB_OUTPUT | |
| - name: 发布 | |
| uses: softprops/action-gh-release@master | |
| id: release | |
| with: | |
| tag_name: rel-${{ steps.time.outputs.timestamp }} | |
| name: Kernel build ${{ steps.time.outputs.time }} | |
| prerelease: ${{ startsWith(github.ref_name, 'dev/') }} | |
| files: | | |
| kernel/* | |
| - name: 发送Telegram通知 | |
| continue-on-error: true | |
| run: | | |
| IDS=(${{ join(github.event.commits.*.id, ' ') }}) | |
| MAX=6 | |
| if [ "${#IDS[@]}" -gt "$MAX" ]; then | |
| COMMIT_IDS_TEXT="$(printf "%s\n" "${IDS[@]:0:$MAX}"; echo "......")" | |
| else | |
| COMMIT_IDS_TEXT="$(printf "%s\n" "${IDS[@]}")" | |
| fi | |
| MSG="\ | |
| <b>CI ${{ steps.time.outputs.time }}</b> | |
| <pre>\ | |
| 项目: ${{ github.repository }} | |
| 分支: ${{ github.ref_name }}\ | |
| </pre> | |
| <b>提交ID:</b> | |
| <pre>$COMMIT_IDS_TEXT</pre>\ | |
| " | |
| PREVIEW_OPTIONS="{ \ | |
| \"url\": \"${{ steps.release.outputs.url }}\", \ | |
| \"prefer_small_media\": true, \ | |
| \"show_above_text\": true \ | |
| }" | |
| BUTTONS="{\"inline_keyboard\": [ [ \ | |
| { \"text\": \"下载链接\", \"url\": \"${{ steps.release.outputs.url }}\" }, \ | |
| { \"text\": \"对比差异\", \"url\": \"${{ github.event.compare }}\" } \ | |
| ] ] }" | |
| curl -LSs -X POST https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage \ | |
| -d "chat_id=${{ vars.TELEGRAM_CHAT_ID }}" \ | |
| -d "message_thread_id=${{ vars.TELEGRAM_MESSAGE_THREAD_ID }}" \ | |
| -d "parse_mode=HTML" \ | |
| --data-urlencode "text=$MSG" \ | |
| -d "link_preview_options=$PREVIEW_OPTIONS" \ | |
| -d "reply_markup=$BUTTONS" \ | |
| -o response.txt && \ | |
| (! ${{ startsWith(github.ref_name, 'stable/') }} || \ | |
| curl -LSs -X POST https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/pinChatMessage \ | |
| -d "chat_id=${{ vars.TELEGRAM_CHAT_ID }}" \ | |
| -d "message_id=$(jq '.result.message_id' response.txt)") | |
| if [ "${{ runner.debug }}" = "1" ]; then | |
| cat response.txt | |
| fi |