Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: enable ecosystem ci #8882

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/actions/eco-ci-result/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 = "rspack-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 '))
.filter(job => job.conclusion !== 'skipped')
.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 = result.length ? `
📝 Ran ecosystem CI: ${urlLink}

| suite | result |
|-------|--------|
${result.map(r => `| [${r.suite}](${r.link}) | ${conclusionEmoji[r.conclusion]} ${r.conclusion} |`).join("\n")}
` : ` 📝 Ran ecosystem CI: ${urlLink}`

console.log(body);

return body;
26 changes: 22 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,7 @@ jobs:
run_ecosystem_ci:
name: Run Ecosystem CI
runs-on: ubuntu-latest
# TODO: enable it after security tokens are added
# if: github.ref_name == 'main' && github.repository_owner == 'web-infra-dev'
if: false
if: github.ref_name == 'main' && github.repository_owner == 'web-infra-dev'
steps:
- name: Run Ecosystem CI
id: eco_ci
Expand All @@ -391,7 +389,7 @@ jobs:
owner: "rspack-contrib"
repo: "rspack-ecosystem-ci"
workflow_file_name: "ecosystem-ci-from-commit.yml"
github_token: ${{ secrets.RSPACK_ACCESS_TOKEN }}
github_token: ${{ secrets.REPO_RSPACK_ECO_CI_GITHUB_TOKEN }}
ref: "main"
client_payload: '{"commitSHA":"${{ github.sha }}","repo":"web-infra-dev/rspack","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'

Expand All @@ -412,6 +410,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: context.sha,
owner: 'web-infra-dev',
repo: 'rspack',
body: ${{ steps.eco-ci-result.outputs.result }}
})

failure_notification:
name: Failure Notification
needs:
Expand Down
156 changes: 74 additions & 82 deletions .github/workflows/ecosystem-ci-trigger.yml
Original file line number Diff line number Diff line change
@@ -1,102 +1,94 @@
name: ecosystem-ci trigger

# TODO: switch to workflow_dispatch
# on:
on:
workflow_dispatch:
inputs:
branch:
description: 'The branch of the Ecosystem CI run'
required: true
default: 'main'

jobs:
trigger:
ecosystem_ci:
name: Run Ecosystem CI
runs-on: ubuntu-latest
if: github.repository == 'web-infra-dev/rspack' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!eco-ci')
if: github.repository == 'web-infra-dev/rspack'
steps:
- uses: actions/github-script@v7
- id: get-pr-number
uses: actions/github-script@v7
name: Get PR Number
with:
script: |
const user = context.payload.sender.login
console.log(`Validate user: ${user}`)

let hasTriagePermission = false
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: user,
});
hasTriagePermission = data.user.permissions.triage
} catch (e) {
console.warn(e)
}

if (hasTriagePermission) {
console.log('Allowed')
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '+1',
})
} else {
console.log('Not allowed')
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '-1',
})
throw new Error('not allowed')
}
- uses: actions/github-script@v7
id: get-pr-data
with:
script: |
console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
const { data: pr } = await github.rest.pulls.get({
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
return {
num: context.issue.number,
branchName: pr.head.ref,
repo: pr.head.repo.full_name
const targetBranch = context.payload.inputs.branch;

const pr = prs.find(pr => pr.head.ref === targetBranch);

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: ${targetBranch}`)
}
- uses: actions/github-script@v7
id: trigger
env:
COMMENT: ${{ github.event.comment.body }}

- id: create-comment
name: Create Comment
uses: actions/github-script@v7
if: steps.get-pr-number.outputs.result
with:
github-token: ${{ secrets.RSPACK_ACCESS_TOKEN }}
result-encoding: string
script: |
const comment = process.env.COMMENT.trim()
const command = comment.split('\n')[0]
const prData = ${{ steps.get-pr-data.outputs.result }}
const url = `${context.serverUrl}//${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const urlLink = `[Open](${url})`
const prData = ${{ steps.get-pr-number.outputs.result }}

const [suite, suiteRefType, suiteRef] = command.replace(/^!eco-ci/, '').trim().split(' ')
const allSuites = suite === '' || suite === '-'
const { data: comment } = await github.rest.issues.createComment({
issue_number: prData.num,
owner: 'web-infra-dev',
repo: 'rspack',
body: `⏳ Triggered ecosystem CI: ${urlLink}`
})
return comment.id

function normalizeSuiteRefType(suiteRefType) {
const prefix = '--suite-'
if (allSuites || suiteRefType === undefined || !suiteRefType.startsWith(prefix)) {
return 'precoded'
}
return suiteRefType.slice(prefix.length)
}
- name: Run Ecosystem CI
id: eco_ci
uses: convictional/[email protected]
continue-on-error: true
with:
owner: "rspack-contrib"
repo: "rspack-ecosystem-ci"
workflow_file_name: "ecosystem-ci-from-pr.yml"
github_token: ${{ secrets.REPO_RSPACK_ECO_CI_GITHUB_TOKEN }}
ref: "main"
client_payload: '{"branchName":"${{ github.event.inputs.branch }}","prNumber":"0","repo":"web-infra-dev/rspack","suite":"-","suiteRefType":"precoded","suiteRef":"precoded"}'
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 1

function normalizeSuiteRef(suiteRef) {
return (allSuites || suiteRef === undefined) ? 'precoded' : suiteRef
}
- id: eco-ci-result
uses: ./.github/actions/eco-ci-result
name: Get CI Result
with:
workflow-output: ${{ toJson(steps.eco_ci.outputs) }}

await github.rest.actions.createWorkflowDispatch({
owner: 'rspack-contrib',
repo: 'rspack-ecosystem-ci',
workflow_id: 'ecosystem-ci-from-pr.yml',
ref: 'main',
inputs: {
prNumber: '' + prData.num,
branchName: prData.branchName,
repo: prData.repo,
suite: allSuites ? '-' : suite,
suiteRefType: normalizeSuiteRefType(suiteRefType),
suiteRef: normalizeSuiteRef(suiteRef),
}
- id: update-comment
uses: actions/github-script@v7
if: steps.get-pr-number.outputs.result
name: Update Comment
with:
script: |
await github.rest.issues.updateComment({
owner: 'web-infra-dev',
repo: 'rspack',
comment_id: ${{ steps.create-comment.outputs.result }},
body: ${{ steps.eco-ci-result.outputs.result }}
})
Loading