Improve CI support in hub push commands via --fail-if-exists and bump command#2672
Open
willosborne wants to merge 2 commits into
Open
Improve CI support in hub push commands via --fail-if-exists and bump command#2672willosborne wants to merge 2 commits into
willosborne wants to merge 2 commits into
Conversation
Adds a --fail-if-exists flag to all five hub push subcommands (architecture, pattern, standard, control-requirement, control-configuration). When set, the push skips the version lookup and auto-bump entirely, pushing the exact version found in the document's $id. If that version already exists on the hub the server returns 409, which the existing error handler surfaces as a fatal error. Intended for CI pipelines where the version in $id is the source of truth and any bump should have happened before commit.
Adds calm hub bump <resource> <file> with five subcommands (architecture, pattern, standard, control-requirement, control-configuration). The command reads the document's $id, checks whether that exact version already exists on the hub, and if so bumps the version in $id on disk by the requested change type (patch/minor/major) without pushing. If the version is not yet published the command exits cleanly with a no-op message. Pairs with --fail-if-exists on hub push: developers run hub bump before committing so CI can push the exact committed version and fail fast if it already exists.
52126bb to
42e0d47
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the CALM CLI’s Hub commands to better support CI workflows by allowing deterministic pushes (no auto-bump) and by adding a local “bump on disk” workflow to avoid version collisions before pushing.
Changes:
- Add
--fail-if-existsto Hub push commands to push the exact$idversion and fail on conflicts (rather than auto-bumping). - Add new
hub bump ...subcommands to bump$idversions on disk when the current version already exists on the Hub. - Add Vitest coverage for
--fail-if-existsbehavior and bump flows.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
cli/src/command-helpers/hub-commands.ts |
Adds failIfExists handling for push flows and introduces bump orchestration for mapped resources + control docs. |
cli/src/command-helpers/hub-commands.spec.ts |
Adds tests for --fail-if-exists and bump behavior. |
cli/src/cli.ts |
Wires new flags and hub bump subcommands into the CLI command tree. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+788
to
+800
| const existingVersions = await client.getMappedResourceVersions(metadata.namespace, metadata.mapping, resourceType); | ||
|
|
||
| if (!existingVersions.includes(metadata.version)) { | ||
| printJsonSuccess({ file: options.file, currentVersion: metadata.version, bumped: false, message: 'Version not yet published to hub; no bump needed.' }); | ||
| return; | ||
| } | ||
|
|
||
| const newVersion = computeSemVerBump(metadata.version, options.changeType); | ||
| const newMetadata = { ...metadata, version: newVersion }; | ||
| const newContent = updateDocumentMetadata(fileContent, newMetadata); | ||
| await writeFile(options.file, newContent, 'utf-8'); | ||
|
|
||
| printBumpResult({ file: options.file, previousVersion: metadata.version, newVersion }, format); |
Comment on lines
+845
to
+859
| const existingVersions = kind === 'configuration' | ||
| ? await client.getControlConfigurationVersions(metadata.domain, metadata.controlName, metadata.configName!) | ||
| : await client.getControlRequirementVersions(metadata.domain, metadata.controlName); | ||
|
|
||
| if (!existingVersions.includes(metadata.version)) { | ||
| printJsonSuccess({ file: options.file, currentVersion: metadata.version, bumped: false, message: 'Version not yet published to hub; no bump needed.' }); | ||
| return; | ||
| } | ||
|
|
||
| const newVersion = computeSemVerBump(metadata.version, options.changeType); | ||
| const newMetadata: ControlDocumentMetadata = { ...metadata, version: newVersion }; | ||
| const newContent = updateControlDocumentMetadata(fileContent, newMetadata); | ||
| await writeFile(options.file, newContent, 'utf-8'); | ||
|
|
||
| printBumpResult({ file: options.file, previousVersion: metadata.version, newVersion }, format); |
| expect.objectContaining({ file: 'arch.json', previousVersion: '1.0.0', newVersion: '1.0.1' }) | ||
| ); | ||
| }); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Type of Change
Affected Components
cli/)calm/)calm-ai/)calm-hub/)calm-hub-ui/)calm-server/)calm-widgets/)docs/)shared/)calm-plugins/vscode/)Commit Message Format ✅
Testing
Checklist