4
name: test if conditions
name: test if conditions
on:
  push:
    branches: [master, test]
env:
  TEST_BRANCH: "test"
  EMPTY_VALUE: ""
jobs:
  test-conditions:
    runs-on: ubuntu-latest
    steps:
      - name: simple evaluation on test
        run: echo "runs"
#eg) for test branch => runs-on: ubuntu-latest
     for master branch => runs-on: ['self-hosted', 'products', 'latest']

is it possible to dynamically load the runs-on in the same workflow ?

Wiki
  • 93
  • 6

2 Answers2

2
${{ (inputs.shouldUseSelfHosted) && fromJSON('[ "self-hosted", "Linux", "X64" ]') || 'ubuntu-latest' }}

Reference: https://github.com/actions/runner/issues/409

Wiki
  • 93
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 10 '22 at 16:34
1

#eg) for test branch => runs-on: ubuntu-latest
for master branch => runs-on: ['self-hosted', 'products', 'latest']

Complete workflow file will be looks like:

---

name: test on multiple runners

on:
  push:
    branches:
      - master
      - test

jobs:
  simple-test:
    # if affected branch is 'test' then runs on 'ubuntu-latest' else self-hosted...
    runs-on: ${{ github.ref_name == 'test' && 'ubuntu-latest' || fromJSON('["self-hosted", "products", "latest"]') }}
    steps:
      - name: simple evaluation on test
        run: echo "runs"
rzlvmp
  • 7,512
  • 5
  • 16
  • 45