diff --git a/.github/workflows/ecosystem-ci-selected.yml b/.github/workflows/ecosystem-ci-selected.yml index 522a2798..e2aa6d60 100644 --- a/.github/workflows/ecosystem-ci-selected.yml +++ b/.github/workflows/ecosystem-ci-selected.yml @@ -101,6 +101,7 @@ jobs: REF_TYPE: ${{ inputs.refType }} REF: ${{ inputs.ref }} REPO: ${{ inputs.repo }} + COMMIT: ${{ steps.ecosystem-ci-run.outputs.commit }} SUITE: ${{ inputs.suite }} STATUS: ${{ job.status }} DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} diff --git a/.github/workflows/ecosystem-ci.yml b/.github/workflows/ecosystem-ci.yml index f8026ff6..ced40fb4 100644 --- a/.github/workflows/ecosystem-ci.yml +++ b/.github/workflows/ecosystem-ci.yml @@ -104,6 +104,7 @@ jobs: REF_TYPE: ${{ inputs.refType || github.event.client_payload.refType || 'branch' }} REF: ${{ inputs.ref || github.event.client_payload.ref || 'main' }} REPO: ${{ inputs.repo || github.event.client_payload.repo || 'vitejs/vite' }} + COMMIT: ${{ steps.ecosystem-ci-run.outputs.commit }} SUITE: ${{ matrix.suite }} STATUS: ${{ job.status }} DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} diff --git a/discord-webhook.ts b/discord-webhook.ts index fee90010..2463cefd 100644 --- a/discord-webhook.ts +++ b/discord-webhook.ts @@ -1,5 +1,5 @@ import fetch from 'node-fetch' -import { getPermanentRef, setupEnvironment } from './utils.ts' +import { setupEnvironment, getPermanentRef } from './utils.ts' type RefType = 'branch' | 'tag' | 'commit' | 'release' type Status = 'success' | 'failure' | 'cancelled' @@ -8,6 +8,7 @@ type Env = { REF_TYPE?: RefType REF?: string REPO?: string + COMMIT?: string SUITE?: string STATUS?: Status DISCORD_WEBHOOK_URL?: string @@ -57,8 +58,14 @@ async function run() { await setupEnvironment() const refType = env.REF_TYPE - // vite repo is not cloned when release - const permRef = refType === 'release' ? undefined : await getPermanentRef() + let permRef: string | undefined + + if (env.COMMIT) { + permRef = env.COMMIT + } else if (refType !== 'release') { + // vite repo is not cloned when release + permRef = await getPermanentRef() + } const targetText = createTargetText(refType, env.REF, permRef, env.REPO) diff --git a/ecosystem-ci.ts b/ecosystem-ci.ts index 98ae3cb1..75465604 100644 --- a/ecosystem-ci.ts +++ b/ecosystem-ci.ts @@ -2,6 +2,7 @@ import fs from 'fs' import path from 'path' import process from 'process' import { cac } from 'cac' +import actionsCore from '@actions/core' import { setupEnvironment, @@ -23,15 +24,49 @@ cli .option('--commit ', 'vite commit sha to use') .option('--release ', 'vite release to use from npm registry') .action(async (suites, options: CommandOptions) => { + let poll = false + if ( + options.branch === 'main' && + options.repo === 'vitejs/vite' && + !options.commit + ) { + const res = await fetch( + `https://api.github.com/repos/${options.repo}/branches/${options.branch}`, + ) + const { + commit: { sha }, + } = (await res.json()) as { commit: { sha: string } } + if (sha) { + options.commit = sha + actionsCore.setOutput('commit', sha) + poll = true + } + } if (options.commit) { const url = `https://pkg.pr.new/vite@${options.commit}` - //eslint-disable-next-line n/no-unsupported-features/node-builtins - const { status } = await fetch(url) - if (status === 200) { - options.release = url - delete options.commit + const maxAttempts = 12 // 1 minute + let attempts = 0 + do { + const { status } = await fetch(url) + if (status === 200) { + options.release = url + delete options.commit + console.log(`continuous release available on ${url}`) + poll = false + } + if (poll) { + // wait 5 seconds before polling again + await sleep(5 * 1000) + } + attempts++ + console.log( + `Polling attempt ${attempts}/${maxAttempts} for continuous release at ${url}`, + ) + } while (poll && attempts < maxAttempts) - console.log(`continuous release available on ${url}`) + if (poll && !options.release) { + console.error(`no continuous release found for ${options.commit}`) + process.exit(1) } } const { root, vitePath, workspace } = await setupEnvironment() @@ -178,3 +213,7 @@ function getSuitesToRun(suites: string[], root: string) { } return suitesToRun } + +async function sleep(ms: number) { + return new Promise((resolve) => setTimeout(resolve, ms)) +} diff --git a/tests/_selftest.ts b/tests/_selftest.ts index 5accdda7..cf80cab4 100644 --- a/tests/_selftest.ts +++ b/tests/_selftest.ts @@ -16,8 +16,13 @@ export async function test(options: RunOptions) { `invalid checkout, expected package.json with "name":"vite-ecosystem-ci" in ${dir}`, ) } - pkg.scripts.selftestscript = - "[ -d ../../vite/packages/vite/dist ] || (echo 'vite build failed' && exit 1)" + if (options.release) { + pkg.scripts.selftestscript = + "[ -d ./node_modules/vite/dist ] || (echo 'vite build failed' && exit 1)" + } else { + pkg.scripts.selftestscript = + "[ -d ../../vite/packages/vite/dist ] || (echo 'vite build failed' && exit 1)" + } await fs.promises.writeFile( pkgFile, JSON.stringify(pkg, null, 2),