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
50 changes: 42 additions & 8 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,16 +24,45 @@ 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

console.log(`continuous release available on ${url}`)
}
const maxAttempts = 60 // 5 minutes
Copy link
Collaborator

Choose a reason for hiding this comment

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

currently vite-ecosystem-ci takes less than one minute to build vite from source. I don't think polling 5 minutes to wait for it to maybe appear on pr.new is the right way to go here.

Either make sure the ecosystem-ci run is only triggered after pr.new is available or skip ahead and build it here.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's important to make it consistent across commits, so I'd prefer not to skip ahead. How about throwing an error if it exceeds 1 minutes? The built package should be available at that time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think ecosystem-ci should be reliant on pr.new availability so fallback is needed.

I'd prefer the wait/poll was implemented at the trigger side, not here

Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer the wait/poll was implemented at the trigger side, not here

The trigger is here in this repo.

on:
schedule:
- cron: "0 5 * * 1,3,5" # monday,wednesday,friday 5AM

Copy link
Collaborator

Choose a reason for hiding this comment

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

it should still go into that job then but not convinced we need this. what's the advantage of pr.new on scheduled runs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey! sorry for the long wait, it's been a bit hard on my side.

it has the same benefits that it has on triggered runs from PRs! it'd avoid the building part on each scheduled run since there's a high chance that commit was already built.

And if it was not built, we wait a bit until it'd be.

But anyway, let me know, I'm ok with making either polling or falling back work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

building vite here takes 14 seconds (thanks rolldown!)

image

is it really going to be faster to check pr.new? Esp. the polling variant feels like overkill. If its there and usable immediately, ok. but else just do it here. scheduled runs (and PR runs too) are unlikely to hit the same commit hash twice, so unless it is cached already there is no benefit for ecosystem-ci

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to keep the behavior consistent across the runs, otherwise there'll be problems that are difficult to investigate like vitejs/vite#20080 (comment).
If the polling is overkill, I think we should always built it here.

let attempts = 0
do {
const { status } = await fetch(url)
if (status !== 200) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this !== instead of the previous === ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey this is for debugging and i need to make few changes.

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)
}
const { root, vitePath, workspace } = await setupEnvironment()
const suitesToRun = getSuitesToRun(suites, root)
Expand Down Expand Up @@ -178,3 +208,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