Skip to content

ecosystem-ci-from-pr #196

ecosystem-ci-from-pr

ecosystem-ci-from-pr #196

# integration tests for vue ecosystem - run from pr comments
name: 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: "vue branch to use"
required: true
type: string
default: "main"
repo:
description: "vue repository to use"
required: true
type: string
default: "vuejs/core"
suite:
description: "testsuite to run. runs all testsuits when `-`."
required: false
type: choice
options:
- "-"
- language-tools
# - naive-ui
- nuxt
- pinia
- quasar
- radix-vue
- router
- test-utils
- vant
- vite-plugin-vue
- vitepress
- vue-i18n
- vue-macros
- vuetify
- vueuse
- vue-simple-compiler
jobs:
init:
runs-on: ubuntu-latest
outputs:
comment-id: ${{ steps.create-comment.outputs.result }}
steps:
- id: create-comment
uses: actions/github-script@v7
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: 'core',
body: `⏳ Triggered ecosystem CI: ${urlLink}`
})
return comment.id
execute-selected-suite:
timeout-minutes: 60
runs-on: ubuntu-latest
needs: init
if: "inputs.suite != '-'"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
--branch ${{ inputs.branchName }}
--repo ${{ inputs.repo }}
${{ inputs.suite }}
env:
COREPACK_ENABLE_STRICT: 0
execute-all:
timeout-minutes: 60
runs-on: ubuntu-latest
needs: init
if: "inputs.suite == '-'"
strategy:
matrix:
suite:
- language-tools
# - naive-ui
- nuxt
- pinia
- quasar
- radix-vue
- router
- test-utils
- vant
- vite-plugin-vue
- vitepress
- vue-i18n
- vue-macros
- vuetify
- vueuse
- vue-simple-compiler
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.12.0
- run: corepack enable
- run: pnpm --version
- run: pnpm i --frozen-lockfile
- run: >-
pnpm tsx ecosystem-ci.ts
--branch ${{ inputs.branchName }}
--repo ${{ inputs.repo }}
${{ matrix.suite }}
env:
COREPACK_ENABLE_STRICT: 0
update-comment:
runs-on: ubuntu-latest
needs: [init, execute-selected-suite, execute-all]
if: always()
steps:
- uses: actions/github-script@v7
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 results
if (selectedSuite !== "-") {
const { conclusion, html_url } = jobs.find(job => job.name === "execute-selected-suite")
results = [{ suite: selectedSuite, conclusion, link: html_url }]
} else {
results = 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:"
}
// check for previous ecosystem-ci runs against the main branch
// first, list workflow runs for ecosystem-ci.yml
const { data: { workflow_runs } } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'ecosystem-ci.yml'
});
// for simplity, we only take the latest completed scheduled run
// otherwise we would have to check the inputs for every maunally triggerred runs, which is an overkill
const latestScheduledRun = workflow_runs.find(run => run.event === "schedule" && run.status === "completed")
// get the jobs for the latest scheduled run
const { data: { jobs: scheduledJobs } } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: latestScheduledRun.id
});
const scheduledResults = scheduledJobs
.filter(job => job.name.startsWith('test-ecosystem '))
.map(job => {
const suite = job.name.replace(/^test-ecosystem \(([^)]+)\)$/, "$1")
return { suite, conclusion: job.conclusion, link: job.html_url }
})
const body = `
📝 Ran ecosystem CI: ${urlLink}
| suite | result | [latest scheduled](${latestScheduledRun.html_url}) |
|-------|--------|----------------|
${results.map(current => {
const latest = scheduledResults.find(s => s.suite === current.suite) || {} // in case a new suite is added after latest scheduled
const firstColumn = current.suite
const secondColumn = `${conclusionEmoji[current.conclusion]} [${current.conclusion}](${current.link})`
const thirdColumn = `${conclusionEmoji[latest.conclusion]} [${latest.conclusion}](${latest.link})`
return `| ${firstColumn} | ${secondColumn} | ${thirdColumn} |`
}).join("\n")}
`
await github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: 'core',
comment_id: ${{ needs.init.outputs.comment-id }}
})
await github.rest.issues.createComment({
issue_number: context.payload.inputs.prNumber,
owner: context.repo.owner,
repo: 'core',
body
})