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

如何在GitHub Actions矩阵策略中为特定值配置高资源运行器

如何在GitHub Actions矩阵中为特定任务配置高资源运行器

当然可以实现,给你两种简单直接的方案:

方案一:扩展矩阵配置

把运行器类型和任务名称绑定到矩阵里,明确指定每个任务用什么运行器:

test-app:
  timeout-minutes: 60
  strategy:
    matrix: 
      include:
        - run: 'app1'
          runner: 'ubuntu-latest'
        - run: 'app2'
          runner: 'ubuntu-latest'
        - run: 'app3'
          runner: 'ubuntu-latest-large' # 高资源运行器,对应4核CPU,是标准版的2倍
  runs-on: ${{ matrix.runner }}
  steps:
    # 这里写你的测试步骤,比如拉代码、安装依赖、运行测试等

方案二:用条件表达式动态指定运行器

如果不想改矩阵结构,直接在runs-on里加判断逻辑,根据当前任务名称自动切换:

test-app:
  runs-on: ${{ matrix.run == 'app3' && 'ubuntu-latest-large' || 'ubuntu-latest' }}
  timeout-minutes: 60
  strategy:
    matrix: 
      run: ['app1', 'app2', 'app3'] 
  steps:
    # 你的测试步骤

补充说明

  • GitHub官方托管的高资源运行器,ubuntu-latest-large是标准ubuntu-latest的2倍资源(4核CPU、16GB内存),如果需要更多资源,还可以用ubuntu-latest-xlarge(8核)等规格,不过这些会产生额外的计费成本。
  • 如果你用的是自托管运行器,只需要把上面的ubuntu-latest-large换成你自己的高资源运行器名称就行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 19:06:18