svelte-ecosystem-ci-from-pr #29
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 svelte ecosystem - run from pr comments | |
name: svelte-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: "svelte branch to use" | |
required: true | |
type: string | |
default: "main" | |
repo: | |
description: "svelte repository to use" | |
required: true | |
type: string | |
default: "sveltejs/svelte" | |
suite: | |
description: "testsuite to run. runs all testsuits when `-`." | |
required: false | |
type: choice | |
options: | |
- "-" | |
- eslint-plugin-svelte | |
- language-tools | |
- mdsvex | |
- melt-ui | |
- melt-ui-preprocessor | |
- prettier-plugin-svelte | |
- rollup-plugin-svelte | |
- skeleton | |
- svelte-eslint-parser | |
- svelte-loader | |
- svelte-preprocess | |
- sveltekit | |
- vite-plugin-svelte | |
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.ECOSYSTEM_CI_GITHUB_APP_ID }} | |
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }} | |
repository: "${{ github.repository_owner }}/svelte" | |
- id: create-comment | |
uses: actions/github-script@v6 | |
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: 'svelte', | |
body: `⏳ Triggered ecosystem CI: ${urlLink}` | |
}) | |
return comment.id | |
execute-selected-suite: | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
needs: init | |
if: "inputs.suite != '-'" | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- uses: denoland/setup-deno@v1 | |
with: | |
deno-version: v1.x | |
continue-on-error: true | |
- 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 }} | |
execute-all: | |
timeout-minutes: 30 | |
runs-on: ubuntu-latest | |
needs: init | |
if: "inputs.suite == '-'" | |
strategy: | |
matrix: | |
suite: | |
- eslint-plugin-svelte | |
- language-tools | |
- mdsvex | |
- melt-ui | |
- melt-ui-preprocessor | |
- prettier-plugin-svelte | |
- rollup-plugin-svelte | |
- skeleton | |
- svelte-eslint-parser | |
- svelte-loader | |
- svelte-preprocess | |
- sveltekit | |
- vite-plugin-svelte | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- uses: denoland/setup-deno@v1 | |
with: | |
deno-version: v1.x | |
continue-on-error: true | |
- 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 }} | |
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.ECOSYSTEM_CI_GITHUB_APP_ID }} | |
private_key: ${{ secrets.ECOSYSTEM_CI_GITHUB_APP_PRIVATE_KEY }} | |
repository: "${{ github.repository_owner }}/svelte" | |
- uses: actions/github-script@v6 | |
with: | |
github-token: ${{ steps.generate-token.outputs.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, 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: 'svelte', | |
comment_id: ${{ needs.init.outputs.comment-id }}, | |
body | |
}) |