Github Actions configure defaults option

Official github actions documentation says I can set the defaults to specfify defaults settings for all jobs https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#defaults . I want to set that up to specify

defaults:
  runs-on: ubuntu-latest
  strategy:
    fail-fast: false # do not cancel 7.2 if 7.3 fails
    matrix:
      php: ['7.2', '7.3', '7.4']
      node-version: ['12.5']
jobs:
    ...

But this fails with

The workflow is not valid. .github/workflows/code_checks.yaml (Line: 7, Col: 3): Unexpected value 'runs-on',.github/workflows/code_checks.yaml (Line: 8, Col: 3): Unexpected value 'strategy'

I want to specify the same runs-on and strategy for all my jobs. Why isn’t the defaults working?

Hi @i-valchev , 

I am sorry to tell you that only run settings could be set under defaults option currently. Runs-on and strategy is not supported under defaults. 

I would encourage you share your idea in the Feedback form for GitHub Actions.   

Right, I see.

The issue I’m facing (I think it’s pretty common) is that there are a few commands that have to run for setup and initialisation. After this is run, there are a bunch of independent from each other checks - unite tests, e2e, code style, etc. To speed up the CI time, I want to have these run in parallel, which is a major benefit of GitHub Actions jobs in my view.

So what’s the best way to configure this kind of setup?

Based on my understanding, you want to set up a workflow with multiple jobs. First job to run a few commands for setup and initialisation. Then other jobs needs the first job and run in parallel. Also the other jobs need the setup and initialisation environment in the first job. 

What I want to explain is that different jobs are running in different hosted vms, so if you installation is executed in the first job, it could not be shared in other jobs. You need to install the same thing in each job. 

There is an action for caching dependencies and build outputs to improve workflow execution time.  You need to add this cache action to all of your jobs . 

use defaults as in the example below:

name: my workflow
on: push

jobs:
  build:
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash
    
    strategy:
      matrix:       
        os: [windows-latest, ubuntu-latest]