0

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?

Probosckie
  • 1,585
  • 4
  • 25
  • 40

0 Answers0