Skip to content

Commit

Permalink
chore(CI): support add eco-ci failure result in commit comment (#4262)
Browse files Browse the repository at this point in the history
Co-authored-by: neverland <chenjiahan.jait@bytedance.com>
  • Loading branch information
9aoy and chenjiahan authored Dec 25, 2024
1 parent 91c23ca commit de5c335
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 54 deletions.
63 changes: 63 additions & 0 deletions .github/actions/eco-ci-result/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: 'Eco CI Result'
description: 'Get ecosystem CI result and format it'

inputs:
workflow-output:
description: 'The output from ecosystem CI workflow'
required: true

outputs:
result:
description: 'Formatted CI result'
value: ${{ steps.get-result.outputs.result }}

runs:
using: "composite"
steps:
- id: get-result
uses: actions/github-script@v7
env:
CI_OUTPUT: ${{ inputs.workflow-output }}
with:
script: |
const owner = "rspack-contrib"
const repo = "rsbuild-ecosystem-ci"
const runId = JSON.parse(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")}
`
console.log(body);
return body;
84 changes: 30 additions & 54 deletions .github/workflows/ecosystem-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ jobs:
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
Expand All @@ -46,6 +40,26 @@ jobs:
URL: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
LARK_WEBHOOK_URL: ${{ secrets.LARK_WEBHOOK_URL }}

- name: Get CI Result
id: eco-ci-result
if: steps.eco_ci.outcome == 'failure'
uses: ./.github/actions/eco-ci-result
with:
workflow-output: ${{ toJson(steps.eco_ci.outputs) }}

- id: create-commit-comment
uses: actions/github-script@v7
if: steps.eco_ci.outcome == 'failure'
name: Create Commit Comment
with:
script: |
await github.rest.repos.createCommitComment({
commit_sha: github.sha,
owner: 'web-infra-dev',
repo: 'rsbuild',
body: ${{ steps.eco-ci-result.outputs.result }}
})
ecosystem_ci:
name: Run Ecosystem CI
runs-on: ubuntu-latest
Expand Down Expand Up @@ -77,7 +91,7 @@ jobs:
- id: create-comment
name: Create Comment
uses: actions/github-script@v6
uses: actions/github-script@v7
if: steps.get-pr-number.outputs.result
with:
result-encoding: string
Expand Down Expand Up @@ -106,54 +120,16 @@ jobs:
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
name: Get CI Result
env:
CI_OUTPUT: ${{ toJson(steps.eco_ci.outputs) }}
- name: Checkout
uses: actions/checkout@v4.2.2
with:
script: |
const owner = "rspack-contrib"
const repo = "rsbuild-ecosystem-ci"
const runId = JSON.parse(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}
fetch-depth: 1

| suite | result |
|-------|--------|
${result.map(r => `| [${r.suite}](${r.link}) | ${conclusionEmoji[r.conclusion]} ${r.conclusion} |`).join("\n")}
`
console.log(body);
return body;
- id: eco-ci-result
uses: ./.github/actions/eco-ci-result
name: Get CI Result
with:
workflow-output: ${{ toJson(steps.eco_ci.outputs) }}

- id: update-comment
uses: actions/github-script@v7
Expand All @@ -165,6 +141,6 @@ jobs:
owner: 'web-infra-dev',
repo: 'rsbuild',
comment_id: ${{ steps.create-comment.outputs.result }},
body: ${{ steps.get-ci-result.outputs.result }}
body: ${{ steps.eco-ci-result.outputs.result }}
})

0 comments on commit de5c335

Please sign in to comment.