From f23d951f90033c86d9dd3288db02448ca06ef04b Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 20 Oct 2023 10:16:45 +0800 Subject: [PATCH] chore: check if commit is up-to-date with remote before release --- scripts/release.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/scripts/release.js b/scripts/release.js index 2c653a4f7..8d9141991 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -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 } }