|
| 1 | +name: Unit tests |
| 2 | + |
| 3 | +on: |
| 4 | + # Build on pushes branches that have a PR (including drafts) |
| 5 | + pull_request: |
| 6 | + # Build on commits pushed to branches without a PR if it's in the allowlist |
| 7 | + push: |
| 8 | + branches: [next] |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + timeout-minutes: 60 |
| 13 | + name: Jest tests (${{ matrix.os }} / node ${{ matrix.node }}) |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + env: |
| 16 | + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} |
| 17 | + TURBO_TEAM: ${{ vars.TURBO_TEAM }} |
| 18 | + continue-on-error: ${{ matrix.experimental }} |
| 19 | + |
| 20 | + strategy: |
| 21 | + # we want to know if a test fails on a specific node version |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + os: [ubuntu-latest] |
| 25 | + node: [18, 20] |
| 26 | + experimental: [false] |
| 27 | + shardIndex: [1, 2, 3, 4] |
| 28 | + shardTotal: [4] |
| 29 | + # include: |
| 30 | + # - os: windows-latest |
| 31 | + # node: 16 |
| 32 | + # experimental: true |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Setup node |
| 39 | + uses: actions/setup-node@v4 |
| 40 | + with: |
| 41 | + node-version: ${{ matrix.node }} |
| 42 | + |
| 43 | + - uses: pnpm/action-setup@v4 |
| 44 | + name: Install pnpm |
| 45 | + id: pnpm-install |
| 46 | + with: |
| 47 | + run_install: false |
| 48 | + |
| 49 | + - name: Get pnpm store directory |
| 50 | + id: pnpm-cache |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT |
| 54 | +
|
| 55 | + - name: Cache node modules |
| 56 | + id: cache-node-modules |
| 57 | + uses: actions/cache@v4 |
| 58 | + env: |
| 59 | + cache-name: cache-node-modules |
| 60 | + with: |
| 61 | + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} |
| 62 | + key: ${{ runner.os }}-pnpm-store-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 63 | + restore-keys: | |
| 64 | + v1-${{ runner.os }}-pnpm-store-${{ env.cache-name }}- |
| 65 | + v1-${{ runner.os }}-pnpm-store- |
| 66 | + v1-${{ runner.os }}- |
| 67 | +
|
| 68 | + - name: Install project dependencies |
| 69 | + run: pnpm install |
| 70 | + |
| 71 | + - name: Test |
| 72 | + id: test |
| 73 | + run: | |
| 74 | + node -v |
| 75 | + pnpm test:jest --silent --shard=${{ matrix.shardIndex}}/${{ matrix.shardTotal }} --ignoreProjects=@sanity/cli |
| 76 | + env: |
| 77 | + GITHUB_SHARD_IDENTIFIER: ${{ matrix.shardIndex }}-${{ matrix.shardTotal }} |
0 commit comments