From: Evan You Date: Fri, 20 Oct 2023 02:16:45 +0000 (+0800) Subject: chore: check if commit is up-to-date with remote before release X-Git-Tag: v3.3.5~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f23d951f90033c86d9dd3288db02448ca06ef04b;p=thirdparty%2Fvuejs%2Fcore.git chore: check if commit is up-to-date with remote before release --- diff --git a/scripts/release.js b/scripts/release.js index 2c653a4f7d..8d91419919 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 } }