rspack-ecosystem-ci-from-pr #290
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# integration tests for rspack ecosystem - run from pr comments | |
name: rspack-ecosystem-ci-from-pr | |
env: | |
# 7 GiB by default on GitHub, setting to 6 GiB | |
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources | |
NODE_OPTIONS: --max-old-space-size=6144 | |
on: | |
workflow_dispatch: | |
inputs: | |
prNumber: | |
description: "PR number (e.g. 9887)" | |
required: true | |
type: string | |
branchName: | |
description: "rspack branch to use" | |
required: true | |
type: string | |
default: "main" | |
repo: | |
description: "rspack repository to use" | |
required: true | |
type: string | |
default: "web-infra-dev/rspack" | |
suite: | |
description: "testsuite to run. runs all testsuits when `-`." | |
required: false | |
type: choice | |
options: | |
- "-" | |
- modernjs | |
- nx | |
- rspress | |
- rsbuild | |
- rslib | |
- examples | |
suiteRefType: | |
description: "type of suite ref to use" | |
required: true | |
type: choice | |
options: | |
- precoded | |
- branch | |
- tag | |
- commit | |
default: "precoded" | |
suiteRef: | |
description: "suite ref to use" | |
required: true | |
type: string | |
default: "precoded" | |
jobs: | |
create-comment: | |
runs-on: ubuntu-latest | |
outputs: | |
comment-id: ${{ steps.create-comment.outputs.result }} | |
steps: | |
- id: create-comment | |
uses: actions/github-script@v6 | |
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: context.repo.owner, | |
repo: 'rspack', | |
body: `⏳ Triggered ecosystem CI: ${urlLink}` | |
}) | |
return comment.id | |
get-runner-labels: | |
name: Get Runner Labels | |
needs: create-comment | |
uses: ./.github/workflows/get-runner-labels.yml | |
prepare-binding: | |
name: Prepare Rspack Binding | |
needs: get-runner-labels | |
runs-on: ${{ fromJSON(needs.get-runner-labels.outputs.LINUX_RUNNER_LABELS) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/prepare-rspack-binding | |
with: | |
repository: ${{ inputs.repo }} | |
ref: ${{ inputs.branchName }} | |
execute-selected-suite: | |
runs-on: ubuntu-latest | |
needs: prepare-binding | |
if: "inputs.suite != '-'" | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/build-rspack | |
with: | |
repository: ${{ inputs.repo }} | |
ref: ${{ inputs.branchName }} | |
- run: pnpm i --frozen-lockfile | |
- name: Expose GitHub Runtime | |
uses: crazy-max/ghaction-github-runtime@v3 | |
- run: >- | |
pnpm tsx ecosystem-ci.ts | |
run-suites | |
--suite-${{ inputs.suiteRefType }} ${{ inputs.suiteRef }} | |
${{ inputs.suite }} | |
execute-all: | |
needs: [get-runner-labels, prepare-binding] | |
if: "inputs.suite == '-'" | |
strategy: | |
matrix: | |
include: | |
- suite: modernjs | |
os: ubuntu-latest | |
- suite: nx | |
os: ubuntu-latest | |
- suite: rspress | |
os: ubuntu-latest | |
- suite: rslib | |
os: ubuntu-latest | |
- suite: rsbuild | |
os: ubuntu-latest | |
- suite: examples | |
os: ubuntu-latest | |
fail-fast: false | |
runs-on: ${{ matrix.os }} | |
name: execute-all (${{ matrix.suite }}) | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/build-rspack | |
with: | |
repository: ${{ inputs.repo }} | |
ref: ${{ inputs.branchName }} | |
- run: pnpm i --frozen-lockfile | |
- name: Expose GitHub Runtime | |
uses: crazy-max/ghaction-github-runtime@v3 | |
- run: >- | |
pnpm tsx ecosystem-ci.ts | |
run-suites | |
${{ matrix.suite }} | |
update-comment: | |
runs-on: ubuntu-latest | |
needs: [create-comment, execute-selected-suite, execute-all] | |
if: always() | |
steps: | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }} | |
script: | | |
const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: context.runId, | |
per_page: 100 | |
}); | |
const selectedSuite = context.payload.inputs.suite | |
let result | |
if (selectedSuite !== "-") { | |
const { conclusion, html_url } = jobs.find(job => job.name === "execute-selected-suite") | |
result = [{ suite: `${selectedSuite} ${context.payload.inputs.suiteRefType} ${context.payload.inputs.suiteRef}`, conclusion, link: html_url }] | |
} else { | |
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 = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.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")} | |
` | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: 'rspack', | |
comment_id: ${{ needs.create-comment.outputs.comment-id }}, | |
body | |
}) |