saci.cc
← Blog

Email tests in GitHub Actions: secrets, shards and limits

A test that waits for a verification email runs fine on your laptop. CI brings new questions: where the key goes, what happens on pull requests from forks, how many tests can wait for email at once and what to do when one fails. This guide answers each one, with GitHub Actions, Playwright and the saci.cc npm package.

If you don't have a test like this yet, start with the Playwright guide.

The key as a secret

Create a key on your account page, just for CI. One key per environment (your laptop, CI, staging) lets you revoke one without stopping the others.

In the repository, open Settings → Secrets and variables → Actions and add a SACI_API_KEY secret. The client reads that variable, so you only need to pass it to the test step:

# .github/workflows/e2e.yml
name: e2e
on: [push, pull_request]

jobs:
  e2e:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-node@v5
        with:
          node-version: 24
      - run: npm ci
      - run: npx playwright install --with-deps
      - run: npx playwright test
        env:
          SACI_API_KEY: ${{ secrets.SACI_API_KEY }}

Fork and Dependabot PRs don't get the secret

GitHub doesn't pass secrets to workflows triggered by a pull request from a fork, or to Dependabot's pull requests. There SACI_API_KEY is empty and every test that creates an inbox fails. Skip those tests when there's no key instead of turning the PR red:

import { test } from "@playwright/test";

test.skip(!process.env.SACI_API_KEY, "No SACI_API_KEY (fork PR?)");

Put that line at the top of the files that wait for email. The other tests still run, and the email tests run again once the PR is merged.

One inbox per test

In parallel, two tests sharing an inbox read each other's email. Create the inbox inside the test, with createInbox() and no name, and every test, worker and retry gets a fresh address. Fixed names like createInbox({ name: "signup" }) only suit tests that never run at the same time.

If several steps use the same inbox, a fixture keeps the test tidy:

import { test as base } from "@playwright/test";
import { createInbox, type Inbox } from "saci.cc";

export const test = base.extend<{ inbox: Inbox }>({
  inbox: async ({}, use, testInfo) => {
    const inbox = await createInbox();
    // The address shows up in the report, to look into a failure
    testInfo.annotations.push({ type: "inbox", description: inbox.address });
    await use(inbox);
  },
});

Shards and parallel workers

Playwright splits the suite across machines with --shard. With a matrix, four jobs run at once:

    strategy:
      fail-fast: false
      matrix:
        shard: [1/4, 2/4, 3/4, 4/4]
    steps:
      # ...the same steps as before...
      - run: npx playwright test --shard=${{ matrix.shard }}
        env:
          SACI_API_KEY: ${{ secrets.SACI_API_KEY }}

All of an account's keys share one requests-per-minute limit: 120 on Free, 600 on Pro and 2,000 on Team. Waiting for an email is cheap, because the client asks the API to hold the request for up to 25 seconds, so each waiting test uses about 3 requests a minute. In practice, about 30 waits at once fit in Free. Past the limit the API answers 429 and the client waits and retries, so the test gets slower but doesn't break.

How many inboxes your suite creates a month

On Free, an account's keys create up to 1,000 inboxes a month. Do the math: 20 email tests running on 10 pushes a day, 22 working days, make 4,400 inboxes, and from the 1,000th on, creating an inbox answers 402 until the month turns. If your account goes past that, the Pro and Team plans have no inbox cap. Before subscribing, you can save:

  • Run the email tests only on pull_request and the main branch, not on every push.
  • Fold sign-up, confirmation and login into one test with one inbox.
  • Tag the email tests (@email) and run them with --grep @email in a job that doesn't run on every commit.

Timeouts and retries

Playwright gives each test 30 seconds, and an email can take longer. Use test.setTimeout(90_000) in tests that wait for email. The client waits up to 60 seconds by default, then throws SaciTimeoutError with a message that says what it was waiting for.

In CI, turn on retries in your Playwright config:

// playwright.config.ts
export default defineConfig({
  retries: process.env.CI ? 2 : 0,
  reporter: process.env.CI ? [["github"], ["html"]] : "list",
});

Since the inbox is created inside the test, each retry starts with an empty inbox and doesn't read the previous attempt's email.

When a test fails

The address the fixture annotated shows up in the HTML report. Inboxes created with your key stay with your account for 7 days on Free (30 on Pro, 90 on Team), and emails stay for about a day. So you can open the email right after the failure and see whether it arrived with another subject, from another sender or without the code:

curl "https://saci.cc/api/addresses/ADDRESS/emails" \
  -H "Authorization: Bearer $SACI_API_KEY"

In short

  • SACI_API_KEY as a secret, with a key just for CI.
  • test.skip when there's no key, for fork and Dependabot PRs.
  • One inbox per test, created inside it, with the address in the report.
  • A 90-second timeout, retries in CI and an eye on inboxes per month.