如何在GitHub Actions中跳过matrix矩阵的macOS x86指定配置
你可以通过两种方式实现跳过 macOS x86 架构的构建任务,优先推荐第一种矩阵排除方案:
方法一:在构建矩阵中添加 exclude 规则(推荐)
直接在 strategy.matrix 配置中加入排除项,GitHub Actions 会直接不生成该组合的任务,不会占用 runner 资源,是性能最优的方案。
修改后的配置如下:
build-and-push-native-libraries: name: Build and push native library on ${{ matrix.os }} ${{ matrix.architecture }} strategy: fail-fast: true matrix: os: [ubuntu-latest, macOS, windows-latest] java: [15] architecture: [x86, x64] include: - compiler: gcc gcc: 8 # 新增排除规则 exclude: - os: macOS architecture: x86 runs-on: ${{ matrix.os }} steps: - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@v1 with: java-version: ${{ matrix.java }} architecture: ${{ matrix.architecture }} - uses: actions/checkout@v2 - if: startsWith(matrix.os, 'ubuntu') == true name: Change the permissions of the build script of external classes run: chmod +x ./java/src/main/resources/compileExternalClasses.sh - name: Build and push native library run: | mvn -B clean package -DskipTests=true --file ./native/pom.xml git config user.name "${{ github.event.head_commit.committer.name }}" git config user.email "${{ github.event.head_commit.committer.email }}" git pull origin experimental git commit -am "Generated library for ${{ matrix.os }} ${{ matrix.architecture }}" --allow-empty git push
方法二:给任务添加 if 跳过条件
如果不想修改矩阵配置,也可以直接给整个任务添加执行条件,匹配到 macOS x86 组合时直接跳过整个任务:
在 runs-on 字段上方添加如下 if 判断即可:
build-and-push-native-libraries: name: Build and push native library on ${{ matrix.os }} ${{ matrix.architecture }} strategy: fail-fast: true matrix: os: [ubuntu-latest, macOS, windows-latest] java: [15] architecture: [x86, x64] include: - compiler: gcc gcc: 8 # 新增跳过条件 if: ${{ !(matrix.os == 'macOS' && matrix.architecture == 'x86') }} runs-on: ${{ matrix.os }} # 后续steps配置保持不变
该方案的区别是 macOS x86 的任务还是会被创建,只是直接标记为跳过状态,适合临时测试时快速禁用某类任务使用。
内容的提问来源于stack exchange,提问作者JJB
相关产品推荐
相关产品推荐

