diff --git a/.github/workflows/ecosystem-ci-selected.yml b/.github/workflows/ecosystem-ci-selected.yml index 11107a09..cc078573 100644 --- a/.github/workflows/ecosystem-ci-selected.yml +++ b/.github/workflows/ecosystem-ci-selected.yml @@ -24,6 +24,11 @@ on: required: true type: string default: "main" + repo: + description: "vite repository to use" + required: true + type: string + default: "vitejs/vite" suite: description: "testsuite to run" required: true @@ -60,7 +65,11 @@ jobs: continue-on-error: true - run: corepack enable - run: pnpm i --frozen-lockfile - - run: pnpm tsx ecosystem-ci.ts --${{ inputs.refType }} ${{ inputs.ref }} ${{ inputs.suite }} + - run: >- + pnpm tsx ecosystem-ci.ts + --${{ inputs.refType }} ${{ inputs.ref }} + --repo ${{ inputs.repo }} + ${{ inputs.suite }} id: ecosystem-ci-run - if: always() run: pnpm tsx discord-webhook.ts @@ -68,6 +77,7 @@ jobs: WORKFLOW_NAME: ci-selected REF_TYPE: ${{ inputs.refType }} REF: ${{ inputs.ref }} + REPO: ${{ inputs.repo }} 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 4099f44f..ca8242d5 100644 --- a/.github/workflows/ecosystem-ci.yml +++ b/.github/workflows/ecosystem-ci.yml @@ -26,6 +26,11 @@ on: required: true type: string default: "main" + repo: + description: "vite repository to use" + required: true + type: string + default: "vitejs/vite" repository_dispatch: types: [ecosystem-ci] jobs: @@ -63,7 +68,11 @@ jobs: continue-on-error: true - run: corepack enable - run: pnpm i --frozen-lockfile - - run: pnpm tsx ecosystem-ci.ts --${{ inputs.refType || github.event.client_payload.refType || 'branch' }} ${{ inputs.ref || github.event.client_payload.ref || 'main' }} ${{ matrix.suite }} + - run: >- + pnpm tsx ecosystem-ci.ts + --${{ inputs.refType || github.event.client_payload.refType || 'branch' }} ${{ inputs.ref || github.event.client_payload.ref || 'main' }} + --repo ${{ inputs.repo || github.event.client_payload.repo || 'vitejs/vite' }} + ${{ matrix.suite }} id: ecosystem-ci-run - if: always() run: pnpm tsx discord-webhook.ts @@ -71,6 +80,7 @@ jobs: WORKFLOW_NAME: ci 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' }} SUITE: ${{ matrix.suite }} STATUS: ${{ job.status }} DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} diff --git a/discord-webhook.ts b/discord-webhook.ts index 29b5f89b..0cfe54dd 100644 --- a/discord-webhook.ts +++ b/discord-webhook.ts @@ -7,6 +7,7 @@ type Env = { WORKFLOW_NAME?: string REF_TYPE?: RefType REF?: string + REPO?: string SUITE?: string STATUS?: Status DISCORD_WEBHOOK_URL?: string @@ -43,6 +44,7 @@ async function run() { assertEnv('WORKFLOW_NAME', env.WORKFLOW_NAME) assertEnv('REF_TYPE', env.REF_TYPE) assertEnv('REF', env.REF) + assertEnv('REPO', env.REPO) assertEnv('SUITE', env.SUITE) assertEnv('STATUS', env.STATUS) assertEnv('DISCORD_WEBHOOK_URL', env.DISCORD_WEBHOOK_URL) @@ -53,7 +55,7 @@ async function run() { // vite repo is not cloned when release const permRef = refType === 'release' ? undefined : await getPermanentRef() - const targetText = createTargetText(refType, env.REF, permRef) + const targetText = createTargetText(refType, env.REF, permRef, env.REPO) const webhookContent = { username: `vite-ecosystem-ci (${env.WORKFLOW_NAME})`, @@ -131,16 +133,18 @@ async function createDescription(suite: string, targetText: string) { function createTargetText( refType: RefType, ref: string, - permRef: string | undefined + permRef: string | undefined, + repo: string ) { + const repoText = repo !== 'vitejs/vite' ? `${repo}:` : '' if (refType === 'branch') { - const link = `https://github.com/vitejs/vite/commits/${permRef || ref}` - return `[${ref} (${permRef || 'unknown'})](${link})` + const link = `https://github.com/${repo}/commits/${permRef || ref}` + return `[${repoText}${ref} (${permRef || 'unknown'})](${link})` } const refTypeText = refType === 'release' ? ' (release)' : '' - const link = `https://github.com/vitejs/vite/commits/${ref}` - return `[${ref}${refTypeText}](${link})` + const link = `https://github.com/${repo}/commits/${ref}` + return `[${repoText}${ref}${refTypeText}](${link})` } run().catch((e) => { diff --git a/ecosystem-ci.ts b/ecosystem-ci.ts index 60ac00bf..a1e05d6e 100644 --- a/ecosystem-ci.ts +++ b/ecosystem-ci.ts @@ -10,6 +10,7 @@ const cli = cac() cli .command('[...suites]', 'build vite and run selected suites') .option('--verify', 'verify checkouts by running tests', { default: false }) + .option('--repo ', 'vite repository to use', { default: 'vitejs/vite' }) .option('--branch ', 'vite branch to use', { default: 'main' }) .option('--tag ', 'vite tag to use') .option('--commit ', 'vite commit sha to use') @@ -39,6 +40,7 @@ cli .option('--verify', 'verify vite checkout by running tests', { default: false }) + .option('--repo ', 'vite repository to use', { default: 'vitejs/vite' }) .option('--branch ', 'vite branch to use', { default: 'main' }) .option('--tag ', 'vite tag to use') .option('--commit ', 'vite commit sha to use') @@ -55,6 +57,7 @@ cli 'verify checkout by running tests before using local vite', { default: false } ) + .option('--repo ', 'vite repository to use', { default: 'vitejs/vite' }) .option('--release ', 'vite release to use from npm registry') .action(async (suites, options: CommandOptions) => { const { root, vitePath, workspace } = await setupEnvironment() @@ -77,6 +80,7 @@ cli ) .option('--good ', 'last known good ref, e.g. a previous tag. REQUIRED!') .option('--verify', 'verify checkouts by running tests', { default: false }) + .option('--repo ', 'vite repository to use', { default: 'vitejs/vite' }) .option('--branch ', 'vite branch to use', { default: 'main' }) .option('--tag ', 'vite tag to use') .option('--commit ', 'vite commit sha to use') diff --git a/types.d.ts b/types.d.ts index be7856b2..0fd0431f 100644 --- a/types.d.ts +++ b/types.d.ts @@ -28,6 +28,7 @@ type Task = string | (() => Promise) export interface CommandOptions { suites?: string[] + repo?: string branch?: string tag?: string commit?: string diff --git a/utils.ts b/utils.ts index d111e0dc..a10744e0 100644 --- a/utils.ts +++ b/utils.ts @@ -71,7 +71,26 @@ export async function setupRepo(options: RepoOptions) { repo = `https://github.com/${repo}.git` } - if (!fs.existsSync(dir)) { + let needClone = true + if (fs.existsSync(dir)) { + const _cwd = cwd + cd(dir) + let currentClonedRepo: string | undefined + try { + currentClonedRepo = await $`git ls-remote --get-url` + } catch { + // when not a git repo + } + cd(_cwd) + + if (repo === currentClonedRepo) { + needClone = false + } else { + fs.rmSync(dir, { recursive: true, force: true }) + } + } + + if (needClone) { await $`git -c advice.detachedHead=false clone ${ shallow ? '--depth=1 --no-tags' : '' } --branch ${tag || branch} ${repo} ${dir}` @@ -210,12 +229,24 @@ export async function runInRepo(options: RunOptions & RepoOptions) { export async function setupViteRepo(options: Partial) { await setupRepo({ - repo: 'vitejs/vite', + repo: options.repo || 'vitejs/vite', dir: vitePath, branch: 'main', shallow: true, ...options }) + + try { + const rootPackageJsonFile = path.join(vitePath, 'package.json') + const rootPackageJson = JSON.parse( + await fs.promises.readFile(rootPackageJsonFile, 'utf-8') + ) + if (rootPackageJson.name !== 'vite-monorepo') { + throw new Error('name does not match') + } + } catch (e) { + throw new Error(`Non-vite repository was cloned by setupViteRepo. (${e})`) + } } export async function getPermanentRef() {