-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (208 loc) · 8.63 KB
/
Copy pathdeploy.yml
File metadata and controls
231 lines (208 loc) · 8.63 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Deployment workflow for the JHB Software website.
#
# This workflow deploys the CMS before the Web frontend to ensure the frontend
# always builds against the latest CMS schema and content. The Web frontend
# fetches data from the CMS at build time, so the CMS must be deployed first.
#
# Production: Triggered on push to main
# Preview: Triggered on pull requests, uses CMS preview URL for Web build
#
# Skip builds by adding to commit message:
# - [skip-cms] - Skip CMS deployment
# - [skip-web] - Skip Web deployment
#
# For CMS-triggered web rebuilds (content updates), use Vercel's deployment hook:
# Vercel → Web project → Settings → Git → Deploy Hooks
#
# Prerequisites:
# - Disable automatic Vercel deployments for both projects to avoid race conditions
# - Set up CMS_VERCEL_AUTOMATION_BYPASS_SECRET to allow Web builds to fetch from protected CMS previews
name: Deploy
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
deploy_cms:
description: 'Deploy CMS'
required: false
default: true
type: boolean
deploy_web:
description: 'Deploy Web'
required: false
default: true
type: boolean
environment:
description: 'Environment'
required: false
default: 'preview'
type: choice
options:
- preview
- production
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
jobs:
detect-changes:
name: Detect Changes
runs-on: ubuntu-latest
outputs:
cms_changed: ${{ steps.changes.outputs.cms_changed }}
web_changed: ${{ steps.changes.outputs.web_changed }}
skip_cms: ${{ steps.skip.outputs.skip_cms }}
skip_web: ${{ steps.skip.outputs.skip_web }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Check for skip tags
id: skip
env:
COMMIT_MSG: ${{ github.event.head_commit.message || github.event.pull_request.title || '' }}
run: |
echo "skip_cms=$([[ "$COMMIT_MSG" == *"[skip-cms]"* ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
echo "skip_web=$([[ "$COMMIT_MSG" == *"[skip-web]"* ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
- name: Detect changed files
id: changes
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# Manual trigger: use input values
echo "cms_changed=true" >> $GITHUB_OUTPUT
echo "web_changed=true" >> $GITHUB_OUTPUT
else
# Push/PR: detect actual changes
if [ "${{ github.event_name }}" == "pull_request" ]; then
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
else
BASE_SHA=${{ github.event.before }}
HEAD_SHA=${{ github.sha }}
fi
CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA 2>/dev/null || echo "")
# Check if cms/ or web/ folders have changes (or workflow file)
CMS_CHANGED=$([[ "$CHANGED_FILES" == *"cms/"* ]] || [[ "$CHANGED_FILES" == *".github/workflows/deploy.yml"* ]] && echo 'true' || echo 'false')
WEB_CHANGED=$([[ "$CHANGED_FILES" == *"web/"* ]] || [[ "$CHANGED_FILES" == *".github/workflows/deploy.yml"* ]] && echo 'true' || echo 'false')
echo "cms_changed=$CMS_CHANGED" >> $GITHUB_OUTPUT
echo "web_changed=$WEB_CHANGED" >> $GITHUB_OUTPUT
echo "Changed files: $CHANGED_FILES"
fi
deploy-cms:
name: Deploy CMS
runs-on: ubuntu-latest
needs: detect-changes
if: |
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_cms == 'true') ||
(github.event_name != 'workflow_dispatch' &&
needs.detect-changes.outputs.cms_changed == 'true' &&
needs.detect-changes.outputs.skip_cms == 'false')
outputs:
deployment_url: ${{ steps.deploy.outputs.deployment_url }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Vercel CLI
run: npm install -g vercel
- name: Deploy to Vercel
id: deploy
run: |
IS_PROD=${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event.inputs.environment == 'production' }}
PROD_FLAG=""
if [ "$IS_PROD" == "true" ]; then
PROD_FLAG="--prod"
fi
DEPLOYMENT_URL=$(vercel deploy $PROD_FLAG --yes --token=${{ secrets.VERCEL_TOKEN }})
echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_CMS_PROJECT_ID }}
deploy-web:
name: Deploy Web
runs-on: ubuntu-latest
needs: [detect-changes, deploy-cms]
if: |
always() &&
(needs.deploy-cms.result == 'success' || needs.deploy-cms.result == 'skipped') &&
(
(github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_web == 'true') ||
(github.event_name != 'workflow_dispatch' &&
needs.detect-changes.outputs.web_changed == 'true' &&
needs.detect-changes.outputs.skip_web == 'false')
)
outputs:
deployment_url: ${{ steps.deploy.outputs.deployment_url }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Install Vercel CLI
run: npm install -g vercel
- name: Deploy to Vercel
id: deploy
run: |
IS_PROD=${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event.inputs.environment == 'production' }}
CMS_URL="${{ needs.deploy-cms.outputs.deployment_url }}"
if [ "$IS_PROD" == "true" ]; then
DEPLOYMENT_URL=$(vercel deploy --prod --yes --token=${{ secrets.VERCEL_TOKEN }} \
--build-env ENABLE_EXPERIMENTAL_COREPACK=1)
elif [ -n "$CMS_URL" ]; then
# Preview with CMS preview URL and bypass secret for Vercel Authentication
DEPLOYMENT_URL=$(vercel deploy --yes --token=${{ secrets.VERCEL_TOKEN }} \
--build-env ENABLE_EXPERIMENTAL_COREPACK=1 \
--build-env CMS_URL=$CMS_URL \
--build-env CMS_VERCEL_AUTOMATION_BYPASS_SECRET=${{ secrets.CMS_VERCEL_AUTOMATION_BYPASS_SECRET }} \
--env CMS_URL=$CMS_URL \
--env CMS_VERCEL_AUTOMATION_BYPASS_SECRET=${{ secrets.CMS_VERCEL_AUTOMATION_BYPASS_SECRET }})
else
# Preview without CMS override (uses production CMS from Vercel env vars)
echo "CMS deployment skipped, using production CMS from Vercel env vars"
DEPLOYMENT_URL=$(vercel deploy --yes --token=${{ secrets.VERCEL_TOKEN }} \
--build-env ENABLE_EXPERIMENTAL_COREPACK=1)
fi
echo "deployment_url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
env:
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_WEB_PROJECT_ID }}
- name: Deployment Summary
run: |
echo "## Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Project | URL |" >> $GITHUB_STEP_SUMMARY
echo "|---------|-----|" >> $GITHUB_STEP_SUMMARY
echo "| CMS | ${{ needs.deploy-cms.outputs.deployment_url || 'Skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Web | ${{ steps.deploy.outputs.deployment_url }} |" >> $GITHUB_STEP_SUMMARY
comment-preview:
name: Comment Preview URLs
runs-on: ubuntu-latest
needs: [deploy-cms, deploy-web]
if: ${{ github.event_name == 'pull_request' && needs.deploy-web.result == 'success' }}
permissions:
contents: read
pull-requests: write
steps:
- name: Find existing comment
uses: peter-evans/find-comment@v4
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '## Preview Deployment'
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v5
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
## Preview Deployment
| Project | URL |
|---------|-----|
| CMS | ${{ needs.deploy-cms.outputs.deployment_url || 'Skipped' }} |
| Web | ${{ needs.deploy-web.outputs.deployment_url }} |
The Web preview uses the CMS preview URL for content fetching.