Skip to content
3 changes: 2 additions & 1 deletion discord-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ async function run() {

const refType = env.REF_TYPE
// vite repo is not cloned when release
const permRef = refType === 'release' ? undefined : await getPermanentRef()
const permRef =
refType === 'release' ? undefined : await getPermanentRef(env.REPO, env.REF)

const targetText = createTargetText(refType, env.REF, permRef, env.REPO)

Expand Down
12 changes: 11 additions & 1 deletion ecosystem-ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
bisectVite,
parseViteMajor,
parseMajorVersion,
getPermanentRef,
} from './utils.ts'
import type { CommandOptions, RunOptions } from './types.d.ts'

Expand All @@ -23,9 +24,18 @@ cli
.option('--commit <commit>', 'vite commit sha to use')
.option('--release <version>', 'vite release to use from npm registry')
.action(async (suites, options: CommandOptions) => {
if (
options.branch === 'main' &&
options.repo === 'vitejs/vite' &&
!options.commit
) {
const sha = await getPermanentRef(options.repo, options.branch)
if (sha) {
options.commit = sha
}
}
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
Copy link
Member

Choose a reason for hiding this comment

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

By this code, we will sometimes get a prebuilt package and sometimes don't, depending on when the last commit was pushed. I think we should avoid that if possible so that there aren't differences among the 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.

i see, can you show me an instance where we give the prebuilt package? i'd like to see how can i manipulate the code to perform well on those edge-cases.

i wonder if putting if (options.commit && !options.release) would resolve that edge case or no? would love to hear your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

The example case of using a prebuilt package is:

  1. I push a commit in the main branch at 10:30.
  2. The CI in Vite repo build the package and uploads it at 10:32.
  3. The ecosystem-ci triggers at 10:35.
  4. The ecosystem-ci uses the prebuilt package.

The example case of not using a prebuilt package is:

  1. I push a commit in the main branch at 10:30.
  2. The ecosystem-ci triggers at 10:31.
  3. The ecosystem-ci does not use a prebuilt package.
  4. The CI in Vite repo build the package and uploads it at 10:32.

i wonder if putting if (options.commit && !options.release) would resolve that edge case or no?

I think that doesn't resolve the case.

Expand Down
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?.startsWith('https://pkg.pr.new/vite@')) {
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 ] || (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
12 changes: 8 additions & 4 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,15 @@ export async function setupViteRepo(options: Partial<RepoOptions>) {
}
}

export async function getPermanentRef() {
cd(vitePath)
export async function getPermanentRef(repo: string, ref: string) {
try {
const ref = await $`git log -1 --pretty=format:%H`
return ref
const res = await fetch(
`https://api.github.com/repos/${repo}/branches/${ref}`,
)
const {
commit: { sha },
} = (await res.json()) as { commit: { sha: string } }
return sha
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correct. What we want for the usage in discord-webhook.ts is the commit hash that the ecosystem-ci ran on. This is getting the latest commit hash when the ci finished (i.e. a different hash will be output when a new commit was pushed while the CI is running). (It is fine for the case of ecosystem-ci.ts as it's called before running.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

this should always use the local checkout if it exists and as mentioned by sapphi we can't have ambiguity introduced by new commits. So in case where no local checkout exists, you would have to obtain the ref in a deterministic way. Currently not sure what that is other than asking for it to be passed in (ie never just a branch name but always branch+revision)

} catch (e) {
console.warn(`Failed to obtain perm ref. ${e}`)
return undefined
Expand Down
Loading