GitHub动作中的缓存依赖性问题
我正在尝试使用小丑中的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 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:
I am trying this solution: Is there a way to speedup npm ci using cache?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论