You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GitHub策略矩阵指定特定自托管Runner完成多版本构建?

GitHub Actions 矩阵匹配自托管Runner问题解决

问题描述

需要使用GitHub策略矩阵在多个平台构建debug和release版本,每个构建对应专属的自托管Runner。当前Workflow配置如下:

name: Build Gatekeepers
on:
  push:
    branches: master
  workflow_dispatch:

jobs:
  Build:
    needs: Update_Checkouts
    strategy:
      matrix:
        os: [x64_win32_vc14, x64_win32_vc142]
        version: [release, debug]
    runs-on: [ ${{ matrix.os }}, ${{ matrix.version}} ]
    steps:
      - name: Wipe all STAGE folder
        shell: cmd
        run: |
          make wipestage
          rm -rf _*.*
          rm -f Makefile.user
      - name: Setup configuration
        run: make ${{ matrix.os }}
      - name: Make license 
        run: make license 
      - name: Make update 
        run: make update
      - name: Make generate
        run: make generate
      - name: Make build install
        run: make bi.${{ matrix.version }}

其中runs-on: [ ${{ matrix.os }}, ${{ matrix.version}} ]无法生效,仅单独使用matrix.os或matrix.version时能运行,但无法选中对应版本的专属Runner。

解决方案

1. 确认标签匹配逻辑

GitHub Actions中runs-on数组的生效逻辑是:自托管Runner必须同时拥有数组内的所有标签,才会被选中。你的写法本身没有问题,但前提是每个专属Runner必须同时打上对应的平台标签(如x64_win32_vc14)和版本标签(如debug/release)。

可前往仓库的Settings -> Actions -> Runners页面,检查每个Runner的标签列表,确认是否同时具备对应平台和版本的标签。

2. 方案一:使用组合标签的矩阵

如果不想给Runner打多个标签,可以直接在矩阵中定义组合后的完整Runner标签:

jobs:
  Build:
    needs: Update_Checkouts
    strategy:
      matrix:
        runner: [x64_win32_vc14_release, x64_win32_vc14_debug, x64_win32_vc142_release, x64_win32_vc142_debug]
    runs-on: ${{ matrix.runner }}
    steps:
      # 后续步骤保持不变

同时给每个专属Runner打上对应的组合标签(如x64_win32_vc14_release),即可精准匹配到对应的Runner。

3. 方案二:拼接矩阵变量为单个标签

如果你的Runner标签是平台与版本的拼接格式(如x64_win32_vc14-debug),可以保留原矩阵结构,通过变量拼接指定Runner:

jobs:
  Build:
    needs: Update_Checkouts
    strategy:
      matrix:
        os: [x64_win32_vc14, x64_win32_vc142]
        version: [release, debug]
    runs-on: ${{ matrix.os }}-${{ matrix.version }}
    steps:
      # 后续步骤保持不变

这种方式要求每个专属Runner的标签严格对应平台+连接符+版本的格式。

内容的提问来源于stack exchange,提问作者Guy Premont

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 16:33:14