Github Action - cache 和 matrix的用法

378 阅读1分钟

Github Action

actions/cache

actions/cache-docs

或者直接点下方的链接,直接跳到相关cache的例子

矩阵 matrix

jobs:
  build:
    strategy:
      matrix:
        # 指定node版本 矩阵指定多版本
        node-version: [12.x, 14.x, 15.x]
         # 指定os 
        os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
  # 用变量的形式,自动分配
  runs-on: ${{ matrix.os }}

   # 用变量的形式,自动分配
  - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}

  #有些任务是不能在其他环境运行的
  # 比如GabrielBB/xvfb-action@v1 只能在linux 下使用
  # 用if条件判断一下就好
  - name: Run headless unit test
      if: matrix.os == 'ubuntu-latest'
      uses: GabrielBB/xvfb-action@v1
      with:
        run: |
          yarn test
          yarn e2e

  # node 后续任务