Skip to content
Source
Sign inSign up

Finish a converted e2e workflow

CI / Start

Finish a converted e2e workflow

src ci convert turns off the traces upload of your sharded end-to-end tests, and leaves TODOs on each upload step. This example finishes those TODOs for the e2e workflow of tanstack/ai, and gives its gate job no container.

3 min read

You need:

1. Read what the converter wrote

tanstack/ai runs its end-to-end tests in 4 shards. A gate job reports one result for all of them. This is part of .github/workflows/e2e.yml:

jobs:
  e2e:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    strategy:
      matrix:
        shard: [1, 2, 3, 4]
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 0
      # ...
      - name: Run E2E Tests
        env:
          SHARD: ${{ matrix.shard }}
        run: pnpm --filter @tanstack/ai-e2e test:e2e --shard="$SHARD/4"

      - name: Upload Traces (on failure)
        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
        if: failure()
        with:
          name: e2e-traces-${{ matrix.shard }}
          path: testing/e2e/test-results/**/*.zip
          retention-days: 14

  e2e-result:
    name: E2E Tests
    needs: e2e
    if: ${{ !cancelled() }}
    runs-on: ubuntu-latest
    steps:
      - name: Check shard results
        env:
          RESULT: ${{ needs.e2e.result }}
        run: test "$RESULT" = success

This is the same part of .source/workflows/e2e.ts, as src ci convert writes it:

export default defineWorkflow('e2e', {
  on: [pullRequest(), push({ branches: ['main', 'alpha', 'beta', 'rc'] })],
})
  .job('e2e', {
    // TODO(convert): check the egress hosts: they are guessed from the job's commands, and its scripts can reach others
    // TODO(convert): its secrets take their values from the CI environment development; pick the job's environment
    image: 'browser',
    size: 'medium',
    timeoutMinutes: 30,
    checkout: { depth: 0 },
    matrix: { shard: [1, 2, 3, 4] },
    environment: 'development',
    secrets: { NX_CLOUD_ACCESS_TOKEN: { optional: true } },
    egress: ['registry.npmjs.org', 'cloud.nx.app', 'cdn.playwright.dev', 'playwright.download.prss.microsoft.com'],
    steps: [
      // ...
      {
        name: 'Run E2E Tests',
        do: (ctx) => ctx.sh`SHARD=${ctx.matrix.shard} bash -ec ${'pnpm --filter @tanstack/ai-e2e test:e2e --shard="$SHARD/4"'}`,
      },
      // ...
      // TODO(convert): the input name of actions/upload-artifact reads ${{ matrix.shard }}, but built-in steps take fixed values
      // TODO(convert): this step ran only after a failed step (failure()), but a failed step stops the job here; the step is off
      { ...artifact({ name: 'e2e-traces-${{ matrix.shard }}', paths: ['testing/e2e/test-results/**/*.zip'], retentionDays: 14 }), if: () => false },
    ],
  })
  .job('e2e-result', {
    // TODO(convert): its secrets take their values from the CI environment development; pick the job's environment
    needs: ['e2e'],
    when: 'always',
    environment: 'development',
    secrets: { NX_CLOUD_ACCESS_TOKEN: { optional: true } },
    steps: [
      {
        name: 'Check shard results',
        do: (ctx) => ctx.sh`RESULT=${ctx.needs.e2e.result} bash -ec ${'test "$RESULT" = success'}`,
      },
    ],
  })

What the converter did:

  • actions/checkout is built in. fetch-depth: 0 is checkout: { depth: 0 }.
  • The job runs Playwright, so it gets the browser image and the medium size.
  • ${{ matrix.shard }} goes to the script in the variable SHARD, never as script text.
  • if: ${{ !cancelled() }} on the gate job is when: 'always'.
  • A failed step stops the job here. So each upload step has a TODO, and the traces upload is off.

Note

Each job with secrets also gets environment: 'development' and a TODO. Step 6 of Move from GitHub Actions covers the environments of the secrets.

2. Upload the results after the job

The converted e2e job has three artifact() upload steps, each with 2 TODOs. Delete the three steps and their TODOs. Then put this step in the e2e job, after its setup and install steps:

{
  name: 'Upload results after the job',
  do: (ctx) => {
    const upload = (name: string, paths: string[]) =>
      ctx.afterJob((after) => artifact({ name: `${name}-${ctx.matrix.shard}`, paths, retentionDays: 14 }).do(after), { always: true })
    upload('e2e-videos', ['testing/e2e/test-results/**/*.webm'])
    upload('e2e-report', ['testing/e2e/playwright-report/'])
    upload('e2e-traces', ['testing/e2e/test-results/**/*.zip'])
  },
},
  • ctx.afterJob runs each upload after the last step of the job. With always: true, it runs also when a step failed.
  • The step comes before the tests, so it registers the uploads before a test can fail.
  • When no file matches, an upload sends nothing, and the job does not fail.

3. Check the plan

Run src ci plan. It shows the 4 shards and the gate:

e2e (.source/workflows/e2e.ts)
  on: pull request, push (branches: main, alpha, beta, rc)
  jobs:
    e2e: 4 matrix cells (shard: 1, 2, 3, 4)
    e2e-result: needs e2e; runs always

4. Replace the gate job

The e2e-result job only checks that every shard passed, but it still waits for a container. Replace the job with one that the forge decides with no container:

  .requireAll('e2e-result', { needs: ['e2e'] })

It passes only when every shard of e2e passed, so the required check e2e/e2e-result stays the same. src ci plan now shows e2e-result: requires all of e2e. See Require all jobs with one check.

Done

Each shard uploads its videos, report and traces after its last step, also when a test failed. One required check, e2e/e2e-result, covers the 4 shards, and it takes no container.