Skip to content

Commit a236fbd

Browse files
committed
chore(workflow): add eco-ci test
1 parent 95b184a commit a236fbd

2 files changed

Lines changed: 249 additions & 0 deletions

File tree

.github/eco-ci-result/action.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: 'Eco CI Result'
2+
description: 'Get ecosystem CI result and format it'
3+
4+
inputs:
5+
workflow-output:
6+
description: 'The output from ecosystem CI workflow'
7+
required: true
8+
9+
outputs:
10+
result:
11+
description: 'Formatted CI result'
12+
value: ${{ steps.get-result.outputs.result }}
13+
14+
runs:
15+
using: 'composite'
16+
steps:
17+
- id: get-result
18+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
19+
env:
20+
CI_OUTPUT: ${{ inputs.workflow-output }}
21+
with:
22+
script: |
23+
const owner = "rspack-contrib"
24+
const repo = "rstest-ecosystem-ci"
25+
const runId = JSON.parse(process.env.CI_OUTPUT).workflow_id
26+
27+
const { data: { jobs } = {} } = await github.rest.actions.listJobsForWorkflowRun({
28+
owner,
29+
repo,
30+
run_id: runId,
31+
})
32+
33+
if (!jobs) {
34+
return 'cannot find CI result'
35+
}
36+
37+
let result = jobs
38+
.filter(job => job.name.startsWith('execute-all '))
39+
.map(job => {
40+
const suite = job.name.replace(/^execute-all \(([^)]+)\)$/, "$1")
41+
return { suite, conclusion: job.conclusion, link: job.html_url }
42+
})
43+
44+
const url = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
45+
const urlLink = `[Open](${url})`
46+
47+
const conclusionEmoji = {
48+
success: ":white_check_mark:",
49+
failure: ":x:",
50+
cancelled: ":stop_button:"
51+
}
52+
53+
const body = `
54+
📝 Ran ecosystem CI: ${urlLink}
55+
56+
| suite | result |
57+
|-------|--------|
58+
${result.map(r => `| [${r.suite}](${r.link}) | ${conclusionEmoji[r.conclusion]} ${r.conclusion} |`).join("\n")}
59+
`
60+
61+
console.log(body);
62+
63+
return body;

.github/workflows/ecosystem-ci.yml

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
name: Ecosystem CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: 'The branch of the Ecosystem CI run'
11+
required: true
12+
default: 'main'
13+
14+
permissions:
15+
# Allow commenting on commits
16+
contents: write
17+
# Allow commenting on issues
18+
issues: write
19+
20+
jobs:
21+
changes:
22+
runs-on: ubuntu-latest
23+
if: github.repository == 'web-infra-dev/rstest' && github.event_name != 'workflow_dispatch'
24+
outputs:
25+
changed: ${{ steps.changes.outputs.changed }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
29+
with:
30+
fetch-depth: 1
31+
32+
- name: Install Pnpm
33+
run: |
34+
npm install -g corepack@latest --force
35+
corepack enable
36+
37+
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
38+
id: changes
39+
with:
40+
predicate-quantifier: 'every'
41+
filters: |
42+
changed:
43+
- "!**/*.md"
44+
- "!**/*.mdx"
45+
- "!**/_meta.json"
46+
- "!**/dictionary.txt"
47+
48+
ecosystem_ci_notify:
49+
name: Run Ecosystem CI With Notify
50+
needs: changes
51+
runs-on: ubuntu-latest
52+
if: github.repository == 'web-infra-dev/rstest' && github.event_name != 'workflow_dispatch' && needs.changes.outputs.changed == 'true'
53+
steps:
54+
- name: Run Ecosystem CI with notify
55+
id: eco_ci
56+
continue-on-error: true
57+
uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be # v1.6.5
58+
with:
59+
owner: 'rspack-contrib'
60+
repo: 'rstest-ecosystem-ci'
61+
workflow_file_name: 'ecosystem-ci-from-commit.yml'
62+
github_token: ${{ secrets.REPO_RSTEST_ECO_CI_GITHUB_TOKEN }}
63+
ref: 'main'
64+
client_payload: '{"commitSHA":"${{ github.sha }}","updateComment":true,"repo":"web-infra-dev/rstest","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'
65+
66+
- name: Checkout
67+
if: steps.eco_ci.outcome == 'failure'
68+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
69+
with:
70+
fetch-depth: 1
71+
72+
- name: Install Pnpm
73+
run: |
74+
npm install -g corepack@latest --force
75+
corepack enable
76+
77+
- name: Setup Node.js
78+
if: steps.eco_ci.outcome == 'failure'
79+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
80+
with:
81+
node-version: 22
82+
cache: 'pnpm'
83+
84+
- name: Get CI Result
85+
id: eco-ci-result
86+
if: steps.eco_ci.outcome == 'failure'
87+
uses: ./.github/actions/eco-ci-result
88+
with:
89+
workflow-output: ${{ toJson(steps.eco_ci.outputs) }}
90+
91+
- id: create-commit-comment
92+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
93+
if: steps.eco_ci.outcome == 'failure'
94+
name: Create Commit Comment
95+
with:
96+
script: |
97+
await github.rest.repos.createCommitComment({
98+
commit_sha: context.sha,
99+
owner: 'web-infra-dev',
100+
repo: 'rstest',
101+
body: ${{ steps.eco-ci-result.outputs.result }}
102+
})
103+
104+
ecosystem_ci:
105+
name: Run Ecosystem CI
106+
runs-on: ubuntu-latest
107+
if: github.repository == 'web-infra-dev/rstest' && github.event_name == 'workflow_dispatch'
108+
steps:
109+
- id: get-pr-number
110+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
111+
name: Get PR Number
112+
with:
113+
script: |
114+
const { data: prs } = await github.rest.pulls.list({
115+
owner: context.repo.owner,
116+
repo: context.repo.repo,
117+
})
118+
119+
const pr = prs.find(pr => pr.head.ref === context.payload.inputs.branch);
120+
121+
if(pr) {
122+
console.log(`Get PR info: ${pr.url}`)
123+
124+
return {
125+
num: pr.number,
126+
branchName: pr.head.ref,
127+
repo: pr.head.repo.full_name
128+
}
129+
} else {
130+
console.log(`can't find PR for branch: ${context.payload.inputs.branch}`)
131+
}
132+
133+
- id: create-comment
134+
name: Create Comment
135+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
136+
if: steps.get-pr-number.outputs.result
137+
with:
138+
result-encoding: string
139+
script: |
140+
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
141+
const urlLink = `[Open](${url})`
142+
const prData = ${{ steps.get-pr-number.outputs.result }}
143+
144+
const { data: comment } = await github.rest.issues.createComment({
145+
issue_number: prData.num,
146+
owner: 'web-infra-dev',
147+
repo: 'rstest',
148+
body: `⏳ Triggered ecosystem CI: ${urlLink}`
149+
})
150+
return comment.id
151+
152+
- name: Run Ecosystem CI
153+
id: eco_ci
154+
uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be # v1.6.5
155+
continue-on-error: true
156+
with:
157+
owner: 'rspack-contrib'
158+
repo: 'rstest-ecosystem-ci'
159+
workflow_file_name: 'ecosystem-ci-selected.yml'
160+
github_token: ${{ secrets.REPO_RSTEST_ECO_CI_GITHUB_TOKEN }}
161+
ref: 'main'
162+
client_payload: '{"ref":"${{ github.event.inputs.branch }}","repo":"web-infra-dev/rstest","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'
163+
164+
- name: Checkout
165+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
166+
with:
167+
fetch-depth: 1
168+
169+
- id: eco-ci-result
170+
uses: ./.github/actions/eco-ci-result
171+
name: Get CI Result
172+
with:
173+
workflow-output: ${{ toJson(steps.eco_ci.outputs) }}
174+
175+
- id: update-comment
176+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
177+
if: steps.get-pr-number.outputs.result
178+
name: Update Comment
179+
with:
180+
script: |
181+
await github.rest.issues.updateComment({
182+
owner: 'web-infra-dev',
183+
repo: 'rstest',
184+
comment_id: ${{ steps.create-comment.outputs.result }},
185+
body: ${{ steps.eco-ci-result.outputs.result }}
186+
})

0 commit comments

Comments
 (0)