diff --git a/.github/actions/eco-ci-result/action.yml b/.github/actions/eco-ci-result/action.yml new file mode 100644 index 0000000000..902fad1981 --- /dev/null +++ b/.github/actions/eco-ci-result/action.yml @@ -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; diff --git a/.github/workflows/ecosystem-ci.yml b/.github/workflows/ecosystem-ci.yml index 62bfba40e9..fc12232b92 100644 --- a/.github/workflows/ecosystem-ci.yml +++ b/.github/workflows/ecosystem-ci.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 }} })