99 runs-on : ubuntu-latest
1010 if : github.repository == 'vitejs/vite' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
1111 steps :
12- - uses : actions/github-script@v7
12+ - name : Get PR Data
13+ uses : actions/github-script@v7
14+ id : get-pr-data
15+ with :
16+ script : |
17+ console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
18+ const { data: pr } = await github.rest.pulls.get({
19+ owner: context.repo.owner,
20+ repo: context.repo.repo,
21+ pull_number: context.issue.number
22+ })
23+ core.setOutput('head_sha', pr.head.sha)
24+ return {
25+ num: context.issue.number,
26+ branchName: pr.head.ref,
27+ commit: pr.head.sha,
28+ repo: pr.head.repo.full_name
29+ }
30+
31+ - name : Check Package Existence
32+ uses : actions/github-script@v7
33+ id : check-package
34+ with :
35+ script : |
36+ const prData = ${{ steps.get-pr-data.outputs.result }}
37+ const url = `https://pkg.pr.new/vite@${prData.commit}`
38+ const response = await fetch(url)
39+ console.log(`Package check URL: ${url}, Status: ${response.status}`)
40+
41+ // Add 'rocket' reaction to the issue comment
42+ if (response.status === 404) {
43+ const reaction = await github.rest.reactions.createForIssueComment({
44+ owner: context.repo.owner,
45+ repo: context.repo.repo,
46+ comment_id: context.payload.comment.id,
47+ content: 'rocket',
48+ })
49+ return { exists: false, reaction: reaction.id }
50+ }
51+
52+ return { exists: true, reaction: null }
53+
54+ - name : Check User Permissions
55+ uses : actions/github-script@v7
56+ id : check-permissions
1357 with :
1458 script : |
1559 const user = context.payload.sender.login
@@ -27,53 +71,143 @@ jobs:
2771 console.warn(e)
2872 }
2973
30- if (hasTriagePermission ) {
31- console.log('Allowed ')
74+ if (allowed ) {
75+ console.log('User is allowed. Adding +1 reaction. ')
3276 await github.rest.reactions.createForIssueComment({
3377 owner: context.repo.owner,
3478 repo: context.repo.repo,
3579 comment_id: context.payload.comment.id,
3680 content: '+1',
3781 })
3882 } else {
39- console.log('Not allowed')
83+ console.log('User is not allowed. Adding -1 reaction. ')
4084 await github.rest.reactions.createForIssueComment({
4185 owner: context.repo.owner,
4286 repo: context.repo.repo,
4387 comment_id: context.payload.comment.id,
4488 content: '-1',
4589 })
46- throw new Error('not allowed ')
90+ throw new Error('User does not have the necessary permissions. ')
4791 }
48- - uses : actions/github-script@v7
49- id : get-pr-data
92+
93+ - name : Generate Token
94+ id : generate-token
95+ uses : tibdex/github-app-token@v2
5096 with :
97+ app_id : ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
98+ installation_retrieval_payload : " ${{ github.repository_owner }}/vite-ecosystem-ci"
99+ private_key : ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
100+
101+ - name : Trigger Preview Release (if Package Not Found)
102+ if : steps.check-package.outputs.exists == false
103+ uses : actions/github-script@v7
104+ id : trigger-preview-release
105+ with :
106+ github-token : ${{ steps.generate-token.outputs.token }}
51107 script : |
52- console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
53- const { data: pr } = await github.rest.pulls.get({
108+ const prData = ${{ steps.get-pr-data.outputs.result }}
109+ console.log('Package not found, triggering preview release...')
110+
111+ // Add label "trigger: preview" to the PR
112+ await github.rest.issues.addLabels({
54113 owner: context.repo.owner,
55114 repo: context.repo.repo,
56- pull_number: context.issue.number
115+ issue_number: prData.num,
116+ labels: ['trigger: preview']
57117 })
58- return {
59- num: context.issue.number,
60- branchName: pr.head.ref,
61- repo: pr.head.repo.full_name,
62- commit: pr.head.sha
118+ console.log('Added "trigger: preview" label.')
119+
120+ - name : Wait for Preview Release Completion (if Package Not Found)
121+ if : steps.check-package.outputs.exists == false
122+ uses : actions/github-script@v7
123+ id : wait-preview-release
124+ with :
125+ script : |
126+ const prData = ${{ steps.get-pr-data.outputs.result }}
127+ const reaction = ${{ steps.check-package.outputs.reaction }}
128+ const workflowFileName = 'preview-release.yml'
129+ const workflow = await github.rest.actions.getWorkflow({
130+ owner: context.repo.owner,
131+ repo: context.repo.repo,
132+ workflow_id: workflowFileName,
133+ })
134+ const workflowId = workflow.data.id
135+ console.log(`Waiting for workflow ID ${workflowId} to complete...`)
136+
137+ const maxRetries = 60 // Wait up to 10 minutes
138+ const delay = 10000 // 10 seconds
139+ let completed = false
140+
141+ for (let i = 0; i < maxRetries; i++) {
142+ const runsData = await github.rest.actions.listWorkflowRuns({
143+ owner: context.repo.owner,
144+ repo: context.repo.repo,
145+ workflow_id: workflowId,
146+ head_sha: prData.commit,
147+ per_page: 100,
148+ page: 1,
149+ })
150+
151+ const runs = runsData.data.workflow_runs
152+
153+ if (runs.length > 0) {
154+ const latestRun = runs[0]
155+ console.log(`Latest run status: ${latestRun.status}, conclusion: ${latestRun.conclusion}`)
156+ if (latestRun.status === 'completed') {
157+ if (latestRun.conclusion === 'success') {
158+ console.log('Preview release workflow completed successfully.')
159+ completed = true
160+ break
161+ } else {
162+ throw new Error('Preview Release workflow failed.')
163+ }
164+ }
165+ }
166+
167+ console.log(`Retrying... (${i + 1}/${maxRetries})`)
168+ await new Promise(resolve => setTimeout(resolve, delay))
63169 }
64- - id : generate-token
65- uses : tibdex/github-app-token@v2
170+
171+ if (!completed) {
172+ throw new Error('Preview Release workflow did not complete in time.')
173+ }
174+
175+ // Remove the 'rocket' reaction
176+ if (reaction) {
177+ await github.rest.reactions.deleteForIssueComment({
178+ owner: context.repo.owner,
179+ repo: context.repo.repo,
180+ comment_id: context.payload.comment.id,
181+ reaction_id: reaction,
182+ })
183+ console.log('Removed "rocket" reaction.')
184+ }
185+
186+ - name : Checkout
187+ uses : actions/checkout@v4
66188 with :
67- app_id : ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
68- installation_retrieval_payload : " ${{ github.repository_owner }}/vite-ecosystem-ci"
69- private_key : ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
70- - uses : actions/github-script@v7
189+ fetch-depth : 0
190+
191+ # This step can be removed on May 26 2025
192+ - name : Check Commit Hash Ambiguity
193+ id : check_ambiguity
194+ run : |
195+ HEAD_SHA=${{ steps.get-pr-data.outputs.head_sha }}
196+ COMMIT_SHORT=${HEAD_SHA:0:7}
197+
198+ if git show "$COMMIT_SHORT"; then
199+ echo "COLLISION=false" >> $GITHUB_ENV
200+ else
201+ echo "COLLISION=true" >> $GITHUB_ENV
202+ fi
203+
204+ - name : Trigger Downstream Workflow
205+ uses : actions/github-script@v7
71206 id : trigger
72207 env :
73208 COMMENT : ${{ github.event.comment.body }}
74209 with :
75210 github-token : ${{ steps.generate-token.outputs.token }}
76- result-encoding : string
77211 script : |
78212 const comment = process.env.COMMENT.trim()
79213 const prData = ${{ steps.get-pr-data.outputs.result }}
89223 prNumber: '' + prData.num,
90224 branchName: prData.branchName,
91225 repo: prData.repo,
92- commit: prData.commit,
226+ commit: process.env.COLLISION === 'false' ? prData.commit : '' ,
93227 suite: suite === '' ? '-' : suite
94228 }
95229 })
0 commit comments