-
-
Notifications
You must be signed in to change notification settings - Fork 77
feat: pkg.pr.new on main #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 15 commits
042e65a
06852c3
00a6c5e
505fe41
8e0cb06
627a5a9
a56f13c
f76ef85
896ce89
04ec121
ade5945
faab52e
257b0ee
1856507
603cee8
2d0e8ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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 | ||
| 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) | ||
| } | ||
| const { root, vitePath, workspace } = await setupEnvironment() | ||
| const suitesToRun = getSuitesToRun(suites, root) | ||
|
|
@@ -178,3 +208,7 @@ function getSuitesToRun(suites: string[], root: string) { | |
| } | ||
| return suitesToRun | ||
| } | ||
|
|
||
| async function sleep(ms: number) { | ||
| return new Promise((resolve) => setTimeout(resolve, ms)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trigger is here in this repo.
vite-ecosystem-ci/.github/workflows/ecosystem-ci.yml
Lines 15 to 17 in 66423f9
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!)
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
There was a problem hiding this comment.
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.