magisk项目build.yml的文件如下
name: Magisk Build
on:
push:
branches: [master]
paths:
- "app/**"
- "native/**"
- "buildSrc/**"
- "build.py"
- "gradle.properties"
- "gradle/libs.versions.toml"
- ".github/workflows/build.yml"
pull_request:
branches: [master]
workflow_dispatch:
jobs:
build:
name: Build Magisk artifacts
runs-on: macos-15
strategy:
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Setup environment
uses: ./.github/actions/setup
with:
is-asset-build: true
- name: Build release
run: ./build.py -vr all
- name: Build debug
run: ./build.py -v all
- name: Stop gradle daemon
run: ./gradlew --stop
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}
path: out
compression-level: 9
- name: Upload mapping and native debug symbols
uses: actions/upload-artifact@v4
with:
name: ${{ github.sha }}-symbols
path: app/apk/build/outputs
compression-level: 9
test-build:
name: Test building on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2025, ubuntu-24.04]
steps:
- name: Check out
uses: actions/checkout@v4
with:
submodules: "recursive"
- name: Setup environment
uses: ./.github/actions/setup
- name: Test build
run: python build.py -v -c .github/ci.prop all
- name: Stop gradle daemon
run: ./gradlew --stop
avd-test:
name: Test API ${{ matrix.version }} (x86_64)
runs-on: ubuntu-24.04
needs: build
if: ${{ github.event_name != 'push' }}
strategy:
fail-fast: false
matrix:
version: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]
type: [""]
include:
- version: 36
type: "google_apis"
- version: 36
type: "google_apis_ps16k"
steps:
- name: Check out
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.sha }}
path: out
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run AVD test
timeout-minutes: 10
env:
AVD_TEST_LOG: 1
run: scripts/avd_test.sh ${{ matrix.version }} ${{ matrix.type }}
- name: Upload logs on error
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: "avd-logs-${{ matrix.version }}"
path: |
kernel.log
logcat.log
avd-test-32:
name: Test API ${{ matrix.version }} (x86)
runs-on: ubuntu-24.04
needs: build
if: ${{ github.event_name != 'push' }}
strategy:
fail-fast: false
matrix:
version: [23, 24, 25, 26, 27, 28, 29, 30]
steps:
- name: Check out
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.sha }}
path: out
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run AVD test
timeout-minutes: 10
env:
FORCE_32_BIT: 1
AVD_TEST_LOG: 1
run: scripts/avd_test.sh ${{ matrix.version }}
- name: Upload logs on error
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: "avd32-logs-${{ matrix.version }}"
path: |
kernel.log
logcat.log
cf-test:
name: Test ${{ matrix.device }}
runs-on: ubuntu-24.04
needs: build
if: ${{ github.event_name != 'push' }}
env:
CF_HOME: /home/runner/aosp_cf_phone
strategy:
fail-fast: false
matrix:
include:
- branch: "aosp-android-latest-release"
device: "aosp_cf_x86_64_only_phone"
steps:
- name: Check out
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: ${{ github.sha }}
path: out
- name: Setup Cuttlefish environment
run: |
scripts/cuttlefish.sh setup
scripts/cuttlefish.sh download ${{ matrix.branch }} ${{ matrix.device }}
- name: Run Cuttlefish test
timeout-minutes: 10
run: su $USER -c 'scripts/cuttlefish.sh test'
- name: Upload logs on error
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: "cvd-logs-${{ matrix.device }}"
path: |
/home/runner/aosp_cf_phone/cuttlefish/instances/cvd-1/logs
/home/runner/aosp_cf_phone/cuttlefish/instances/cvd-1/cuttlefish_config.json
这个 build.yml
文件是 GitHub Actions 的配置文件,用于自动化构建、测试 Magisk 项目。以下为你详细解读其内容:
1. 触发条件
on:
push:
branches: [master]
paths:
- "app/**"
- "native/**"
- "buildSrc/**"
- "build.py"
- "gradle.properties"
- "gradle/libs.versions.toml"
- ".github/workflows/build.yml"
pull_request:
branches: [master]
workflow_dispatch:
-
push:当
master
分支上有代码推送,并且修改的文件路径匹配所列文件时,工作流会被触发。 -
pull_request:当向
master
分支发起拉取请求时,工作流会被触发。 - workflow_dispatch:可以通过 GitHub 界面手动触发该工作流。
2. 任务部分
2.1 build
任务
jobs:
build:
name: Build Magisk artifacts
runs-on: macos-15
strategy:
fail-fast: false
steps:
# ...
- 任务名称:构建 Magisk 制品。
-
运行环境:
macos-15
。 -
策略:
fail-fast: false
表示即使某个步骤失败,其他步骤也会继续执行。 -
步骤:
-
Check out:使用
actions/checkout@v4
检出代码,并递归初始化子模块。 -
Setup environment:使用自定义的
.github/actions/setup
动作设置环境,is-asset-build
设为true
。 -
Build release:运行
./build.py -vr all
构建发布版本。 -
Build debug:运行
./build.py -v all
构建调试版本。 -
Stop gradle daemon:运行
./gradlew --stop
停止 Gradle 守护进程。 -
Upload build artifact:使用
actions/upload-artifact@v4
上传构建产物,名称为当前提交的 SHA 值,路径为out
目录。 -
Upload mapping and native debug symbols:上传映射文件和本地调试符号,名称为当前提交的 SHA 值加上
-symbols
,路径为app/apk/build/outputs
目录。
-
Check out:使用
2.2 test-build
任务
test-build:
name: Test building on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2025, ubuntu-24.04]
steps:
# ...
- 任务名称:在不同操作系统上测试构建。
-
运行环境:
windows-2025
和ubuntu-24.04
。 -
策略:
fail-fast: false
表示即使某个步骤失败,其他步骤也会继续执行。 -
步骤:
- Check out:检出代码并递归初始化子模块。
- Setup environment:使用自定义动作设置环境。
-
Test build:运行
python build.py -v -c .github/ci.prop all
进行测试构建。 - Stop gradle daemon:停止 Gradle 守护进程。
2.3 avd-test
任务
avd-test:
name: Test API ${{ matrix.version }} (x86_64)
runs-on: ubuntu-24.04
needs: build
if: ${{ github.event_name != 'push' }}
strategy:
fail-fast: false
matrix:
version: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]
type: [""]
include:
- version: 36
type: "google_apis"
- version: 36
type: "google_apis_ps16k"
steps:
# ...
- 任务名称:在不同 API 版本的 x86_64 模拟器上进行测试。
-
运行环境:
ubuntu-24.04
。 -
依赖:依赖
build
任务完成。 -
触发条件:非
push
事件触发。 -
策略:
fail-fast: false
表示即使某个步骤失败,其他步骤也会继续执行。 -
步骤:
- Check out:检出代码。
-
Download build artifacts:下载
build
任务生成的构建产物。 - Enable KVM group perms:设置 KVM 组权限。
-
Run AVD test:运行
scripts/avd_test.sh
脚本进行 AVD 测试,超时时间为 10 分钟。 - Upload logs on error:如果测试失败,上传日志文件。
2.4 avd-test-32
任务
avd-test-32:
name: Test API ${{ matrix.version }} (x86)
runs-on: ubuntu-24.04
needs: build
if: ${{ github.event_name != 'push' }}
strategy:
fail-fast: false
matrix:
version: [23, 24, 25, 26, 27, 28, 29, 30]
steps:
# ...
- 任务名称:在不同 API 版本的 x86 模拟器上进行测试。
-
运行环境:
ubuntu-24.04
。 -
依赖:依赖
build
任务完成。 -
触发条件:非
push
事件触发。 -
策略:
fail-fast: false
表示即使某个步骤失败,其他步骤也会继续执行。 -
步骤:与
avd-test
任务类似,只是增加了FORCE_32_BIT
环境变量。
2.5 cf-test
任务
cf-test:
name: Test ${{ matrix.device }}
runs-on: ubuntu-24.04
needs: build
if: ${{ github.event_name != 'push' }}
env:
CF_HOME: /home/runner/aosp_cf_phone
strategy:
fail-fast: false
matrix:
include:
- branch: "aosp-android-latest-release"
device: "aosp_cf_x86_64_only_phone"
steps:
# ...
- 任务名称:在指定设备上进行 Cuttlefish 测试。
-
运行环境:
ubuntu-24.04
。 -
依赖:依赖
build
任务完成。 -
触发条件:非
push
事件触发。 -
策略:
fail-fast: false
表示即使某个步骤失败,其他步骤也会继续执行。 -
步骤:
- Check out:检出代码。
-
Download build artifacts:下载
build
任务生成的构建产物。 - Setup Cuttlefish environment:设置 Cuttlefish 环境,下载指定分支和设备的文件。
-
Run Cuttlefish test:运行
scripts/cuttlefish.sh test
脚本进行测试,超时时间为 10 分钟。 - Upload logs on error:如果测试失败,上传日志文件。
总体而言,这个配置文件实现了 Magisk 项目的自动化构建和多环境测试,确保代码在不同环境下的稳定性和兼容性。