Skip to content

Commit 637047e

Browse files
committed
git commit exits 1 when nothing is staged; skip it so a no-op doesn't abort before the tag/push
1 parent e905a8c commit 637047e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

script/publish

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,27 @@ async function runFile(cmd, args, exitOnError = true) {
8787
}
8888
}
8989

90+
async function commit(message) {
91+
const nothingStaged = await new Promise((resolve) =>
92+
exec('git diff --cached --quiet', (err) => resolve(!err)))
93+
if (nothingStaged) {
94+
console.log(`Nothing staged, skipping commit: ${message}`)
95+
return
96+
}
97+
await run(`git commit -m "${message}"`)
98+
}
99+
90100
async function publish(version) {
91101
packageJson.version = version
92102
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2) + '\n')
93103

94104
await run('git add package.json')
95-
await run(`git commit -m "Bump version to ${version}"`)
105+
await commit(`Bump version to ${version}`)
96106

97107
if (fs.existsSync(path.join(process.cwd(), 'script/build'))) {
98108
await run('script/build')
99109
await run('git add .')
100-
await run(`git commit -m "Build version ${version}"`)
110+
await commit(`Build version ${version}`)
101111
}
102112

103113
await run(`git tag v${version}`)

0 commit comments

Comments
 (0)