-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (204 loc) · 7.97 KB
/
website.yml
File metadata and controls
245 lines (204 loc) · 7.97 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
name: Website Deploy
on:
repository_dispatch:
types: [azd-web-core-updated]
workflow_dispatch:
workflow_call:
push:
branches:
- main
paths:
- 'web/**'
- '.github/workflows/website.yml'
pull_request:
types: [opened, synchronize, reopened, closed]
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
packages: read
jobs:
build:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup pnpm
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4
with:
version: 9
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
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: |
sed -i "s|site: 'https://jongio.github.io/azd-rest/'|site: 'https://jongio.github.io/azd-rest/pr/${{ env.PR_NUMBER }}/'|g" astro.config.mjs
sed -i "s|base: '/azd-rest/'|base: '/azd-rest/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
deploy-production:
if: github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: gh-pages
fetch-depth: 0
- name: Download production artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
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"
find . -maxdepth 1 ! -name '.' ! -name '.git' ! -name 'pr' ! -name '_new_build' -exec rm -rf {} +
mv _new_build/* .
rm -rf _new_build
touch .nojekyll
git add -A
git commit -m "Deploy production website" --allow-empty
git push origin gh-pages
deploy-preview:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: gh-pages
fetch-depth: 0
- name: Download PR preview artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
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"
touch .nojekyll
git add .nojekyll pr/${{ env.PR_NUMBER }}
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@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const prNumber = context.payload.pull_request.number;
const previewUrl = `https://jongio.github.io/azd-rest/pr/${prNumber}/`;
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) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body
});
}
cleanup-preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
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"
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@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const prNumber = context.payload.pull_request.number;
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
});
}