【问题标题】:github actions share workspace (yml config)github 操作共享工作区(yml 配置)
【发布时间】:2020-03-03 10:06:38
【问题描述】:

如果我可以运行如下所示的工作流程,那就太棒了 - 也许我只是在 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

我已阅读Github actions share workspace/artifacts between jobs?,但我宁愿不必上传node_modules 并为每一步下载。

【问题讨论】:

    标签: github continuous-integration github-actions


    【解决方案1】:

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

    在作业之间上传/下载工件是一种解决方案。您还可以尝试新的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 限制后,将根据上次访问缓存的时间逐出旧缓存。上周未访问的缓存也将被驱逐。

    【讨论】:

    • 请注意,压缩后(tar+gzip)会检查 400MB 限制,这有点帮助。
    • 是的,我现在使用actions/cache!谢谢。
    猜你喜欢
    • 2019-12-21
    • 2021-10-08
    • 2021-04-10
    • 1970-01-01
    • 2021-04-09
    • 2017-03-24
    • 1970-01-01
    • 1970-01-01
    • 2021-08-30
    相关资源
    最近更新 更多