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 permissions :
12- issues : write # to add / delete reactions
12+ issues : write # to add / delete reactions, post comments
1313 pull-requests : write # to read PR data, and to add labels
1414 actions : read # to check workflow status
1515 contents : read # to clone the repo
1616 steps :
1717 - name : Check User Permissions
18- uses : actions/github-script@v7
18+ uses : actions/github-script@v8
1919 id : check-permissions
2020 with :
2121 script : |
5656 }
5757
5858 - name : Get PR Data
59- uses : actions/github-script@v7
59+ uses : actions/github-script@v8
6060 id : get-pr-data
6161 with :
6262 script : |
6666 repo: context.repo.repo,
6767 pull_number: context.issue.number
6868 })
69+
70+ const commentCreatedAt = new Date(context.payload.comment.created_at)
71+ const commitPushedAt = new Date(pr.head.repo.pushed_at)
72+
73+ console.log(`Comment created at: ${commentCreatedAt.toISOString()}`)
74+ console.log(`PR last pushed at: ${commitPushedAt.toISOString()}`)
75+
76+ // Check if any commits were pushed after the comment was created
77+ if (commitPushedAt > commentCreatedAt) {
78+ const errorMsg = [
79+ '⚠️ Security warning: PR was updated after the trigger command was posted.',
80+ '',
81+ `Comment posted at: ${commentCreatedAt.toISOString()}`,
82+ `PR last pushed at: ${commitPushedAt.toISOString()}`,
83+ '',
84+ 'This could indicate an attempt to inject code after approval.',
85+ 'Please review the latest changes and re-run /ecosystem-ci run if they are acceptable.'
86+ ].join('\n')
87+
88+ core.setFailed(errorMsg)
89+
90+ await github.rest.issues.createComment({
91+ owner: context.repo.owner,
92+ repo: context.repo.repo,
93+ issue_number: context.issue.number,
94+ body: errorMsg
95+ })
96+
97+ throw new Error('PR was pushed to after comment was created')
98+ }
99+
69100 core.setOutput('head_sha', pr.head.sha)
70101 return {
71102 num: context.issue.number,
75106 }
76107
77108 - name : Check Package Existence
78- uses : actions/github-script@v7
109+ uses : actions/github-script@v8
79110 id : check-package
80111 with :
81112 script : |
@@ -109,12 +140,14 @@ jobs:
109140
110141 - name : Trigger Preview Release (if Package Not Found)
111142 if : fromJSON(steps.check-package.outputs.result).exists == false
112- uses : actions/github-script@v7
143+ uses : actions/github-script@v8
113144 id : trigger-preview-release
145+ env :
146+ PR_DATA : ${{ steps.get-pr-data.outputs.result }}
114147 with :
115148 github-token : ${{ steps.generate-token.outputs.token }}
116149 script : |
117- const prData = ${{ steps.get-pr-data.outputs.result }}
150+ const prData = JSON.parse(process.env.PR_DATA)
118151 console.log('Package not found, triggering preview release...')
119152
120153 // Add label "trigger: preview" to the PR
@@ -128,12 +161,15 @@ jobs:
128161
129162 - name : Wait for Preview Release Completion (if Package Not Found)
130163 if : fromJSON(steps.check-package.outputs.result).exists == false
131- uses : actions/github-script@v7
164+ uses : actions/github-script@v8
132165 id : wait-preview-release
166+ env :
167+ PR_DATA : ${{ steps.get-pr-data.outputs.result }}
168+ REACTION : ${{ fromJSON(steps.check-package.outputs.result).reaction }}
133169 with :
134170 script : |
135- const prData = ${{ steps.get-pr-data.outputs.result }}
136- const reaction = ${{ fromJSON(steps.check-package.outputs.result).reaction }}
171+ const prData = JSON.parse(process.env.PR_DATA)
172+ const reaction = +process.env.REACTION
137173 const workflowFileName = 'preview-release.yml'
138174 const workflow = await github.rest.actions.getWorkflow({
139175 owner: context.repo.owner,
@@ -195,34 +231,22 @@ jobs:
195231 }
196232
197233 - name : Checkout
198- uses : actions/checkout@v4
234+ uses : actions/checkout@v5
199235 with :
200236 ref : refs/pull/${{ fromJSON(steps.get-pr-data.outputs.result).num }}/head
201237 fetch-depth : 0
202238
203- # This step can be removed on May 26 2025
204- - name : Check Commit Hash Ambiguity
205- id : check_ambiguity
206- run : |
207- HEAD_SHA=${{ steps.get-pr-data.outputs.head_sha }}
208- COMMIT_SHORT=${HEAD_SHA:0:7}
209-
210- if git show "$COMMIT_SHORT"; then
211- echo "COLLISION=false" >> $GITHUB_ENV
212- else
213- echo "COLLISION=true" >> $GITHUB_ENV
214- fi
215-
216239 - name : Trigger Downstream Workflow
217- uses : actions/github-script@v7
240+ uses : actions/github-script@v8
218241 id : trigger
219242 env :
220243 COMMENT : ${{ github.event.comment.body }}
244+ PR_DATA : ${{ steps.get-pr-data.outputs.result }}
221245 with :
222246 github-token : ${{ steps.generate-token.outputs.token }}
223247 script : |
224248 const comment = process.env.COMMENT.trim()
225- const prData = ${{ steps.get-pr-data.outputs.result }}
249+ const prData = JSON.parse(process.env.PR_DATA)
226250
227251 const suite = comment.split('\n')[0].replace(/^\/ecosystem-ci run/, '').trim()
228252
@@ -235,7 +259,7 @@ jobs:
235259 prNumber: '' + prData.num,
236260 branchName: prData.branchName,
237261 repo: prData.repo,
238- commit: process.env.COLLISION === 'false' ? prData.commit : '' ,
262+ commit: prData.commit,
239263 suite: suite === '' ? '-' : suite
240264 }
241265 })
0 commit comments