-
Notifications
You must be signed in to change notification settings - Fork 0
307 lines (256 loc) · 9.34 KB
/
pr.yml
File metadata and controls
307 lines (256 loc) · 9.34 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
name: PR Checks
on:
pull_request:
branches:
- main
- release/*
jobs:
checks-and-tests:
name: Checks and Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Run checks
run: npm run build && npm run check-format && npm run check-exports && npm run lint && npm run type-check
- name: Run tests with coverage
run: npm run test:coverage
- name: Create output directory
run: mkdir -p out
- name: Extract current coverage
run: npm run coverage:extract -- --output out/current-coverage.json
- name: Upload current coverage
uses: actions/upload-artifact@v4
with:
name: current-coverage
path: out/current-coverage.json
retention-days: 1
coverage-compare:
name: Compare Coverage
runs-on: ubuntu-latest
needs: checks-and-tests
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Download current coverage
uses: actions/download-artifact@v4
with:
name: current-coverage
path: out
- name: Check if coverage scripts exist
id: check-scripts
run: |
if [ -f "scripts/compare-coverage.ts" ] && [ -f "scripts/extract-coverage.ts" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Checkout base branch
if: steps.check-scripts.outputs.exists == 'true'
run: |
git fetch origin ${{ github.base_ref }}
git checkout origin/${{ github.base_ref }}
- name: Check if coverage scripts exist in base branch
if: steps.check-scripts.outputs.exists == 'true'
id: check-base-scripts
run: |
if [ -f "scripts/compare-coverage.ts" ] && [ -f "scripts/extract-coverage.ts" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Install dependencies (base)
if: steps.check-scripts.outputs.exists == 'true' && steps.check-base-scripts.outputs.exists == 'true'
run: npm ci --ignore-scripts
- name: Run tests with coverage (base)
if: steps.check-scripts.outputs.exists == 'true' && steps.check-base-scripts.outputs.exists == 'true'
run: npm run test:coverage
- name: Extract base coverage
if: steps.check-scripts.outputs.exists == 'true' && steps.check-base-scripts.outputs.exists == 'true'
run: npm run coverage:extract -- --output out/base-coverage.json
- name: Upload base coverage
if: steps.check-scripts.outputs.exists == 'true' && steps.check-base-scripts.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: base-coverage
path: out/base-coverage.json
retention-days: 1
- name: Checkout PR branch
if: steps.check-scripts.outputs.exists == 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install dependencies (PR branch)
if: steps.check-scripts.outputs.exists == 'true'
run: npm ci --ignore-scripts
- name: Download current coverage
uses: actions/download-artifact@v4
with:
name: current-coverage
path: out
- name: Download base coverage
uses: actions/download-artifact@v4
with:
name: base-coverage
path: out
continue-on-error: true
- name: Compare coverage
id: compare
run: |
# Run comparison (will handle missing base file gracefully)
npm exec tsx scripts/compare-coverage.ts out/current-coverage.json out/base-coverage.json > out/coverage-report.md 2>&1 || true
# Read the report for the PR comment
REPORT=$(cat out/coverage-report.md)
# Set output for PR comment (escape for GitHub Actions)
echo "report<<EOF" >> $GITHUB_OUTPUT
echo "$REPORT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Post PR comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const report = process.env.COVERAGE_REPORT;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📊 Coverage Report')
);
const commentBody = report;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
env:
COVERAGE_REPORT: ${{ steps.compare.outputs.report }}
- name: Upload coverage analysis
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-analysis
path: |
out/current-coverage.json
out/base-coverage.json
out/coverage-report.md
retention-days: 30
deploy-remote-flows:
name: Deploy Remote Flows Preview
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy remote-flows to vercel
id: vercel-remote-flows
uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_REMOTE_FLOWS_PROJECT_ID }}
github-token: ${{ secrets.GITHUB_TOKEN }}
github-comment: true
scope: ${{ secrets.VERCEL_ORG_ID }}
- name: Save deployment URL
run: |
echo "${{ steps.vercel-remote-flows.outputs.preview-url }}" > remote-flows-url.txt
- name: Upload deployment URL
uses: actions/upload-artifact@v4
with:
name: remote-flows-url
path: remote-flows-url.txt
deploy-example-app:
name: Deploy Example App Preview
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy remote-flows-example-app to vercel
id: vercel-example-app
uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_EXAMPLE_APP_PROJECT_ID }}
scope: ${{ secrets.VERCEL_ORG_ID }}
github-token: ${{ secrets.GITHUB_TOKEN }}
github-comment: true
- name: Save deployment URL
run: |
echo "${{ steps.vercel-example-app.outputs.preview-url }}" > example-app-url.txt
- name: Upload deployment URL
uses: actions/upload-artifact@v4
with:
name: example-app-url
path: example-app-url.txt
e2e-tests:
name: E2E Tests
runs-on: ubuntu-latest
needs: [checks-and-tests, deploy-remote-flows, deploy-example-app]
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install main package dependencies
run: npm ci --ignore-scripts
- name: Install example/ dependencies
working-directory: ./example
run: npm ci
- name: Install Playwright
working-directory: ./example
run: npx playwright install chromium --with-deps
- name: Download remote-flows URL
uses: actions/download-artifact@v4
with:
name: remote-flows-url
- name: Download example-app URL
uses: actions/download-artifact@v4
with:
name: example-app-url
- name: Set deployment URLs
id: set-urls
run: |
echo "REMOTE_FLOWS_URL=$(cat remote-flows-url.txt)" >> $GITHUB_ENV
echo "EXAMPLE_APP_URL=$(cat example-app-url.txt)" >> $GITHUB_ENV
- name: Run Playwright tests
env:
BASE_URL: ${{ env.REMOTE_FLOWS_URL }}
VERCEL_BYPASS_TOKEN: ${{ secrets.VERCEL_BYPASS_TOKEN }}
DEBUG: pw:api
working-directory: ./example
run: npx playwright test --project=chromium
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30