diff --git a/discord-webhook.ts b/discord-webhook.ts index fee9001..3dc85f2 100644 --- a/discord-webhook.ts +++ b/discord-webhook.ts @@ -58,7 +58,8 @@ async function run() { const refType = env.REF_TYPE // vite repo is not cloned when release - const permRef = refType === 'release' ? undefined : await getPermanentRef() + const permRef = + refType === 'release' ? undefined : await getPermanentRef(env.REPO, env.REF) const targetText = createTargetText(refType, env.REF, permRef, env.REPO) diff --git a/ecosystem-ci.ts b/ecosystem-ci.ts index 98ae3cb..436d419 100644 --- a/ecosystem-ci.ts +++ b/ecosystem-ci.ts @@ -10,6 +10,7 @@ import { bisectVite, parseViteMajor, parseMajorVersion, + getPermanentRef, } from './utils.ts' import type { CommandOptions, RunOptions } from './types.d.ts' @@ -23,9 +24,18 @@ cli .option('--commit ', 'vite commit sha to use') .option('--release ', 'vite release to use from npm registry') .action(async (suites, options: CommandOptions) => { + if ( + options.branch === 'main' && + options.repo === 'vitejs/vite' && + !options.commit + ) { + const sha = await getPermanentRef(options.repo, options.branch) + if (sha) { + options.commit = sha + } + } 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 diff --git a/tests/_selftest.ts b/tests/_selftest.ts index 5accdda..1ec56c1 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?.startsWith('https://pkg.pr.new/vite@')) { + pkg.scripts.selftestscript = + "[ -d ./node_modules/vite ] || (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), diff --git a/utils.ts b/utils.ts index 75eef8d..2097700 100644 --- a/utils.ts +++ b/utils.ts @@ -371,11 +371,15 @@ export async function setupViteRepo(options: Partial) { } } -export async function getPermanentRef() { - cd(vitePath) +export async function getPermanentRef(repo: string, ref: string) { try { - const ref = await $`git log -1 --pretty=format:%H` - return ref + const res = await fetch( + `https://api.github.com/repos/${repo}/branches/${ref}`, + ) + const { + commit: { sha }, + } = (await res.json()) as { commit: { sha: string } } + return sha } catch (e) { console.warn(`Failed to obtain perm ref. ${e}`) return undefined