Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run GitHub Action on multiple environments (operating systems)

I want to run GitHub Actions on more than one environment, let's say on Windows and Linux. I managed to do it with Travis CI, but I could not find information about how to do it with GitHub Actions.

Has anyone tried it?

This is my nodejs.yml.

name: Node CI

on: [ push ]

jobs:
  build:
    runs-on: ubuntu-latest
    
    strategy:
      matrix:
        node-version: [ 12.x ]
    
    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install
        run: |
          npm ci
      - name: prettier format check
        run: |
          npm run prettier-check
      - name: lint format check
        run: |
          npm run lint-check
      - name: build, and test
        run: |
          npm run build
          npm test --if-present
        env:
          CI: true
like image 970
Yordan Kanchelov Avatar asked Nov 22 '25 14:11

Yordan Kanchelov


1 Answers

You can use a matrix strategy:

https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#about-matrix-strategies

and

https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategy

name: Node CI

on: [push]

jobs:
    build:
        runs-on: ${{ matrix.os }}

        strategy:
            matrix:
                os: [ubuntu-latest, windows-latest]
                node-version: [12.x]

        steps:
            - uses: actions/checkout@v1
            - name: Use Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v1
              with:
                  node-version: ${{ matrix.node-version }}
            - name: npm install
              run: |
                  npm ci
            - name: prettier format check
              run: |
                  npm run prettier-check
            - name: lint format check
              run: |
                  npm run lint-check
            - name: build, and test
              run: |
                  npm run build
                  npm test --if-present
              env:
                  CI: true

like image 155
riQQ Avatar answered Nov 24 '25 02:11

riQQ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!