在多个环境中运行Github Action

时间:2019-12-11 23:50:04

标签: github continuous-integration action

当前,我要做的是在多个环境中运行Github Action,比如说在Windows和Linux上。我设法用travis ci做到了这一点,但是我找不到有关如何使用Github Actions做到这一点的信息。

有人尝试过吗?

当前,这是我的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

2 个答案:

答案 0 :(得分:0)

所以答案实际上很简单。您将创建两个名称不同的操作文件..就我而言:

nodejs-ubuntu.yml nodejs-windows.yml

更改其名称并修改为所需的平台,例如,windows-lates / mac-latest或其他任何东西,一切都应按预期工作。

答案 1 :(得分:0)

您可以为此使用策略/矩阵(请参见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