Skip to content

Commit

Permalink
fix: check release on pkg.pr.new and fallback to build
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 19, 2024
1 parent a94bd14 commit 927aff5
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion ecosystem-ci.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import https from 'node:https'
import { cac } from 'cac'

import {
Expand Down Expand Up @@ -39,7 +40,15 @@ cli
// Normalize branch / commit to pkg.pr.new releases
if (!isSelfTest && !options.release && !options.tag && !options.local) {
if (options.commit) {
options.release = `@${options.commit.slice(0, 7)}`
const shortSha = options.commit.slice(0, 7)
const hasRelease = await checkRelease(shortSha)
if (hasRelease) {
options.release = `@${shortSha}`
} else {
console.log(
'\nCommit not released on pkg.pr.new yet, building from source.\n',
)
}
} else if (options.repo === 'vuejs/core' && options.branch) {
options.release = `@${options.branch}`
}
Expand Down Expand Up @@ -198,3 +207,25 @@ function getSuitesToRun(suites: string[], root: string) {
}
return suitesToRun
}

async function checkRelease(commit: string) {
return new Promise((resolve, reject) => {
const req = https.request(
{
method: 'GET',
hostname: 'pkg.pr.new',
path: `/vuejs/core/vue@${commit}`,
},
(res) => {
if (res.statusCode === 200) {
resolve(true)
} else {
resolve(false)
}
req.destroy()
},
)
req.on('error', reject)
req.end()
})
}

0 comments on commit 927aff5

Please sign in to comment.