Github actions 如何在两个服务器中配置两个runner

Github actions how to configure two runners in two servers

我有一个名为 api 的 GitHub 存储库。 api 有两个分支 DEVQA

我已经为 DEV 分支设置了工作流程并且工作正常。

这是 DEV 分支的工作流程

# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
  push:
    branches: [DEV]
  pull_request:
    branches: [DEV]

jobs:
  build:
    runs-on: self-hosted
    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"
      - run: npm ci
      # - run: pm2 stop app.js
      - run: pm2 start ecosystem.config.js --update-env

然后我创建了我的第二个 EC2 实例和第二个运行程序以及另一个工作流文件

# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: QA Build

on:
  push:
    branches: [ QA ]
  pull_request:
    branches: [ QA ]

jobs:
  build:

    runs-on: self-hosted
    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'npm'
    - run: npm i
    - run: pm2 start ecosystem.config.js --update-env

但是每当我将一些代码推送到 QA 分支时,我的第一个运行程序和第一个 EC-2 实例仍然运行。似乎根本不使用第二个实例或工作流。 如何根据分支指定runner和instance?

如果您只有两个默认设置的跑步者,您将无法区分两者。因为这样的工作只需要两者中的任何一个。

标签可以标记一个特定的跑步者,您可以直接选择。参见 GitHub self-hosted runners docs on labels

然后您可以像这样使用特定的跑步者

runs-on: [self-hosted, dev]