GitHub Actionsbeginner
GitHub Actions Email Testing
CI/CD workflow for email testing with GitHub Actions
GitHub Actions Email Testing (yaml)yaml
# .github/workflows/email-tests.yml
name: Email Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
# Use run ID for unique test isolation
TEST_MAILBOX: ci-${{ github.run_id }}
jobs:
email-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Start application
run: npm run dev &
env:
DATABASE_URL: ${{ secrets.TEST_DATABASE_URL }}
- name: Wait for app to be ready
run: npx wait-on http://localhost:3000 --timeout 60000
- name: Run email tests
run: npm run test:email
env:
PLOP_API_KEY: ${{ secrets.PLOP_API_KEY }}
BASE_URL: http://localhost:3000
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: email-test-results
path: |
test-results/
playwright-report/
- name: Upload screenshots on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: failure-screenshots
path: test-results/**/*.png
# Optional: Test against staging
staging-email-tests:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: email-tests
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Install Playwright
run: npx playwright install --with-deps chromium
- name: Run staging email tests
run: npm run test:email
env:
PLOP_API_KEY: ${{ secrets.PLOP_API_KEY }}
BASE_URL: https://staging.yourapp.com
TEST_MAILBOX: staging-${{ github.run_id }}
# Example package.json scripts:
# "test:email": "playwright test tests/email/",
# "test:email:headed": "playwright test tests/email/ --headed"How It Works
1
Test Isolation
Using github.run_id in the mailbox name ensures each CI run is isolated. No conflicts between parallel runs.
2
Secrets Management
The PLOP_API_KEY is stored in GitHub Secrets, never exposed in logs or code.
3
Artifact Upload
Test results and screenshots are uploaded as artifacts for debugging failed tests.
4
Staging Tests
A separate job runs against staging after main branch merges, using a different test mailbox.