-
-
Notifications
You must be signed in to change notification settings - Fork 58
301 lines (279 loc) · 10.3 KB
/
ecosystem-ci-from-pr.yml
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
# integration tests for vite ecosystem - run from pr comments
name: vite-ecosystem-ci-from-pr
env:
# 7 GiB by default on GitHub, setting to 6 GiB
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
NODE_OPTIONS: --max-old-space-size=6144
on:
workflow_dispatch:
inputs:
prNumber:
description: "PR number (e.g. 9887)"
required: true
type: string
branchName:
description: "vite branch to use"
required: true
type: string
default: "main"
repo:
description: "vite repository to use"
required: true
type: string
default: "vitejs/vite"
suite:
description: "testsuite to run. runs all testsuits when `-`."
required: false
type: choice
options:
- "-"
- analogjs
- astro
- histoire
- hydrogen
- iles
- ladle
- laravel
- marko
- nuxt
- nx
- previewjs
- quasar
- qwik
- rakkas
- storybook
- sveltekit
- unocss
- vike
- vite-plugin-pwa
- vite-plugin-react
- vite-plugin-react-pages
- vite-plugin-react-swc
- vite-plugin-svelte
- vite-plugin-vue
- vite-setup-catalogue
- vitepress
- vitest
jobs:
init:
runs-on: ubuntu-latest
outputs:
comment-id: ${{ steps.create-comment.outputs.result }}
steps:
- id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.PR_GITHUB_APP_ID }}
installation_retrieval_payload: "${{ github.repository_owner }}/vite"
private_key: ${{ secrets.PR_GITHUB_APP_PRIVATE_KEY }}
- id: create-comment
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
result-encoding: string
script: |
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const urlLink = `[Open](${url})`
const { data: comment } = await github.rest.issues.createComment({
issue_number: context.payload.inputs.prNumber,
owner: context.repo.owner,
repo: 'vite',
body: `⏳ Triggered ecosystem CI: ${urlLink}`
})
return comment.id
execute-selected-suite:
timeout-minutes: 30
runs-on: ubuntu-latest
needs: init
if: "inputs.suite != '-'"
outputs:
ref: ${{ steps.get-ref.outputs.ref }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
continue-on-error: true
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
--branch ${{ inputs.branchName }}
--repo ${{ inputs.repo }}
${{ inputs.suite }}
- id: get-ref
if: always()
run: |
ref=$(git log -1 --pretty=format:%H)
echo "ref=$ref" >> $GITHUB_OUTPUT
working-directory: workspace/vite
execute-all:
timeout-minutes: 30
runs-on: ubuntu-latest
needs: init
if: "inputs.suite == '-'"
outputs:
ref: ${{ steps.get-ref.outputs.ref }}
strategy:
matrix:
suite:
- analogjs
- astro
- histoire
# - hydrogen # disabled until they complete they migration back to Vite
# - iles # disabled until its CI is fixed
- ladle
- laravel
- marko
- nuxt
# - nx # disabled temporarily
- previewjs
- quasar
- qwik
- rakkas
- remix
# - storybook # disabled until test is updated, see https://github.com/vitejs/vite-ecosystem-ci/issues/130
- sveltekit
- unocss
- vike
- vite-plugin-pwa
- vite-plugin-react
- vite-plugin-react-pages
- vite-plugin-react-swc
- vite-plugin-svelte
- vite-plugin-vue
- vite-setup-catalogue
- vitepress
- vitest
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
continue-on-error: true
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
--branch ${{ inputs.branchName }}
--repo ${{ inputs.repo }}
${{ matrix.suite }}
- id: get-ref
if: always()
run: |
ref=$(git log -1 --pretty=format:%H)
echo "ref=$ref" >> $GITHUB_OUTPUT
working-directory: workspace/vite
update-comment:
runs-on: ubuntu-latest
needs: [init, execute-selected-suite, execute-all]
if: always()
steps:
- id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.PR_GITHUB_APP_ID }}
installation_retrieval_payload: "${{ github.repository_owner }}/vite"
private_key: ${{ secrets.PR_GITHUB_APP_PRIVATE_KEY }}
- uses: actions/github-script@v7
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const mainRepoName = 'vite'
const ref = "${{ needs.execute-all.outputs.ref }}" || "${{ needs.execute-selected-suite.outputs.ref }}"
const refLink = `[\`${ref.slice(0, 7)}\`](${context.serverUrl}/${context.repo.owner}/${mainRepoName}/pull/${context.payload.inputs.prNumber}/commits/${ref})`
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
per_page: 100
});
const selectedSuite = context.payload.inputs.suite
let results
if (selectedSuite !== "-") {
const { conclusion, html_url } = jobs.find(job => job.name === "execute-selected-suite")
results = [{ suite: selectedSuite, conclusion, link: html_url }]
} else {
results = jobs
.filter(job => job.name.startsWith('execute-all '))
.map(job => {
const suite = job.name.replace(/^execute-all \(([^)]+)\)$/, "$1")
return { suite, conclusion: job.conclusion, link: job.html_url }
})
}
const url = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const urlLink = `[Open](${url})`
const conclusionEmoji = {
success: ":white_check_mark:",
failure: ":x:",
cancelled: ":stop_button:"
}
// check for previous ecosystem-ci runs against the main branch
// first, list workflow runs for ecosystem-ci.yml
const { data: { workflow_runs } } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'ecosystem-ci.yml'
});
// for simplity, we only take the latest completed scheduled run
// otherwise we would have to check the inputs for every maunally triggerred runs, which is an overkill
const latestScheduledRun = workflow_runs.find(run => run.event === "schedule" && run.status === "completed")
// get the jobs for the latest scheduled run
const { data: { jobs: scheduledJobs } } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: latestScheduledRun.id
});
const scheduledResults = scheduledJobs
.filter(job => job.name.startsWith('test-ecosystem '))
.map(job => {
const suite = job.name.replace(/^test-ecosystem \(([^)]+)\)$/, "$1")
return { suite, conclusion: job.conclusion, link: job.html_url }
})
const rows = []
const successfulSuitesWithoutChanges = []
results.forEach(current => {
const latest = scheduledResults.find(s => s.suite === current.suite) || {} // in case a new suite is added after latest scheduled
if (current.conclusion === "success" && latest.conclusion === "success") {
successfulSuitesWithoutChanges.push(`[${current.suite}](${current.link})`)
}
else {
const firstColumn = current.suite
const secondColumn = `${conclusionEmoji[current.conclusion]} [${current.conclusion}](${current.link})`
const thirdColumn = `${conclusionEmoji[latest.conclusion]} [${latest.conclusion}](${latest.link})`
rows.push(`| ${firstColumn} | ${secondColumn} | ${thirdColumn} |`)
}
})
let body = `
📝 Ran ecosystem CI on ${refLink}: ${urlLink}
`
if (rows.length > 0) {
body += `| suite | result | [latest scheduled](${latestScheduledRun.html_url}) |
|-------|--------|----------------|
${rows.join("\n")}
${conclusionEmoji.success} ${successfulSuitesWithoutChanges.join(", ")}
`
} else {
body += `${conclusionEmoji.success} ${successfulSuitesWithoutChanges.join(", ")}
`
}
await github.rest.issues.createComment({
issue_number: context.payload.inputs.prNumber,
owner: context.repo.owner,
repo: mainRepoName,
body
})
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: mainRepoName,
comment_id: ${{ needs.init.outputs.comment-id }}
})