Skip to content

Commit c1666d2

Browse files
authored
feat: vite repo (#120)
* feat: repo option * feat: repo option discord webhook * feat: repo option discord webhook * feat: assert root package.json name * fix: condition
1 parent 101506d commit c1666d2

6 files changed

Lines changed: 70 additions & 10 deletions

File tree

.github/workflows/ecosystem-ci-selected.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ on:
2424
required: true
2525
type: string
2626
default: "main"
27+
repo:
28+
description: "vite repository to use"
29+
required: true
30+
type: string
31+
default: "vitejs/vite"
2732
suite:
2833
description: "testsuite to run"
2934
required: true
@@ -60,14 +65,19 @@ jobs:
6065
continue-on-error: true
6166
- run: corepack enable
6267
- run: pnpm i --frozen-lockfile
63-
- run: pnpm tsx ecosystem-ci.ts --${{ inputs.refType }} ${{ inputs.ref }} ${{ inputs.suite }}
68+
- run: >-
69+
pnpm tsx ecosystem-ci.ts
70+
--${{ inputs.refType }} ${{ inputs.ref }}
71+
--repo ${{ inputs.repo }}
72+
${{ inputs.suite }}
6473
id: ecosystem-ci-run
6574
- if: always()
6675
run: pnpm tsx discord-webhook.ts
6776
env:
6877
WORKFLOW_NAME: ci-selected
6978
REF_TYPE: ${{ inputs.refType }}
7079
REF: ${{ inputs.ref }}
80+
REPO: ${{ inputs.repo }}
7181
SUITE: ${{ inputs.suite }}
7282
STATUS: ${{ job.status }}
7383
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}

.github/workflows/ecosystem-ci.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ on:
2626
required: true
2727
type: string
2828
default: "main"
29+
repo:
30+
description: "vite repository to use"
31+
required: true
32+
type: string
33+
default: "vitejs/vite"
2934
repository_dispatch:
3035
types: [ecosystem-ci]
3136
jobs:
@@ -63,14 +68,19 @@ jobs:
6368
continue-on-error: true
6469
- run: corepack enable
6570
- run: pnpm i --frozen-lockfile
66-
- run: pnpm tsx ecosystem-ci.ts --${{ inputs.refType || github.event.client_payload.refType || 'branch' }} ${{ inputs.ref || github.event.client_payload.ref || 'main' }} ${{ matrix.suite }}
71+
- run: >-
72+
pnpm tsx ecosystem-ci.ts
73+
--${{ inputs.refType || github.event.client_payload.refType || 'branch' }} ${{ inputs.ref || github.event.client_payload.ref || 'main' }}
74+
--repo ${{ inputs.repo || github.event.client_payload.repo || 'vitejs/vite' }}
75+
${{ matrix.suite }}
6776
id: ecosystem-ci-run
6877
- if: always()
6978
run: pnpm tsx discord-webhook.ts
7079
env:
7180
WORKFLOW_NAME: ci
7281
REF_TYPE: ${{ inputs.refType || github.event.client_payload.refType || 'branch' }}
7382
REF: ${{ inputs.ref || github.event.client_payload.ref || 'main' }}
83+
REPO: ${{ inputs.repo || github.event.client_payload.repo || 'vitejs/vite' }}
7484
SUITE: ${{ matrix.suite }}
7585
STATUS: ${{ job.status }}
7686
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}

discord-webhook.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Env = {
77
WORKFLOW_NAME?: string
88
REF_TYPE?: RefType
99
REF?: string
10+
REPO?: string
1011
SUITE?: string
1112
STATUS?: Status
1213
DISCORD_WEBHOOK_URL?: string
@@ -43,6 +44,7 @@ async function run() {
4344
assertEnv('WORKFLOW_NAME', env.WORKFLOW_NAME)
4445
assertEnv('REF_TYPE', env.REF_TYPE)
4546
assertEnv('REF', env.REF)
47+
assertEnv('REPO', env.REPO)
4648
assertEnv('SUITE', env.SUITE)
4749
assertEnv('STATUS', env.STATUS)
4850
assertEnv('DISCORD_WEBHOOK_URL', env.DISCORD_WEBHOOK_URL)
@@ -53,7 +55,7 @@ async function run() {
5355
// vite repo is not cloned when release
5456
const permRef = refType === 'release' ? undefined : await getPermanentRef()
5557

56-
const targetText = createTargetText(refType, env.REF, permRef)
58+
const targetText = createTargetText(refType, env.REF, permRef, env.REPO)
5759

5860
const webhookContent = {
5961
username: `vite-ecosystem-ci (${env.WORKFLOW_NAME})`,
@@ -131,16 +133,18 @@ async function createDescription(suite: string, targetText: string) {
131133
function createTargetText(
132134
refType: RefType,
133135
ref: string,
134-
permRef: string | undefined
136+
permRef: string | undefined,
137+
repo: string
135138
) {
139+
const repoText = repo !== 'vitejs/vite' ? `${repo}:` : ''
136140
if (refType === 'branch') {
137-
const link = `https://github.com/vitejs/vite/commits/${permRef || ref}`
138-
return `[${ref} (${permRef || 'unknown'})](${link})`
141+
const link = `https://github.com/${repo}/commits/${permRef || ref}`
142+
return `[${repoText}${ref} (${permRef || 'unknown'})](${link})`
139143
}
140144

141145
const refTypeText = refType === 'release' ? ' (release)' : ''
142-
const link = `https://github.com/vitejs/vite/commits/${ref}`
143-
return `[${ref}${refTypeText}](${link})`
146+
const link = `https://github.com/${repo}/commits/${ref}`
147+
return `[${repoText}${ref}${refTypeText}](${link})`
144148
}
145149

146150
run().catch((e) => {

ecosystem-ci.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const cli = cac()
1010
cli
1111
.command('[...suites]', 'build vite and run selected suites')
1212
.option('--verify', 'verify checkouts by running tests', { default: false })
13+
.option('--repo <repo>', 'vite repository to use', { default: 'vitejs/vite' })
1314
.option('--branch <branch>', 'vite branch to use', { default: 'main' })
1415
.option('--tag <tag>', 'vite tag to use')
1516
.option('--commit <commit>', 'vite commit sha to use')
@@ -39,6 +40,7 @@ cli
3940
.option('--verify', 'verify vite checkout by running tests', {
4041
default: false
4142
})
43+
.option('--repo <repo>', 'vite repository to use', { default: 'vitejs/vite' })
4244
.option('--branch <branch>', 'vite branch to use', { default: 'main' })
4345
.option('--tag <tag>', 'vite tag to use')
4446
.option('--commit <commit>', 'vite commit sha to use')
@@ -55,6 +57,7 @@ cli
5557
'verify checkout by running tests before using local vite',
5658
{ default: false }
5759
)
60+
.option('--repo <repo>', 'vite repository to use', { default: 'vitejs/vite' })
5861
.option('--release <version>', 'vite release to use from npm registry')
5962
.action(async (suites, options: CommandOptions) => {
6063
const { root, vitePath, workspace } = await setupEnvironment()
@@ -77,6 +80,7 @@ cli
7780
)
7881
.option('--good <ref>', 'last known good ref, e.g. a previous tag. REQUIRED!')
7982
.option('--verify', 'verify checkouts by running tests', { default: false })
83+
.option('--repo <repo>', 'vite repository to use', { default: 'vitejs/vite' })
8084
.option('--branch <branch>', 'vite branch to use', { default: 'main' })
8185
.option('--tag <tag>', 'vite tag to use')
8286
.option('--commit <commit>', 'vite commit sha to use')

types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Task = string | (() => Promise<any>)
2828

2929
export interface CommandOptions {
3030
suites?: string[]
31+
repo?: string
3132
branch?: string
3233
tag?: string
3334
commit?: string

utils.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,26 @@ export async function setupRepo(options: RepoOptions) {
7171
repo = `https://github.com/${repo}.git`
7272
}
7373

74-
if (!fs.existsSync(dir)) {
74+
let needClone = true
75+
if (fs.existsSync(dir)) {
76+
const _cwd = cwd
77+
cd(dir)
78+
let currentClonedRepo: string | undefined
79+
try {
80+
currentClonedRepo = await $`git ls-remote --get-url`
81+
} catch {
82+
// when not a git repo
83+
}
84+
cd(_cwd)
85+
86+
if (repo === currentClonedRepo) {
87+
needClone = false
88+
} else {
89+
fs.rmSync(dir, { recursive: true, force: true })
90+
}
91+
}
92+
93+
if (needClone) {
7594
await $`git -c advice.detachedHead=false clone ${
7695
shallow ? '--depth=1 --no-tags' : ''
7796
} --branch ${tag || branch} ${repo} ${dir}`
@@ -210,12 +229,24 @@ export async function runInRepo(options: RunOptions & RepoOptions) {
210229

211230
export async function setupViteRepo(options: Partial<RepoOptions>) {
212231
await setupRepo({
213-
repo: 'vitejs/vite',
232+
repo: options.repo || 'vitejs/vite',
214233
dir: vitePath,
215234
branch: 'main',
216235
shallow: true,
217236
...options
218237
})
238+
239+
try {
240+
const rootPackageJsonFile = path.join(vitePath, 'package.json')
241+
const rootPackageJson = JSON.parse(
242+
await fs.promises.readFile(rootPackageJsonFile, 'utf-8')
243+
)
244+
if (rootPackageJson.name !== 'vite-monorepo') {
245+
throw new Error('name does not match')
246+
}
247+
} catch (e) {
248+
throw new Error(`Non-vite repository was cloned by setupViteRepo. (${e})`)
249+
}
219250
}
220251

221252
export async function getPermanentRef() {

0 commit comments

Comments
 (0)