-
Notifications
You must be signed in to change notification settings - Fork 1
125 lines (105 loc) · 3.52 KB
/
test-and-deploy.yml
File metadata and controls
125 lines (105 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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'
})