This is not possible, with defaults you can only set the shell and working-directory.
You're kinda looking for default-strategy which doesn't exist. One thing to keep in mind with Github Actions is that each job is spawned on a different machine which doesn't share any information with the previous job.
What suits your needs better is to create one job with one set of strategies and multiple steps.
Answer from zzarbi on Stack OverflowThis is not possible, with defaults you can only set the shell and working-directory.
You're kinda looking for default-strategy which doesn't exist. One thing to keep in mind with Github Actions is that each job is spawned on a different machine which doesn't share any information with the previous job.
What suits your needs better is to create one job with one set of strategies and multiple steps.
I have the same gripe with Actions. I am working around it for now by setting repeated job configurations as inputs that are not required and have defaults. That way they are defaulted but can also be user-overridden if desired. I suppose they could also be workflow-level env vars but that would make them not user-overridable, if that's a concern for you.
So I do:
on:
workflow_call:
inputs:
runs-on:
required: false
type: string
description: The self-hosted runner to use
default: 'linux'
timeout-minutes:
required: false
type: number
description: The maximum time in minutes that the job can run.
default: 90
# note that you *can* set this default
defaults:
run:
shell: bash
# use the workflow defaults here
jobs:
init:
name: Initialize
runs-on: ${{ inputs.runs-on }}
timeout-minutes: ${{ inputs.timeout-minutes }}
Dynamic default value for action inputs
How to set a default value for a workflow_dispatch variable?
How to use env variable as default value for input in github actions? - Stack Overflow
defaults.run.working-directory option not being respected
Videos
You could define the env variable as follow (remember to put string literal in single quotes):
env:
GODOT_MONO_BUILD_TAG: ${{ github.event.inputs.mono-build-repo || 'latest' }}
where latest should be the default value for the env var
The suggestion to use the env context is a good one although its use is limited - For example, I found that the env context can not be used for workflow or job names, only for step names:
on:
push:
workflow_dispatch:
inputs:
my-var:
default: abc
env:
TAG: ${{ inputs.my-var || 'abc' }}
run-name: My Workflow with variable [${{ env.MY_VAR }}] << does not work
jobs:
some-job:
name: My JOB with variable [${{ env.MY_VAR }}] << does not work
steps:
- name: My Step with variable [${{ env.MY_VAR }}] << works!
We can use inputs for the workflow/job names but on push events, those values are empty :-(
An alternative is to use store defaults in Repository/Organization variables that can then be accessed from the vars context - i.e. you could do something like ${{ inputs.my-var || vars.DEFAULT_MY_VAR }}
If there are any other suggestions for using (default) variables regardless of the event type - please post them.
It would be awesome if a push event could inherit the default inputs from the workflow_dispatch event ...
More about contexts and how to use them here