-
Notifications
You must be signed in to change notification settings - Fork 167
167 lines (146 loc) · 5.81 KB
/
ecosystem-ci.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
name: Ecosystem CI
on:
push:
branches: [main]
workflow_dispatch:
inputs:
branch:
description: 'The branch of the Ecosystem CI run'
required: true
default: 'main'
jobs:
ecosystem_ci_notify:
name: Run Ecosystem CI With Notify
runs-on: ubuntu-latest
if: github.repository == 'web-infra-dev/rsbuild' && github.event_name != 'workflow_dispatch' && !startsWith(github.event.head_commit.message, 'docs')
steps:
- name: Run Ecosystem CI with notify
id: eco_ci
continue-on-error: true
uses: convictional/trigger-workflow-and-wait@v1.6.5
with:
owner: "rspack-contrib"
repo: "rsbuild-ecosystem-ci"
workflow_file_name: "ecosystem-ci-from-commit.yml"
github_token: ${{ secrets.REPO_RSBUILD_ECO_CI_GITHUB_TOKEN }}
ref: "main"
client_payload: '{"commitSHA":"${{ github.sha }}","updateComment":true,"repo":"web-infra-dev/rsbuild","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'
- if: steps.eco_ci.outcome == 'failure'
uses: actions/checkout@v4.2.2
- if: steps.eco_ci.outcome == 'failure'
uses: actions/setup-node@v4.1.0
with:
node-version: 20
- name: Send Failure Notification
if: steps.eco_ci.outcome == 'failure'
shell: bash
run: ./scripts/alert/lark.js
env:
TITLE: Rsbuild Ecosystem CI failed
DESCRIPTION: |
commitID: [${{github.sha}}](${{github.server_url}}/${{github.repository}}/commit/${{github.sha}})
URL: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
LARK_WEBHOOK_URL: ${{ secrets.LARK_WEBHOOK_URL }}
ecosystem_ci:
name: Run Ecosystem CI
runs-on: ubuntu-latest
if: github.repository == 'web-infra-dev/rsbuild' && github.event_name == 'workflow_dispatch'
steps:
- id: get-pr-number
uses: actions/github-script@v7
name: Get PR Number
with:
script: |
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
})
const pr = prs.find(pr => pr.head.ref === context.payload.inputs.branch);
if(pr) {
console.log(`Get PR info: ${pr.url}`)
return {
num: pr.number,
branchName: pr.head.ref,
repo: pr.head.repo.full_name
}
} else {
console.log(`can't find PR for branch: ${context.payload.inputs.branch}`)
}
- id: create-comment
name: Create Comment
uses: actions/github-script@v6
if: steps.get-pr-number.outputs.result
with:
github-token: ${{ secrets.ECOSYSTEM_CI_ACCESS_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: 'web-infra-dev',
repo: 'rsbuild',
body: `⏳ Triggered ecosystem CI: ${urlLink}`
})
return comment.id
- name: Run Ecosystem CI
id: eco_ci
uses: convictional/trigger-workflow-and-wait@v1.6.5
with:
owner: "rspack-contrib"
repo: "rsbuild-ecosystem-ci"
workflow_file_name: "ecosystem-ci-selected.yml"
github_token: ${{ secrets.REPO_RSBUILD_ECO_CI_GITHUB_TOKEN }}
ref: "main"
client_payload: '{"ref":"${{ github.event.inputs.branch }}","repo":"web-infra-dev/rsbuild","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'
- id: get-ci-result
uses: actions/github-script@v7
if: steps.get-pr-number.outputs.result.num
name: Get CI Result
env:
CI_OUTPUT: ${{ toJson(steps.eco_ci.outputs) }}
with:
script: |
const owner = "rspack-contrib"
const repo = "rsbuild-ecosystem-ci"
const runId = process.env.CI_OUTPUT.workflow_id
const { data: { jobs } = {} } = await github.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: runId,
})
if (!jobs) {
return 'cannot find CI result'
}
let result = 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 = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
const urlLink = `[Open](${url})`
const conclusionEmoji = {
success: ":white_check_mark:",
failure: ":x:",
cancelled: ":stop_button:"
}
const body = `
📝 Ran ecosystem CI: ${urlLink}
| suite | result |
|-------|--------|
${result.map(r => `| [${r.suite}](${r.link}) | ${conclusionEmoji[r.conclusion]} ${r.conclusion} |`).join("\n")}
`
return body;
- id: update-comment
uses: actions/github-script@v7
if: steps.get-pr-number.outputs.result.num
name: Update Comment
with:
script: |
await github.rest.issues.updateComment({
owner: 'web-infra-dev',
repo: 'rsbuild',
comment_id: ${{ steps.create-comment.outputs.result }},
body: ${{ steps.get-ci-result.outputs.result }}
})