Home > database >  How to DRY up GitHub Actions by listing multiple OS's for the same job?
How to DRY up GitHub Actions by listing multiple OS's for the same job?

Time:11-18

I have this GitHub Actions workflow working:

name: Test Bootstrap

on: push

jobs:
  bootstrap-on-mac:
    runs-on: macos-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
      - name: Bootstrap
        run: ./bootstrap.sh

  bootstrap-on-ubuntu:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
      - name: Bootstrap
        run: ./bootstrap.sh

But is there a way to combine the jobs into a single job that gets executed on multiple operating systems?

So something like this?:

name: Test Bootstrap

on: push

jobs:
  bootstrap-on-mac:
    runs-on:
      - macos-latest
      - ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v2
      - name: Bootstrap
        run: ./bootstrap.sh

I couldn't get the above working because I think GitHub interprets it as requiring an OS that's labelled macos-latest, ubuntu-latest, which doesn't exist.

I tried to use the matrix strategy, but I kept on getting errors and none of the example matrices are 1 dimensional. All of the examples are 2 dimensions or higher.

Thank you for your time

  • Related