-
Notifications
You must be signed in to change notification settings - Fork 244
246 lines (207 loc) · 10.2 KB
/
preview-docs.yml
File metadata and controls
246 lines (207 loc) · 10.2 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
name: Preview Documentation (Azure Blob Storage)
on:
pull_request:
types: [opened, synchronize, reopened, closed]
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
env:
AZCOPY_AUTO_LOGIN_TYPE: SPN
AZCOPY_SPA_APPLICATION_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZCOPY_SPA_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZCOPY_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
jobs:
build_and_deploy_job:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
runs-on: ubuntu-latest
name: Build and Deploy Job
timeout-minutes: 30
outputs:
first_gen_docs_url: ${{ steps.deploy.outputs.first_gen_docs_url }}
first_gen_storybook_url: ${{ steps.deploy.outputs.first_gen_storybook_url }}
second_gen_storybook_url: ${{ steps.deploy.outputs.second_gen_storybook_url }}
steps:
## --- SETUP --- ##
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node LTS version
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- name: Enable Corepack
run: corepack enable
- name: Generate PR hash
id: pr_hash
run: |
# Use just PR number so each commit overwrites the previous deployment
pr_hash="pr-${{ github.event.pull_request.number }}"
echo "hash=${pr_hash}" >> "$GITHUB_OUTPUT"
echo "Generated PR hash: ${pr_hash}"
## --- YARN CACHE --- ##
- name: Check for cached dependencies
continue-on-error: true
id: cache-dependencies
uses: actions/cache@v4
with:
path: |
.cache/yarn
node_modules
key: ubuntu-latest-node20-${{ hashFiles('yarn.lock', 'package.json') }}
## --- INSTALL & BUILD --- ##
- name: Install dependencies
shell: bash
run: yarn install --immutable
- name: Build all generations
run: yarn build
- name: Generate Custom Elements Manifest
run: yarn workspace @spectrum-web-components/1st-gen docs:analyze
- name: Move CEM to Storybook directory
run: cp 1st-gen/projects/documentation/custom-elements.json 1st-gen/storybook/
- name: Build documentation with path prefix
env:
SWC_DIR: ${{ steps.pr_hash.outputs.hash }}/docs/first-gen-docs
run: |
yarn workspace @spectrum-web-components/1st-gen docs:build
- name: Build first-gen Storybook
run: yarn workspace @spectrum-web-components/1st-gen storybook:build
- name: Build second-gen Storybook
run: yarn workspace @spectrum-web-components/2nd-gen storybook:build
## --- DEPLOY TO AZURE BLOB STORAGE --- ##
- name: Setup AzCopy
uses: ./.github/actions/setup-azcopy
- name: Deploy first-gen documentation to Azure Blob Storage
env:
PR_HASH: ${{ steps.pr_hash.outputs.hash }}
run: |
echo "Uploading first-gen documentation to ${PR_HASH}/docs/first-gen-docs/"
azcopy copy "1st-gen/projects/documentation/dist/*" \
"https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/docs/first-gen-docs/" \
--recursive \
--from-to LocalBlob
echo "✅ First-gen documentation uploaded successfully"
- name: Deploy first-gen Storybook to Azure Blob Storage
env:
PR_HASH: ${{ steps.pr_hash.outputs.hash }}
run: |
echo "Uploading first-gen Storybook to ${PR_HASH}/docs/first-gen-storybook/"
azcopy copy "1st-gen/projects/documentation/dist/storybook/*" \
"https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/docs/first-gen-storybook/" \
--recursive \
--from-to LocalBlob
echo "✅ First-gen Storybook uploaded successfully"
- name: Deploy second-gen Storybook to Azure Blob Storage
env:
PR_HASH: ${{ steps.pr_hash.outputs.hash }}
run: |
echo "Uploading second-gen Storybook to ${PR_HASH}/docs/second-gen-storybook/"
azcopy copy "2nd-gen/packages/swc/storybook-static/*" \
"https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/docs/second-gen-storybook/" \
--recursive \
--from-to LocalBlob
echo "✅ Second-gen Storybook uploaded successfully"
- name: Set deployment URLs
id: deploy
env:
PR_HASH: ${{ steps.pr_hash.outputs.hash }}
run: |
first_gen_docs_url="https://swcpreviews.z13.web.core.windows.net/${PR_HASH}/docs/first-gen-docs/"
first_gen_storybook_url="https://swcpreviews.z13.web.core.windows.net/${PR_HASH}/docs/first-gen-storybook/"
second_gen_storybook_url="https://swcpreviews.z13.web.core.windows.net/${PR_HASH}/docs/second-gen-storybook/"
echo "first_gen_docs_url=${first_gen_docs_url}" >> "$GITHUB_OUTPUT"
echo "first_gen_storybook_url=${first_gen_storybook_url}" >> "$GITHUB_OUTPUT"
echo "second_gen_storybook_url=${second_gen_storybook_url}" >> "$GITHUB_OUTPUT"
echo "📦 All deployments completed:"
echo " - Documentation: ${first_gen_docs_url}"
echo " - First-gen Storybook: ${first_gen_storybook_url}"
echo " - Second-gen Storybook: ${second_gen_storybook_url}"
- name: Post Previews Comment
uses: actions/github-script@v7
with:
script: |
const { buildPreviewURLComment } = await import('${{ github.workspace }}/.github/scripts/build-preview-urls-comment.js');
const { commentOrUpdate } = await import('${{ github.workspace }}/.github/scripts/comment-or-update.js');
const prNumber = context.payload.pull_request.number;
const body = buildPreviewURLComment(prNumber);
console.log(`Posting comment to PR #${prNumber}`);
commentOrUpdate(github, context, '## 📚 Branch Preview Links', body);
smoke_tests:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
needs: build_and_deploy_job
runs-on: ubuntu-latest
name: Smoke Tests
timeout-minutes: 15
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
- name: Wait for deployment
env:
DOC_URL: ${{ needs.build_and_deploy_job.outputs.first_gen_docs_url }}
run: |
echo "Waiting for deployment to be available at: ${DOC_URL}"
# Wait up to 10 minutes for the deployment to be available
max_attempts=60
attempt=1
while [ $attempt -le $max_attempts ]; do
echo "Attempt $attempt/$max_attempts: Checking if site is available..."
if curl -f -s --max-time 10 "${DOC_URL}" > /dev/null; then
echo "✅ ${DOC_URL} is now available!"
break
else
echo "❌ Site not ready yet, waiting 10 seconds..."
sleep 10
attempt=$((attempt + 1))
fi
done
if [ $attempt -gt $max_attempts ]; then
echo "❌ Timeout: Site was not available after 10 minutes"
exit 1
fi
- name: Setup Job and Install Dependencies
uses: ./.github/actions/setup-job
- name: Install Playwright Browsers
run: cd 1st-gen && yarn playwright install --with-deps
- name: Run Playwright tests
run: cd 1st-gen && yarn playwright test projects/documentation/e2e/published.spec.ts
env:
DOC_PREVIEW_URL: ${{ needs.build_and_deploy_job.outputs.first_gen_docs_url }}
SWC_DIR: pr-${{ github.event.pull_request.number }}
NODE_ENV: CI
- name: Upload Playwright Report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Clean up PR deployment
timeout-minutes: 5
steps:
- name: Check out code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Generate PR hash
id: pr_hash
run: |
# Create the same hash as in the deploy job
pr_hash="pr-${{ github.event.pull_request.number }}"
echo "hash=${pr_hash}" >> "$GITHUB_OUTPUT"
- name: Setup AzCopy
uses: ./.github/actions/setup-azcopy
- name: Clean up PR deployment
env:
PR_HASH: ${{ steps.pr_hash.outputs.hash }}
run: |
echo "Cleaning up deployment: ${PR_HASH}/"
azcopy remove "https://swcpreviews.blob.core.windows.net/\$web/${PR_HASH}/" \
--recursive || echo "Cleanup completed (some files may not exist)"
echo "Cleanup completed for PR deployment: ${PR_HASH}/"