Skip to content
1 change: 1 addition & 0 deletions .github/workflows/ecosystem-ci-selected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ecosystem-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
13 changes: 10 additions & 3 deletions discord-webhook.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -8,6 +8,7 @@ type Env = {
REF_TYPE?: RefType
REF?: string
REPO?: string
COMMIT?: string
SUITE?: string
STATUS?: Status
DISCORD_WEBHOOK_URL?: string
Expand Down Expand Up @@ -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)

Expand Down
51 changes: 45 additions & 6 deletions ecosystem-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,15 +24,49 @@ cli
.option('--commit <commit>', 'vite commit sha to use')
.option('--release <version>', '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()
Expand Down Expand Up @@ -178,3 +213,7 @@ function getSuitesToRun(suites: string[], root: string) {
}
return suitesToRun
}

async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
9 changes: 7 additions & 2 deletions tests/_selftest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Copy link
Contributor Author

@Aslemammad Aslemammad Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sapphi-red would love to hear your thoughts on this now that the ci is fixed by this!

"[ -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),
Expand Down