GitHub Actions 共享工作区 (YML 配置)

5
希望能够运行以下类似的工作流,也许我只是在 GitHub Actions 中缺少简单的配置,但我不知道如何在使用 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

我已经阅读了Github Actions共享工作区/工件的方法? 但我不想为每个步骤上传 node_modules 并下载。

1个回答

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-

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

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


2
请注意,400MB的限制是在压缩(tar+gzip)后进行检查的,这可以稍微帮助一下。 - Samira
是的,目前我已经采用了actions/cache!谢谢。 - JaKXz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接