nuxt-ecosystem-ci-from-pr #48
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 nuxt ecosystem - run from pr comments | |
name: nuxt-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 | |
# configure corepack to be strict but not download newer versions or change anything | |
COREPACK_DEFAULT_TO_LATEST: 0 | |
COREPACK_ENABLE_AUTO_PIN: 0 | |
COREPACK_ENABLE_STRICT: 1 | |
on: | |
workflow_dispatch: | |
inputs: | |
prNumber: | |
description: PR number (e.g. 9887) | |
required: true | |
type: string | |
branchName: | |
description: nuxt branch to use | |
required: true | |
type: string | |
default: main | |
nitro: | |
description: the version of nitro to use | |
type: choice | |
options: | |
- v3 nightly | |
- v2 nightly | |
- v2 latest | |
default: v2 latest | |
repo: | |
description: nuxt repository to use | |
required: true | |
type: string | |
default: nuxt/nuxt | |
suite: | |
description: test suite to run. runs all test suites when `-`. | |
required: false | |
type: choice | |
options: | |
- '-' | |
- starter | |
- content | |
- ui | |
- image | |
- pinia | |
- examples | |
- example-layers-monorepo | |
- bridge | |
- nuxt-com | |
- vite-pwa | |
- docus | |
- og-image | |
- histoire | |
- elk | |
- devtools | |
- fonts | |
- scripts | |
- icon | |
- cli | |
- test-utils | |
- module-builder | |
- sanity-module | |
- tailwindcss | |
- sitemap | |
- i18n-module | |
- werewolves-assistant | |
- storybook | |
jobs: | |
init: | |
runs-on: ubuntu-latest | |
outputs: | |
comment-id: ${{ steps.create-comment.outputs.result }} | |
steps: | |
- id: generate-token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ secrets.PR_GITHUB_APP_ID }} | |
private_key: ${{ secrets.PR_GITHUB_APP_PRIVATE_KEY }} | |
repository: '${{ github.repository_owner }}/nuxt' | |
- id: create-comment | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ steps.generate-token.outputs.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: 'nuxt', | |
body: `⏳ Triggered ecosystem CI: ${urlLink}` | |
}) | |
return comment.id | |
execute-selected-suite: | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
needs: init | |
if: 'inputs.suite != ''-''' | |
outputs: | |
ref: ${{ steps.get-ref.outputs.ref }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- 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: | |
NUXT_UI_PRO_TOKEN: ${{ secrets.NUXT_UI_PRO_TOKEN }} | |
NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_TOKEN }} | |
NITRO_VERSION: ${{ inputs.nitro }} | |
- id: get-ref | |
if: always() | |
run: | | |
ref=$(git log -1 --pretty=format:%H) | |
echo "ref=$ref" >> $GITHUB_OUTPUT | |
working-directory: workspace/nuxt | |
execute-all: | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
needs: init | |
if: 'inputs.suite == ''-''' | |
outputs: | |
ref: ${{ steps.get-ref.outputs.ref }} | |
strategy: | |
matrix: | |
suite: | |
- starter | |
- content | |
- ui | |
- image | |
- pinia | |
- examples | |
- example-layers-monorepo | |
- bridge | |
- nuxt-com | |
- vite-pwa | |
- docus | |
- og-image | |
- histoire | |
- elk | |
- devtools | |
- fonts | |
- scripts | |
- icon | |
- cli | |
- test-utils | |
- module-builder | |
- sanity-module | |
- tailwindcss | |
- sitemap | |
- i18n-module | |
- werewolves-assistant | |
- storybook | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- 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: | |
NUXT_UI_PRO_TOKEN: ${{ secrets.NUXT_UI_PRO_TOKEN }} | |
NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_TOKEN }} | |
- id: get-ref | |
if: always() | |
run: | | |
ref=$(git log -1 --pretty=format:%H) | |
echo "ref=$ref" >> $GITHUB_OUTPUT | |
working-directory: workspace/nuxt | |
update-comment: | |
runs-on: ubuntu-latest | |
needs: [init, execute-selected-suite, execute-all] | |
if: always() | |
steps: | |
- id: generate-token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ secrets.PR_GITHUB_APP_ID }} | |
private_key: ${{ secrets.PR_GITHUB_APP_PRIVATE_KEY }} | |
repository: '${{ github.repository_owner }}/nuxt' | |
- uses: actions/github-script@v7 | |
with: | |
github-token: ${{ steps.generate-token.outputs.token }} | |
script: | | |
const mainRepoName = 'nuxt' | |
const ref = "${{ needs.execute-all.outputs.ref }}" || "${{ needs.execute-selected-suite.outputs.ref }}" | |
const refLink = `[\`${ref.slice(0, 7)}\`](${context.serverUrl}/${context.repo.owner}/${mainRepoName}/pull/${context.payload.inputs.prNumber}/commits/${ref})` | |
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 rows = [] | |
const successfulSuitesWithoutChanges = [] | |
results.forEach(current => { | |
const latest = scheduledResults.find(s => s.suite === current.suite) || {} // in case a new suite is added after latest scheduled | |
if (current.conclusion === "success" && latest.conclusion === "success") { | |
successfulSuitesWithoutChanges.push(`[${current.suite}](${current.link})`) | |
} | |
else { | |
const firstColumn = current.suite | |
const secondColumn = `${conclusionEmoji[current.conclusion]} [${current.conclusion}](${current.link})` | |
const thirdColumn = `${conclusionEmoji[latest.conclusion]} [${latest.conclusion}](${latest.link})` | |
rows.push(`| ${firstColumn} | ${secondColumn} | ${thirdColumn} |`) | |
} | |
}) | |
let body = ` | |
📝 Ran ecosystem CI on ${refLink}: ${urlLink} | |
` | |
if (rows.length > 0) { | |
body += `| suite | result | [latest scheduled](${latestScheduledRun.html_url}) | | |
|-------|--------|----------------| | |
${rows.join("\n")} | |
${conclusionEmoji.success} ${successfulSuitesWithoutChanges.join(", ")} | |
` | |
} else { | |
body += `${conclusionEmoji.success} ${successfulSuitesWithoutChanges.join(", ")} | |
` | |
} | |
await github.rest.issues.createComment({ | |
issue_number: context.payload.inputs.prNumber, | |
owner: context.repo.owner, | |
repo: mainRepoName, | |
comment_id: ${{ needs.init.outputs.comment-id }}, | |
body | |
}) | |
await github.rest.issues.deleteComment({ | |
owner: context.repo.owner, | |
repo: mainRepoName, | |
comment_id: ${{ needs.init.outputs.comment-id }} | |
}) |