github actions 共享工作区(yml 配置)

JaK*_*KXz 5 continuous-integration github github-actions

如果我可以运行如下所示的工作流程,那就太酷了 - 也许我只是缺少 GitHub 操作中的简单配置,但我不知道如何在作业之间共享工作区,同时用于指定job.needs哪些作业可以运行当其他人已经成功完成时。

name: Node CI

on: [push]
env:
  CI: true

jobs:
  install:
    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: install node_modules
      run: yarn install

  lint:
    runs-on: ubuntu-latest
    needs: [install]
    steps:
      - name: eslint
        run: yarn lint

  build:
    needs: [install]
    runs-on: ubuntu-latest
    steps:
      - name: yarn build
        run: yarn build

  test:
    needs: [install, build]
    runs-on: ubuntu-latest
    steps:
      - name: jest
        run: yarn test --coverage
Run Code Online (Sandbox Code Playgroud)

我已阅读Github actions shareworkspace/artifacts Between jobs? 但我不想node_modules每一步都上传和下载。

pet*_*ans 2

据我所知,操作工作区仅在同一作业的步骤之间共享。您无法在作业之间共享文件系统。

在作业之间上传/下载工件是一种解决方案。您还可以尝试新actions/cache操作来缓存node_modules目录并在后续作业中恢复它。

- uses: actions/cache@v1
  with:
    path: node_modules
    key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-node-
Run Code Online (Sandbox Code Playgroud)

请注意,目前有一些相当严格的限制,因此如果您有一个非常大的node_modules目录,它可能无法工作。

单个缓存限制为 400MB,存储库最多可以有 2GB 缓存。一旦达到 2GB 限制,较旧的缓存将根据上次访问缓存的时间被逐出。上周未访问的缓存也将被驱逐。

  • 请注意,压缩 (tar+gzip) 后会检查 400MB 限制,这会有所帮助。 (2认同)