Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 3
Message 1 of 4

Can workflow specify which self-runner to run a job?

Solved! Go to Solution.

I have a project, that can be compiled to both Linux and Macos. I want the workflow to have three jobs. The first job is to build execuables for Linux and Macos respectively on cloud. The second and the third job are to perform self-hosted testing jobs. And because the test is USB connected hardware related, it can only be run on self-hosted runners.

I will have two self-hosted runners running whose OS are Linux and Macos respectively.

 

A pseudo workflow is as follows:

on: [push]

jobs:
  build_phase:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, ubuntu-latest]
    name: build binary
    steps:
      - name: checkout
        uses: actions/checkout@v2

      - name: build
        run: |
          ./build
          mkdir build-artifact-${runner.os}
          cp built_binary build-artifact-${runner.os}

      - name: upload artifact
        uses: actions/upload-artifact@v1
        with:
          name: binary-${runner.os}
          path: build-artifact-${runner.os}


  test_macos:
    runs-on: self-hosted
    self-runner-os: macos       # pseudo argument
    name: on board test macos
    needs: build_phase
    steps:
      - name: obtain artifact
        uses: actions/download-artifact@v1
        with:
          name: binary-Macos

      - name: do test
        run: |
          ./test built_binary

  test_linux:
    runs-on: self-hosted
    self-runner-os: Linux       # pseudo argument
    name: on board test linux
    needs: build_phase
    steps:
      - name: obtain artifact
        uses: actions/download-artifact@v1
        with:
          name: binary-Linux

      - name: do test
        run: |
          ./test built_binary
        

 

 

So far I don't see any way to select self-hosted runner in a workflow. I wonder if there is a way to do this. Or is there any other solutions for my scenario?

3 Replies
Highlighted
Solution
GitHub Partner
Message 2 of 4

Re: Can workflow specify which self-runner to run a job?

When use a self-hosted runner, you could specify its OS by next syntex: 

runs-on: [self-hosted, macos]

For more information, please refer to the officail document

 

Highlighted
Copilot Lvl 3
Message 3 of 4

Re: Can workflow specify which self-runner to run a job?

Thanks for your reply! And it does resolve my problem!

 

One more thing is that, is it possible to identify two self-hosted runners with same OS in a workflow? For example, if I have two self-hosted Linux runners, but they are connected to different hardwares for different testing procedures, is there a way to identify them besides the OS or architecture label? Are self-defined labels available?

Highlighted
GitHub Partner
Message 4 of 4

Re: Can workflow specify which self-runner to run a job?

Specify self-defined labels to choose self-hoested runner is not supported currently. You could share this idea in the Feedback form for GitHub Actions. Thank you for helping us building a better Github Actions.