GitHub动作中的缓存依赖性问题

发布于 2025-02-03 20:17:56 字数 1821 浏览 1 评论 0原文

我正在尝试使用小丑中的Shard选项在多个跑步者中并行运行测试。

但是在我可以在CI上执行此操作之前 - 我必须执行其他一些步骤,例如结帐代码库,请在运行测试的特定作业中安装依赖项。

问题语句 - 我想避免为运行的每个测试碎片安装依赖项。

我在互联网上进行了搜索,发现我无法在上一份工作中做到这一点,因为每个工作都在自己的容器中开始。

因此,我写了这样的东西:

run_tests:
    runs-on: [self-hosted]
    name: Run Tests
    continue-on-error: false
    strategy:
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - name: Checkout Codebase
        uses: actions/checkout-action@v2
      - name: Use Node v14.15.1
        uses: actions/setup-node@v1
        with:
          node-version: 14.15.1
      - name: Cache NPM dependencies
        id: npmCacheStep
        uses: actions/cache@v2
        with:
          path: ~/.npm
          key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-npm-cache-
      - name: Install Dependencies
        if: steps.npmCacheStep.outputs.cache-hit != 'true'
        run: npm ci
      - name: Run tests
        run: npm run test -- --colors --coverage --shard=${{ matrix.shard }}/${{ strategy.job-total }}

要解决我的问题声明,我说如果它找到了NPM依赖项的缓存 - 然后不要在很多地方推荐再次安装NPM模块 - https://docs.github.com/en/en/en/actions/using-using-工作流/依赖于速度 - 速度 - 工作流量

但是当我尝试运行此操作时,

  • NPM安装步骤将跳过(如前所述) 我在github操作工作流日志上收到以下错误:

我正在尝试此解决方案:有没有一种方法可以使用缓存加速NPM CI?

I am trying to use the shard option in jest to run my tests in parallel across multiple runners.

But before I can do this on CI - I have to do some other steps like checkout codebase, install dependencies in the specific job running the test.

Problem statement - I want to avoid installing dependencies for each shard of test running.

I searched around the internet and found that I cannot do this in another preceding job because each job starts fresh in its own container.

Hence I wrote something like this:

run_tests:
    runs-on: [self-hosted]
    name: Run Tests
    continue-on-error: false
    strategy:
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - name: Checkout Codebase
        uses: actions/checkout-action@v2
      - name: Use Node v14.15.1
        uses: actions/setup-node@v1
        with:
          node-version: 14.15.1
      - name: Cache NPM dependencies
        id: npmCacheStep
        uses: actions/cache@v2
        with:
          path: ~/.npm
          key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-npm-cache-
      - name: Install Dependencies
        if: steps.npmCacheStep.outputs.cache-hit != 'true'
        run: npm ci
      - name: Run tests
        run: npm run test -- --colors --coverage --shard=${{ matrix.shard }}/${{ strategy.job-total }}

To solve my problem statement, I'm saying that if it found a cache of npm dependencies - then don't install npm modules again as recommended at lots of places - https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows

But when I try to run this

  • the npm install step is skipped (as expected)
    I get the following error on github actions workflow logs:
    enter image description here

I am trying this solution: Is there a way to speedup npm ci using cache?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文