]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: check if commit is up-to-date with remote before release
authorEvan You <yyx990803@gmail.com>
Fri, 20 Oct 2023 02:16:45 +0000 (10:16 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 20 Oct 2023 02:16:45 +0000 (10:16 +0800)
scripts/release.js

index 2c653a4f7d6f9a358a498883700e65b64c36a8f4..8d91419919b7508c85c1bd1b3d4f6b6a27d9d1dd 100644 (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
   }
 }