Skip to content

Merge staging into main #353

Merge staging into main

Merge staging into main #353

name: Test & Deploy
on:
pull_request:
branches: [staging, main]
push:
branches: [staging, main]
jobs:
# Enforce that PRs to main must come from staging branch
check-source:
if: github.event_name == 'pull_request' && github.base_ref == 'main'
runs-on: ubuntu-latest
name: check-source
steps:
- name: Verify PR is from staging
run: |
if [ "${{ github.head_ref }}" != "staging" ]; then
echo "ERROR: PRs to main must come from the staging branch."
echo "Current source branch: ${{ github.head_ref }}"
echo ""
echo "Please merge your changes to staging first, then create a PR from staging to main."
exit 1
fi
echo "Source branch verified: staging -> main"
# Full test suite - only runs for staging branch
test:
if: github.base_ref == 'staging' || github.ref == 'refs/heads/staging'
runs-on: ubuntu-latest
name: test
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Install Playwright Chromium only
run: npx playwright install chromium
# Fetch data - uses fallbacks automatically when MongoDB unavailable
- name: Fetch bootstrap data
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
run: |
echo "Running data fetch (will use fallbacks if MongoDB unavailable)..."
npm run fetch:all
# Run tests and build for all PRs and pushes
- name: Run tests and build
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
run: |
echo "Running full test suite and build..."
npm run build
# Upload Playwright test results
- name: Upload Playwright test results
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
# Lighter verification for main - just verify build succeeds
verify-main:
if: github.base_ref == 'main' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
name: verify-main
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 22
- name: Install dependencies
run: npm ci
- name: Fetch bootstrap data
env:
MONGODB_URI: ${{ secrets.MONGODB_URI }}
run: npm run fetch:all
- name: Verify build
run: |
echo "Verifying production build..."
npx next build
deploy:
needs: test
if: github.ref == 'refs/heads/staging'
runs-on: ubuntu-latest
name: deploy
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Mark deployment ready
run: echo "Tests passed - ready for deployment"
- name: Set deployment status
uses: actions/github-script@v7
with:
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'success',
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: 'Tests passed - Vercel deployment triggered',
context: 'ci/deployment-triggered'
})