Skip to content

Commit 9c747f1

Browse files
committed
debug git show
1 parent 6dfc0f9 commit 9c747f1

File tree

1 file changed

+174
-154
lines changed

1 file changed

+174
-154
lines changed
Lines changed: 174 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: ecosystem-ci trigger
22

3+
# on:
4+
# issue_comment:
5+
# types: [created]
36
on:
4-
issue_comment:
5-
types: [created]
7+
push:
68

79
jobs:
810
trigger:
@@ -27,166 +29,184 @@ jobs:
2729
repo: pr.head.repo.full_name
2830
}
2931
30-
- name: Check Package Existence
31-
uses: actions/github-script@v7
32-
id: check-package
33-
with:
34-
script: |
35-
const prData = ${{ steps.get-pr-data.outputs.result }}
36-
const url = `https://pkg.pr.new/vite@${prData.commit}`
37-
const response = await fetch(url)
38-
console.log(`Package check URL: ${url}, Status: ${response.status}`)
39-
40-
// Add 'rocket' reaction to the issue comment
41-
if (response.status === 404) {
42-
const reaction = await github.rest.reactions.createForIssueComment({
43-
owner: context.repo.owner,
44-
repo: context.repo.repo,
45-
comment_id: context.payload.comment.id,
46-
content: 'rocket',
47-
})
48-
return { exists: false, reaction: reaction.id }
49-
}
50-
51-
return { exists: true, reaction: null }
52-
53-
- name: Check User Permissions
54-
uses: actions/github-script@v7
55-
id: check-permissions
32+
# - name: Check Package Existence
33+
# uses: actions/github-script@v7
34+
# id: check-package
35+
# with:
36+
# script: |
37+
# const prData = ${{ steps.get-pr-data.outputs.result }}
38+
# const url = `https://pkg.pr.new/vite@${prData.commit}`
39+
# const response = await fetch(url)
40+
# console.log(`Package check URL: ${url}, Status: ${response.status}`)
41+
42+
# // Add 'rocket' reaction to the issue comment
43+
# if (response.status === 404) {
44+
# const reaction = await github.rest.reactions.createForIssueComment({
45+
# owner: context.repo.owner,
46+
# repo: context.repo.repo,
47+
# comment_id: context.payload.comment.id,
48+
# content: 'rocket',
49+
# })
50+
# return { exists: false, reaction: reaction.id }
51+
# }
52+
53+
# return { exists: true, reaction: null }
54+
55+
# - name: Check User Permissions
56+
# uses: actions/github-script@v7
57+
# id: check-permissions
58+
# with:
59+
# script: |
60+
# const user = context.payload.sender.login
61+
# console.log(`Validate user: ${user}`)
62+
63+
# let hasTriagePermission = false
64+
# try {
65+
# const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
66+
# owner: context.repo.owner,
67+
# repo: context.repo.repo,
68+
# username: user,
69+
# });
70+
# hasTriagePermission = ['triage', 'write', 'admin'].some(p => data.user.permissions[p]);
71+
# } catch (e) {
72+
# console.warn(e)
73+
# }
74+
75+
# if (allowed) {
76+
# console.log('User is allowed. Adding +1 reaction.')
77+
# await github.rest.reactions.createForIssueComment({
78+
# owner: context.repo.owner,
79+
# repo: context.repo.repo,
80+
# comment_id: context.payload.comment.id,
81+
# content: '+1',
82+
# })
83+
# } else {
84+
# console.log('User is not allowed. Adding -1 reaction.')
85+
# await github.rest.reactions.createForIssueComment({
86+
# owner: context.repo.owner,
87+
# repo: context.repo.repo,
88+
# comment_id: context.payload.comment.id,
89+
# content: '-1',
90+
# })
91+
# throw new Error('User does not have the necessary permissions.')
92+
# }
93+
94+
# - name: Generate Token
95+
# id: generate-token
96+
# uses: tibdex/github-app-token@v2
97+
# with:
98+
# app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
99+
# installation_retrieval_payload: "${{ github.repository_owner }}/vite-ecosystem-ci"
100+
# private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
101+
102+
# - name: Trigger Preview Release (if Package Not Found)
103+
# if: steps.check-package.outputs.exists == false
104+
# uses: actions/github-script@v7
105+
# id: trigger-preview-release
106+
# with:
107+
# github-token: ${{ steps.generate-token.outputs.token }}
108+
# script: |
109+
# const prData = ${{ steps.get-pr-data.outputs.result }}
110+
# console.log('Package not found, triggering preview release...')
111+
112+
# // Add label "trigger: preview" to the PR
113+
# await github.rest.issues.addLabels({
114+
# owner: context.repo.owner,
115+
# repo: context.repo.repo,
116+
# issue_number: prData.num,
117+
# labels: ['trigger: preview']
118+
# })
119+
# console.log('Added "trigger: preview" label.')
120+
121+
# - name: Wait for Preview Release Completion (if Package Not Found)
122+
# if: steps.check-package.outputs.exists == false
123+
# uses: actions/github-script@v7
124+
# id: wait-preview-release
125+
# with:
126+
# script: |
127+
# const prData = ${{ steps.get-pr-data.outputs.result }}
128+
# const reaction = ${{ steps.check-package.outputs.reaction }}
129+
# const workflowFileName = 'preview-release.yml'
130+
# const workflow = await github.rest.actions.getWorkflow({
131+
# owner: context.repo.owner,
132+
# repo: context.repo.repo,
133+
# workflow_id: workflowFileName,
134+
# })
135+
# const workflowId = workflow.data.id
136+
# console.log(`Waiting for workflow ID ${workflowId} to complete...`)
137+
138+
# const maxRetries = 60 // Wait up to 10 minutes
139+
# const delay = 10000 // 10 seconds
140+
# let completed = false
141+
142+
# for (let i = 0; i < maxRetries; i++) {
143+
# const runsData = await github.rest.actions.listWorkflowRuns({
144+
# owner: context.repo.owner,
145+
# repo: context.repo.repo,
146+
# workflow_id: workflowId,
147+
# head_sha: prData.commit,
148+
# per_page: 100,
149+
# page: 1,
150+
# })
151+
152+
# const runs = runsData.data.workflow_runs
153+
154+
# if (runs.length > 0) {
155+
# const latestRun = runs[0]
156+
# console.log(`Latest run status: ${latestRun.status}, conclusion: ${latestRun.conclusion}`)
157+
# if (latestRun.status === 'completed') {
158+
# if (latestRun.conclusion === 'success') {
159+
# console.log('Preview release workflow completed successfully.')
160+
# completed = true
161+
# break
162+
# } else {
163+
# throw new Error('Preview Release workflow failed.')
164+
# }
165+
# }
166+
# }
167+
168+
# console.log(`Retrying... (${i + 1}/${maxRetries})`)
169+
# await new Promise(resolve => setTimeout(resolve, delay))
170+
# }
171+
172+
# if (!completed) {
173+
# throw new Error('Preview Release workflow did not complete in time.')
174+
# }
175+
176+
# // Remove the 'rocket' reaction
177+
# if (reaction) {
178+
# await github.rest.reactions.deleteForIssueComment({
179+
# owner: context.repo.owner,
180+
# repo: context.repo.repo,
181+
# comment_id: context.payload.comment.id,
182+
# reaction_id: reaction,
183+
# })
184+
# console.log('Removed "rocket" reaction.')
185+
# }
186+
187+
- name: Checkout
188+
uses: actions/checkout@v4
56189
with:
57-
script: |
58-
const user = context.payload.sender.login
59-
console.log(`Validate user: ${user}`)
60-
61-
let hasTriagePermission = false
62-
try {
63-
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
64-
owner: context.repo.owner,
65-
repo: context.repo.repo,
66-
username: user,
67-
});
68-
hasTriagePermission = ['triage', 'write', 'admin'].some(p => data.user.permissions[p]);
69-
} catch (e) {
70-
console.warn(e)
71-
}
190+
fetch-depth: 0
72191

73-
if (allowed) {
74-
console.log('User is allowed. Adding +1 reaction.')
75-
await github.rest.reactions.createForIssueComment({
76-
owner: context.repo.owner,
77-
repo: context.repo.repo,
78-
comment_id: context.payload.comment.id,
79-
content: '+1',
80-
})
81-
} else {
82-
console.log('User is not allowed. Adding -1 reaction.')
83-
await github.rest.reactions.createForIssueComment({
84-
owner: context.repo.owner,
85-
repo: context.repo.repo,
86-
comment_id: context.payload.comment.id,
87-
content: '-1',
88-
})
89-
throw new Error('User does not have the necessary permissions.')
90-
}
91-
92-
- name: Generate Token
93-
id: generate-token
94-
uses: tibdex/github-app-token@v2
95-
with:
96-
app_id: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_ID }}
97-
installation_retrieval_payload: "${{ github.repository_owner }}/vite-ecosystem-ci"
98-
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }}
99-
100-
- name: Trigger Preview Release (if Package Not Found)
101-
if: steps.check-package.outputs.exists == false
102-
uses: actions/github-script@v7
103-
id: trigger-preview-release
104-
with:
105-
github-token: ${{ steps.generate-token.outputs.token }}
106-
script: |
107-
const prData = ${{ steps.get-pr-data.outputs.result }}
108-
console.log('Package not found, triggering preview release...')
192+
- name: Check Commit Hash Ambiguity
193+
id: check_ambiguity
194+
run: |
195+
COMMIT_HASH=${{ steps.get-pr-data.outputs.commit }}
196+
COMMIT_SHORT=${COMMIT_HASH:0:7}
109197
110-
// Add label "trigger: preview" to the PR
111-
await github.rest.issues.addLabels({
112-
owner: context.repo.owner,
113-
repo: context.repo.repo,
114-
issue_number: prData.num,
115-
labels: ['trigger: preview']
116-
})
117-
console.log('Added "trigger: preview" label.')
118-
119-
- name: Wait for Preview Release Completion (if Package Not Found)
120-
if: steps.check-package.outputs.exists == false
121-
uses: actions/github-script@v7
122-
id: wait-preview-release
123-
with:
124-
script: |
125-
const prData = ${{ steps.get-pr-data.outputs.result }}
126-
const reaction = ${{ steps.check-package.outputs.reaction }}
127-
const workflowFileName = 'preview-release.yml'
128-
const workflow = await github.rest.actions.getWorkflow({
129-
owner: context.repo.owner,
130-
repo: context.repo.repo,
131-
workflow_id: workflowFileName,
132-
})
133-
const workflowId = workflow.data.id
134-
console.log(`Waiting for workflow ID ${workflowId} to complete...`)
135-
136-
const maxRetries = 60 // Wait up to 10 minutes
137-
const delay = 10000 // 10 seconds
138-
let completed = false
139-
140-
for (let i = 0; i < maxRetries; i++) {
141-
const runsData = await github.rest.actions.listWorkflowRuns({
142-
owner: context.repo.owner,
143-
repo: context.repo.repo,
144-
workflow_id: workflowId,
145-
head_sha: prData.commit,
146-
per_page: 100,
147-
page: 1,
148-
})
149-
150-
const runs = runsData.data.workflow_runs
151-
152-
if (runs.length > 0) {
153-
const latestRun = runs[0]
154-
console.log(`Latest run status: ${latestRun.status}, conclusion: ${latestRun.conclusion}`)
155-
if (latestRun.status === 'completed') {
156-
if (latestRun.conclusion === 'success') {
157-
console.log('Preview release workflow completed successfully.')
158-
completed = true
159-
break
160-
} else {
161-
throw new Error('Preview Release workflow failed.')
162-
}
163-
}
164-
}
165-
166-
console.log(`Retrying... (${i + 1}/${maxRetries})`)
167-
await new Promise(resolve => setTimeout(resolve, delay))
168-
}
169-
170-
if (!completed) {
171-
throw new Error('Preview Release workflow did not complete in time.')
172-
}
173-
174-
// Remove the 'rocket' reaction
175-
if (reaction) {
176-
await github.rest.reactions.deleteForIssueComment({
177-
owner: context.repo.owner,
178-
repo: context.repo.repo,
179-
comment_id: context.payload.comment.id,
180-
reaction_id: reaction,
181-
})
182-
console.log('Removed "rocket" reaction.')
183-
}
198+
if git show "$COMMIT_SHORT"; then
199+
echo "COMMIT=$COMMIT_HASH" >> $GITHUB_ENV
200+
else
201+
echo "COMMIT=" >> $GITHUB_ENV
202+
fi
184203
185204
- name: Trigger Downstream Workflow
186205
uses: actions/github-script@v7
187206
id: trigger
188207
env:
189208
COMMENT: ${{ github.event.comment.body }}
209+
COMMIT: ${{ env.COMMIT }}
190210
with:
191211
github-token: ${{ steps.generate-token.outputs.token }}
192212
script: |
@@ -204,7 +224,7 @@ jobs:
204224
prNumber: '' + prData.num,
205225
branchName: prData.branchName,
206226
repo: prData.repo,
207-
commit: prData.commit,
227+
commit: process.env.COMMIT,
208228
suite: suite === '' ? '-' : suite
209229
}
210230
})

0 commit comments

Comments
 (0)