Skip to content

Latest commit

 

History

History
201 lines (148 loc) · 12.1 KB

ci-cd.md

File metadata and controls

201 lines (148 loc) · 12.1 KB

CI/CD

This framework runs on GitHub Actions with Bun. Three workflows cover pull requests, nightly runs, and production checks. Each job uses a GitHub Environment, which scopes the credentials to that environment.

Workflows

Workflow File Trigger Environment Stages
CI .github/workflows/ci.yml pull request and push to main dev (smoke stage only) Format check, Lint, Smoke tests (dev), CI
Nightly .github/workflows/nightly.yml 02:00 UTC daily, or manual qa and staging (matrix) Smoke and integration
Production smoke .github/workflows/prod-smoke.yml 06:00 UTC on weekdays, or manual production Production smoke (@prod)
Sauce Labs .github/workflows/sauce.yml manual only dev Validate and run on Sauce Labs (see sauce-labs.md)
Dependency audit .github/workflows/audit.yml 05:00 UTC on Mondays, or manual none bun audit against the npm advisory database

Failed scheduled runs

When a scheduled nightly or production smoke run fails, a report-failure job opens one issue titled Scheduled run failed: <workflow>, labelled scheduled-failure, and links the run. Later failures add a comment to that open issue rather than opening another. Close the issue once the failure is fixed. Manual runs do not open issues.

The job requests only issues: write, and it runs only for scheduled events. Failure issues are created only after the scheduled-runs switch is set (see Turning on scheduled runs).

CI stages

The CI workflow has four jobs. Each one appears as its own box in the Actions graph.

flowchart LR
    F["Format check"] --> S["Smoke tests (dev)"]
    L["Lint"] --> S
    F --> C["CI"]
    L --> C
    S --> C
Loading

Text alternative: Format check and Lint run in parallel. Smoke tests (dev) run only when both pass. The final job, CI, passes only when all three succeeded. Branch protection requires CI.

Job Shown as Waits for Environment Purpose
format Format check nothing none bun run format:check
lint Lint nothing none bun run lint
smoke Smoke tests (dev) format, lint dev Browser install, bun run test:smoke, summary, report upload
ci CI format, lint, smoke none Fails unless every stage succeeded, including skipped or cancelled stages

Format and Lint need no secrets, so they also run for pull requests from forks. Only the smoke stage selects the dev Environment, because only it needs E2E_USERNAME and E2E_PASSWORD.

A failed gate skips the smoke stage. The CI job then fails, because a skipped stage is not a success.

Nightly and production

Both workflows have one test stage, so they keep a single job. Their steps are named the same way: Checkout, Setup Bun, Setup Playwright, Run tests, Summary, Upload reports. The nightly matrix runs qa and staging as separate jobs.

flowchart TD
    SCHED1["Schedule 02:00 UTC"] --> NIGHT["nightly.yml: matrix qa and staging"]
    MANUAL1["Manual run"] --> NIGHT
    SCHED2["Schedule weekdays 06:00 UTC"] --> PROD["prod-smoke.yml: @prod on production"]
    MANUAL2["Manual run"] --> PROD
    NIGHT --> ART["Summary and reports/ artifact"]
    PROD --> ART
Loading

Text alternative: a nightly schedule or a manual run executes the matrix on qa and staging. A weekday schedule or a manual run executes @prod tests on production. Both write a run summary and upload reports/ as an artifact.

Turning on scheduled runs

The nightly and production workflows skip their scheduled runs until you turn them on. Without this, the first scheduled run would fail, because the qa, staging, and production environments and their secrets do not exist yet. Manual runs (workflow_dispatch) always work, so you can test each environment first.

Turn them on in this order:

  1. Create each environment and set its E2E_USERNAME and E2E_PASSWORD secrets (see Environments and secrets).
  2. Run each workflow manually and confirm it passes.
  3. Set the repository variable:
    gh variable set ENABLE_SCHEDULED_RUNS --body true --repo <owner>/<repo>

To pause scheduled runs again, set the variable to any value other than true. The skipped scheduled runs show as skipped, not failed.

Shared actions

Two local composite actions replace the setup steps that used to be copied into each workflow:

Action Path Does
Setup Bun .github/actions/setup-bun Installs Bun, restores the Bun package cache keyed on bun.lock, runs bun install --frozen-lockfile
Setup Playwright .github/actions/setup-playwright Reads the installed Playwright version, restores the browser cache, then installs Chromium on a miss or only its system dependencies on a hit

Both need the repository checked out first. Setup Playwright must run after Setup Bun, because it reads the version from the installed dependencies.

Run summary

After each test run, scripts/ci-summary.js writes a short Markdown table to the run's summary page: environment, total tests, passed, failed, and skipped. It reads reports/junit/results.xml, which Playwright writes when CI is set. If the file is missing, the summary says so and the step still succeeds, so a summary problem never fails a run.

Environments and secrets

Each job selects a GitHub Environment with environment:. The environment's secrets are the only credentials the job can read.

GitHub Environment Secrets Protection
dev E2E_USERNAME, E2E_PASSWORD none
qa E2E_USERNAME, E2E_PASSWORD none
staging E2E_USERNAME, E2E_PASSWORD optional
production E2E_USERNAME, E2E_PASSWORD required reviewers recommended

Set them up once. Replace <owner>/<repo> with the repository, for example codewithmmak/playwright-javascript. Run these as an account with admin rights on the repository.

# Create the environments (idempotent)
gh api --method PUT repos/<owner>/<repo>/environments/dev
gh api --method PUT repos/<owner>/<repo>/environments/qa
gh api --method PUT repos/<owner>/<repo>/environments/staging
gh api --method PUT repos/<owner>/<repo>/environments/production

# Set secrets. gh prompts for the value, so it is not stored in shell history.
gh secret set E2E_USERNAME --env dev --repo <owner>/<repo>
gh secret set E2E_PASSWORD --env dev --repo <owner>/<repo>

Repeat the two gh secret set commands for qa, staging, and production with the accounts for each environment.

Required reviewers for production: set them in Settings → Environments → production → Required reviewers. The API needs reviewer IDs, so the UI is simpler. If reviewers are required, a scheduled prod-smoke run waits for approval before it starts. Decide whether that is what you want before you enable it.

Remove old secrets. Repository secrets ORANGEHRM_USERNAME and ORANGEHRM_PASSWORD were used before this layout. Delete them once the dev environment has E2E_* secrets:

gh secret delete ORANGEHRM_USERNAME --repo <owner>/<repo>
gh secret delete ORANGEHRM_PASSWORD --repo <owner>/<repo>

Forks: pull requests from forks do not receive environment secrets, so the smoke stage fails for them. Format and Lint still run. This is expected.

Branch protection

Protect main so that merges require the aggregate CI check to pass.

The protection rule must name the check that the workflow reports. Before the stage split, that was "Format, lint, and smoke tests (dev)". That name no longer exists. A rule that still requires it blocks every merge.

Safe order when changing the rule:

  1. Open the pull request. Its run reports a check named CI on the pull request head.
  2. Wait until CI is green.
  3. In Settings → Branches, change the required check for main to CI, or run:
    gh api --method PUT repos/<owner>/<repo>/branches/main/protection --input protection.json
    where protection.json has required_status_checks.contexts set to ["CI"]. This is an admin action.
  4. Merge the pull request normally. Its own CI check satisfies the new rule.

Optionally require one approving review as well.

Job steps

Every job follows the same pattern:

  1. Checkout (actions/checkout, pinned to a commit SHA)
  2. Setup Bun (local action, installs locked dependencies)
  3. Setup Playwright (local action, browser cache), for jobs that run tests
  4. The command, with TEST_ENV and the environment's secrets
  5. Summary (scripts/ci-summary.js), always
  6. Upload reports/ as an artifact, always, retained for 14 to 30 days

Permissions are contents: read. Actions are pinned to commit SHAs. Renovate updates the pins, with a comment naming the version (see renovate.json).

Reports

Each run uploads an artifact named for the workflow, the environment, and the run ID. The run summary shows the result table and names the artifact. Open monocart/index.html from the artifact to view the full report. See reporting.md.

Troubleshooting

Symptom Likely cause
Set E2E_USERNAME and E2E_PASSWORD in the Smoke tests log The dev Environment is missing secrets
The CI check is red but no test ran A format or lint stage failed. Smoke tests is skipped, and CI reports the stage results
Pull requests wait for a check named "Format, lint, and smoke tests (dev)" Branch protection still requires the old name. Change it to CI (see Branch protection)
Job waits at "Waiting for approval" The production environment has required reviewers and this is a scheduled run
The smoke stage fails only on a fork pull request Forks do not receive secrets (expected)
bun install --frozen-lockfile fails bun.lock is out of date. Run bun install locally and commit the lockfile
The run summary says "No JUnit results were written" The test step failed before Playwright wrote its results, so check that step's log