Workflow ID: _bmad/bmm/testarch/ci
Version: 4.0 (BMad v6)
Scaffolds a production-ready CI/CD quality pipeline with test execution, burn-in loops for flaky test detection, parallel sharding, artifact collection, and notification configuration. This workflow creates platform-specific CI configuration optimized for fast feedback and reliable test execution.
Note: This is typically a one-time setup per repo; run it any time after the test framework exists, ideally before feature work starts.
Critical: Verify these requirements before proceeding. If any fail, HALT and notify the user.
.git/ directory exists)npm run test:e2e succeeds)framework workflow)Verify Git Repository
.git/ directorygit remote -v)Validate Test Framework
playwright.config.* or cypress.config.*framework workflow first to set up test infrastructure"Run Local Tests
npm run test:e2e (or equivalent from package.json)Detect CI Platform
.github/workflows/*.yml (GitHub Actions).gitlab-ci.yml (GitLab CI).circleci/config.yml (Circle CI)Jenkinsfile (Jenkins)github.com → GitHub Actions (default)gitlab.com → GitLab CIRead Environment Configuration
.nvmrc for Node version if presentpackage.json to identify dependencies (affects caching strategy)Halt Condition: If preflight checks fail, stop immediately and report which requirement failed.
Based on detection or user preference, use the appropriate template:
GitHub Actions (.github/workflows/test.yml):
GitLab CI (.gitlab-ci.yml):
Circle CI (.circleci/config.yml):
Jenkins (Jenkinsfile):
Use templates from {installed_path}/ directory:
github-actions-template.ymlgitlab-ci-template.ymlKey pipeline stages:
stages:
- lint # Code quality checks
- test # Test execution (parallel shards)
- burn-in # Flaky test detection
- report # Aggregate results and publish
Parallel Sharding:
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- name: Run tests
run: npm run test:e2e -- --shard=${{ matrix.shard }}/${{ strategy.job-total }}
Purpose: Splits tests into N parallel jobs for faster execution (target: <10 min per shard)
Critical pattern from production systems:
burn-in:
name: Flaky Test Detection
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install dependencies
run: npm ci
- name: Run burn-in loop (10 iterations)
run: |
for i in {1..10}; do
echo "🔥 Burn-in iteration $i/10"
npm run test:e2e || exit 1
done
- name: Upload failure artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: burn-in-failures
path: test-results/
retention-days: 30
Purpose: Runs tests multiple times to catch non-deterministic failures before they reach main branch.
When to run:
Node modules cache:
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
Browser binaries cache (Playwright):
- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
Purpose: Reduces CI execution time by 2-5 minutes per run.
Failure artifacts only:
- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.shard }}
path: |
test-results/
playwright-report/
retention-days: 30
Artifacts to collect:
Add Retry Logic
- name: Run tests with retries
uses: nick-invision/retry@v2
with:
timeout_minutes: 30
max_attempts: 3
retry_on: error
command: npm run test:e2e
Purpose: Handles transient failures (network issues, race conditions)
If notify_on_failure is enabled:
- name: Notify on failure
if: failure()
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
text: 'Test failures detected in PR #${{ github.event.pull_request.number }}'
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
Selective testing script (scripts/test-changed.sh):
#!/bin/bash
# Run only tests for changed files
CHANGED_FILES=$(git diff --name-only HEAD~1)
if echo "$CHANGED_FILES" | grep -q "src/.*\.ts$"; then
echo "Running affected tests..."
npm run test:e2e -- --grep="$(echo $CHANGED_FILES | sed 's/src\///g' | sed 's/\.ts//g')"
else
echo "No test-affecting changes detected"
fi
Local mirror script (scripts/ci-local.sh):
#!/bin/bash
# Mirror CI execution locally for debugging
echo "🔍 Running CI pipeline locally..."
# Lint
npm run lint || exit 1
# Tests
npm run test:e2e || exit 1
# Burn-in (reduced iterations)
for i in {1..3}; do
echo "🔥 Burn-in $i/3"
npm run test:e2e || exit 1
done
echo "✅ Local CI pipeline passed"
Generate Documentation
CI README (docs/ci.md):
Secrets checklist (docs/ci-secrets-checklist.md):
CI Configuration File
.github/workflows/test.yml (GitHub Actions).gitlab-ci.yml (GitLab CI).circleci/config.yml (Circle CI)Pipeline Stages
Helper Scripts
scripts/test-changed.sh - Selective testingscripts/ci-local.sh - Local CI mirrorscripts/burn-in.sh - Standalone burn-in executionDocumentation
docs/ci.md - CI pipeline guidedocs/ci-secrets-checklist.md - Required secretsOptimization Features
Speedup: 20× faster than sequential execution through parallelism and caching.
Critical: Check configuration and load appropriate fragments.
Read {config_source} and check config.tea_use_playwright_utils.
Core CI Patterns (Always load):
ci-burn-in.md - Burn-in loop patterns: 10-iteration detection, GitHub Actions workflow, shard orchestration, selective execution (678 lines, 4 examples)selective-testing.md - Changed test detection strategies: tag-based, spec filters, diff-based selection, promotion rules (727 lines, 4 examples)visual-debugging.md - Artifact collection best practices: trace viewer, HAR recording, custom artifacts, accessibility integration (522 lines, 5 examples)test-quality.md - CI-specific test quality criteria: deterministic tests, isolated with cleanup, explicit assertions, length/time optimization (658 lines, 5 examples)playwright-config.md - CI-optimized configuration: parallelization, artifact output, project dependencies, sharding (722 lines, 5 examples)If config.tea_use_playwright_utils: true:
Load playwright-utils CI-relevant fragments:
burn-in.md - Smart test selection with git diff analysis (very important for CI optimization)network-error-monitor.md - Automatic HTTP 4xx/5xx detection (recommend in CI pipelines)Recommend:
*framework and *automate workflowsGitHub Actions:
actions/cache for cachingGitLab CI:
.gitlab-ci.yml in rootcache: directive for cachingparallel: 4Circle CI:
.circleci/config.ymlparallelism: 4When to run:
Iterations:
Failure threshold:
Failure artifacts only:
Artifact types:
Detect changed files:
git diff --name-only HEAD~1
Run affected tests only:
Trade-off:
Purpose: Debug CI failures locally
Usage:
./scripts/ci-local.sh
Mirrors CI environment:
After completing this workflow, provide a summary:
## CI/CD Pipeline Complete
**Platform**: GitHub Actions (or GitLab CI, etc.)
**Artifacts Created**:
- ✅ Pipeline configuration: .github/workflows/test.yml
- ✅ Burn-in loop: 10 iterations for flaky detection
- ✅ Parallel sharding: 4 jobs for fast execution
- ✅ Caching: Dependencies + browser binaries
- ✅ Artifact collection: Failure-only traces/screenshots/videos
- ✅ Helper scripts: test-changed.sh, ci-local.sh, burn-in.sh
- ✅ Documentation: docs/ci.md, docs/ci-secrets-checklist.md
**Performance:**
- Lint: <2 min
- Test (per shard): <10 min
- Burn-in: <30 min
- Total: <45 min (20× speedup vs sequential)
**Next Steps**:
1. Commit CI configuration: `git add .github/workflows/test.yml && git commit -m "ci: add test pipeline"`
2. Push to remote: `git push`
3. Configure required secrets in CI platform settings (see docs/ci-secrets-checklist.md)
4. Open a PR to trigger first CI run
5. Monitor pipeline execution and adjust parallelism if needed
**Knowledge Base References Applied**:
- Burn-in loop pattern (ci-burn-in.md)
- Selective testing strategy (selective-testing.md)
- Artifact collection (visual-debugging.md)
- Test quality criteria (test-quality.md)
After completing all steps, verify:
chmod +x)Refer to checklist.md for comprehensive validation criteria.