I have a couple of GitHub workflows divided into parent ones and reusable workflows.
The parents are build and deploy, each triggered at different circumstances and calling the subworkflows with different input parameters.
Subworkflows are basically build scripts that consist of several steps, like checkouts, fetching other artifacts and then building on mac or windows machine.
The problem is that I would like to specify on what runner the sub workflow is going to run from the parent script.
I would like to run the build subworkflow on a different runner when called from parent deploy.yml
and from build.yml
. I have setup 2 self-hosted runners, each with different labels, lets say [self-hosted, macOS]
and [self-hosted, macOS, deploy]
.
I tried adding a string input parameter to the subworkflow and then used it like this:
MacBuild:
name: Mac build
uses: ./.github/workflows/build-mac.yml
with:
build_installer: true
installer_artifact: true
runner_tags: "[self-hosted, macOS, deploy]"
secrets: inherit
then in sub workflow
runs-on: ${{ inputs.runner_tags }}
and it actually parsed it OK, saying that "Requested labels: [self-hosted, macOS, deploy]", but the runner never actually picked up the job, even it was idle.
Is there a way to do what I want?
This is the deploy.yml
file:
name: Deploy
on:
push:
jobs:
MacBuild:
name: Mac build
uses: ./.github/workflows/build-mac.yml
with:
build_installer: true
installer_artifact: true
secrets: inherit
This is the build-mac.yml
file:
name: Build Release Mac
on:
workflow_call:
inputs:
build_installer:
description: 'Sign products and build isntaller'
type: boolean
required: false
default: false
installer_artifact:
description: 'Upload installer to artifacts'
type: boolean
required: false
default: false
jobs:
MacBuild:
name: macOS Build Release
runs-on: [self-hosted, macOS]
steps:
- name: Checkout Repository
uses: actions/checkout@main
with:
path: ${{ github.event.repository.name }}
- name: Check out other repository
uses: actions/checkout@main
with:
repository: organization/other_repository
token: ${{ secrets.RUNNERS_PAT }}
path: other_repository
ref: development # branch
Already tried passing the runner labels as string parameter these ways:
didn't work, runner didn't pick up the job.
Duplicate (similar) to How to Dynamically assign the runs-on value in the github actions
This answer helped: https://stackoverflow.com/a/73253764/19599681
I used another sub workflow input parameter - bool, to decide what runner flags to use, so the script looks like this:
name: Build Mac Release
on:
workflow_call:
inputs:
build_installer:
description: 'Sign products and build isntaller'
type: boolean
required: false
default: false
installer_artifact:
description: 'Upload installer to artifacts'
type: boolean
required: false
default: false
deploy_runner:
description: 'Use deploy runner'
type: boolean
required: false
default: false
jobs:
MacBuild:
name: macOS Build Release
runs-on: ${{ (inputs.deploy_runner) && fromJSON('[ "self-hosted", "macOS", "deploy" ]') || fromJSON('[ "self-hosted", "macOS"]') }}
I believe it could be possible to just send the string with tags as an input parameter and parse it here by fromJSON()
, but I have not tested that.