Skip to content
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

feat: pkg.pr.new on main #354

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions discord-webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ 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 Expand Up @@ -132,8 +132,8 @@ async function fetchJobs() {
Accept: 'application/vnd.github.v3+json',
...(process.env.GITHUB_TOKEN
? {
Authorization: `token ${process.env.GITHUB_TOKEN}`,
}
Authorization: `token ${process.env.GITHUB_TOKEN}`,
}
: undefined),
},
})
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
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
} catch (e) {
console.warn(`Failed to obtain perm ref. ${e}`)
return undefined
Expand Down
Loading