chore: check if commit is up-to-date with remote before release

This commit is contained in:
Evan You 2023-10-20 10:16:45 +08:00
parent e3c2d699f6
commit f23d951f90
1 changed files with 28 additions and 0 deletions

View File

@ -79,6 +79,12 @@ const getPkgRoot = pkg => path.resolve(__dirname, '../packages/' + pkg)
const step = msg => console.log(chalk.cyan(msg))
async function main() {
if (!(await isInSyncWithRemote())) {
return
} else {
console.log(`${chalk.green(``)} commit is up-to-date with rmeote.\n`)
}
let targetVersion = args._[0]
if (isCanary) {
@ -299,6 +305,28 @@ async function getCIResult() {
const data = await res.json()
return data.workflow_runs.length > 0
} catch (e) {
console.error('Failed to get CI status for current commit.')
return false
}
}
async function isInSyncWithRemote() {
try {
const { stdout: sha } = await execa('git', ['rev-parse', 'HEAD'])
const { stdout: branch } = await execa('git', [
'rev-parse',
'--abbrev-ref',
'HEAD'
])
const res = await fetch(
`https://api.github.com/repos/vuejs/core/commits/${branch}?per_page=1`
)
const data = await res.json()
return data.sha === sha
} catch (e) {
console.error(
'Failed to check whether local HEAD is up-to-date with remote.'
)
return false
}
}