fix(release): make publish-version.mjs idempotent for re-runs
Skip the peer-dep commit when nothing is staged and skip the lerna version step when the workspace is already at the target version. Allows the release pipeline to be re-triggered after a partial run.
This commit is contained in:
parent
3fc8706126
commit
647fd025cf
@ -62,12 +62,22 @@ async function run() {
|
|||||||
|
|
||||||
console.log('Committing and pushing changes...');
|
console.log('Committing and pushing changes...');
|
||||||
await execa('git', ['add', '-A']);
|
await execa('git', ['add', '-A']);
|
||||||
|
|
||||||
|
// On re-runs after a partial release the peer-dep updates above are no-ops,
|
||||||
|
// leaving nothing staged. Skip the commit/push so the script stays idempotent.
|
||||||
|
const { stdout: stagedFiles } = await execa('git', ['diff', '--cached', '--name-only']);
|
||||||
|
if (stagedFiles.trim()) {
|
||||||
await execa('git', ['commit', '-m', 'chore(version): version.json [skip ci]']);
|
await execa('git', ['commit', '-m', 'chore(version): version.json [skip ci]']);
|
||||||
await execa('git', ['push', 'origin', branchName]);
|
await execa('git', ['push', 'origin', branchName]);
|
||||||
|
} else {
|
||||||
|
console.log('No peer-dependency changes to commit, skipping');
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Setting the version using lerna...');
|
console.log('Setting the version using lerna...');
|
||||||
|
|
||||||
// add a message to the commit to indicate that the version was set using lerna
|
// Skip lerna version if package versions already match the target (e.g. a
|
||||||
|
// previous release run finished the version bump but failed before publish).
|
||||||
|
if (lernaJson.version !== nextVersion.trim()) {
|
||||||
await execa('npx', [
|
await execa('npx', [
|
||||||
'lerna',
|
'lerna',
|
||||||
'version',
|
'version',
|
||||||
@ -83,6 +93,9 @@ async function run() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
console.log('Version set using lerna');
|
console.log('Version set using lerna');
|
||||||
|
} else {
|
||||||
|
console.log(`Already at target version ${nextVersion.trim()}, skipping lerna version`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(err => {
|
run().catch(err => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user