问题
Currently what I want to do is to run the GitHub Actions on more than one environment, let's say on windows and linux. I managed to do it with the Travis CI, but I could not find information about how to do it with GitHub Actions.
Has anyone tried it?
Currently, 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
回答1:
You can use a strategy / matrix for that (see https://docs.github.com/en/actions/reference/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
回答2:
So the answer was pretty simple actually. You create two action files with a different name .. In my case:
nodejs-ubuntu.yml nodejs-windows.yml
Change their name and modify to the desired platform, for example, windows-lates/mac-latest or whatever and everything should work as expected.
来源:https://stackoverflow.com/questions/59295795/run-github-action-on-multiple-environments