Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/ecosystem-ci-selected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -60,14 +65,19 @@ 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: >-
Comment thread
dominikg marked this conversation as resolved.
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
env:
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 }}
12 changes: 11 additions & 1 deletion .github/workflows/ecosystem-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -63,14 +68,19 @@ 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
env:
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 }}
16 changes: 10 additions & 6 deletions discord-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Env = {
WORKFLOW_NAME?: string
REF_TYPE?: RefType
REF?: string
REPO?: string
SUITE?: string
STATUS?: Status
DISCORD_WEBHOOK_URL?: string
Expand Down Expand Up @@ -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)
Expand All @@ -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})`,
Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 4 additions & 0 deletions ecosystem-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <repo>', 'vite repository to use', { default: 'vitejs/vite' })
.option('--branch <branch>', 'vite branch to use', { default: 'main' })
.option('--tag <tag>', 'vite tag to use')
.option('--commit <commit>', 'vite commit sha to use')
Expand Down Expand Up @@ -39,6 +40,7 @@ cli
.option('--verify', 'verify vite checkout by running tests', {
default: false
})
.option('--repo <repo>', 'vite repository to use', { default: 'vitejs/vite' })
.option('--branch <branch>', 'vite branch to use', { default: 'main' })
.option('--tag <tag>', 'vite tag to use')
.option('--commit <commit>', 'vite commit sha to use')
Expand All @@ -55,6 +57,7 @@ cli
'verify checkout by running tests before using local vite',
{ default: false }
)
.option('--repo <repo>', 'vite repository to use', { default: 'vitejs/vite' })
.option('--release <version>', 'vite release to use from npm registry')
.action(async (suites, options: CommandOptions) => {
const { root, vitePath, workspace } = await setupEnvironment()
Expand All @@ -77,6 +80,7 @@ cli
)
.option('--good <ref>', 'last known good ref, e.g. a previous tag. REQUIRED!')
.option('--verify', 'verify checkouts by running tests', { default: false })
.option('--repo <repo>', 'vite repository to use', { default: 'vitejs/vite' })
.option('--branch <branch>', 'vite branch to use', { default: 'main' })
.option('--tag <tag>', 'vite tag to use')
.option('--commit <commit>', 'vite commit sha to use')
Expand Down
1 change: 1 addition & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Task = string | (() => Promise<any>)

export interface CommandOptions {
suites?: string[]
repo?: string
branch?: string
tag?: string
commit?: string
Expand Down
35 changes: 33 additions & 2 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down Expand Up @@ -210,12 +229,24 @@ export async function runInRepo(options: RunOptions & RepoOptions) {

export async function setupViteRepo(options: Partial<RepoOptions>) {
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() {
Expand Down