-
Notifications
You must be signed in to change notification settings - Fork 2
265 lines (223 loc) · 9 KB
/
website.yml
File metadata and controls
265 lines (223 loc) · 9 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: Website Deploy
on:
repository_dispatch:
types: [azd-web-core-updated]
workflow_dispatch: # Allow manual trigger
workflow_call: # Allow being called from release workflow
push:
branches:
- main
paths:
- 'web/**'
- '.github/workflows/website.yml'
pull_request:
types: [opened, synchronize, reopened, closed]
# No paths filter - generate preview site for all PRs
# Allow only one concurrent deployment per ref, cancel in-progress for the same ref
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
packages: read
jobs:
# Build job - runs for all triggers except PR closed
build:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Setup pnpm
uses: pnpm/action-setup@5b4374b04084dc1f9032b52464284b769ac5059e # v4
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '20'
cache: 'pnpm'
cache-dependency-path: 'pnpm-lock.yaml'
registry-url: 'https://npm.pkg.github.com'
- name: Install dependencies
working-directory: web
run: pnpm install --frozen-lockfile
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build website (Production)
if: github.event_name != 'pull_request'
working-directory: web
run: pnpm build
- name: Build website (PR Preview)
if: github.event_name == 'pull_request'
working-directory: web
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# Update astro.config.mjs for PR preview paths
sed -i "s|site: 'https://jongio.github.io/azd-exec/'|site: 'https://jongio.github.io/azd-exec/pr/${{ env.PR_NUMBER }}/'|g" astro.config.mjs
sed -i "s|base: '/azd-exec/'|base: '/azd-exec/pr/${{ env.PR_NUMBER }}/'|g" astro.config.mjs
pnpm build
- name: Upload production artifact
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: production-build
path: web/dist
retention-days: 1
- name: Upload PR preview artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: pr-preview-${{ github.event.pull_request.number }}
path: web/dist
retention-days: 7
# Production deploy - on main branch push, workflow_call, or workflow_dispatch
deploy-production:
if: github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: gh-pages
fetch-depth: 0
- name: Download production artifact
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: production-build
path: _new_build
- name: Deploy to GitHub Pages
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Remove old production files (keep pr/ directory for previews)
find . -maxdepth 1 ! -name '.' ! -name '.git' ! -name 'pr' ! -name '_new_build' -exec rm -rf {} +
# Move new build files to root
mv _new_build/* .
rm -rf _new_build
# Add .nojekyll to prevent Jekyll processing (needed for _astro folder)
touch .nojekyll
# Commit and push
git add -A
git commit -m "Deploy production website" --allow-empty
git push origin gh-pages
# PR preview deploy - only on pull requests
deploy-preview:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: gh-pages
fetch-depth: 0
- name: Download PR preview artifact
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: pr-preview-${{ github.event.pull_request.number }}
path: pr/${{ github.event.pull_request.number }}
- name: Deploy PR preview
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Add .nojekyll to prevent Jekyll processing (needed for _astro folder)
touch .nojekyll
# Add the PR preview directory
git add .nojekyll pr/${{ env.PR_NUMBER }}
# Commit and push
git commit -m "Deploy PR #${{ env.PR_NUMBER }} preview" --allow-empty
git push origin gh-pages
- name: Comment PR with preview URL
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://jongio.github.io/azd-exec/pr/${prNumber}/`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚀 **Website Preview**')
);
const body = `🚀 **Website Preview**
Your PR preview is ready!
📎 **Preview URL:** ${previewUrl}
_This preview will be automatically cleaned up when the PR is closed._`;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body
});
}
# Cleanup PR preview when PR is closed
cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
ref: gh-pages
fetch-depth: 0
- name: Remove PR preview
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Remove PR preview directory if it exists
if [ -d "pr/${{ env.PR_NUMBER }}" ]; then
git rm -rf pr/${{ env.PR_NUMBER }}
git commit -m "Cleanup PR #${{ env.PR_NUMBER }} preview"
git push origin gh-pages
echo "Cleaned up preview for PR #${{ env.PR_NUMBER }}"
else
echo "No preview found for PR #${{ env.PR_NUMBER }}"
fi
- name: Update PR comment
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const prNumber = context.payload.pull_request.number;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚀 **Website Preview**')
);
if (botComment) {
const body = `🚀 **Website Preview**
~~Your PR preview was available here.~~
_Preview has been cleaned up as the PR was closed._`;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body
});
}