Implement deploy rollback - #1744
Draft
gcirclest wants to merge 1 commit into
Draft
Conversation
Add `circleci deploy rollback <target-version>` over the V3 project rollback
endpoint, POST /api/v3/projects/{id}/rollback.
--component and --environment accept a name or a UUID. The endpoint addresses
both by id, so a name is resolved through the component and environment list
endpoints first; an ambiguous component name reports the candidate ids rather
than picking one.
--from (current_version) is optional. Omitted, it is read from the component's
versions filtered by the environment, which the API returns most recently
deployed first. The API re-checks it, so a stale inference fails the rollback
instead of moving the wrong version.
The response's id is the pipeline run or the release-agent command carrying the
rollback out, and rollback_type says which, so the output points at the right
place to follow it.
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.
Adds
circleci deploy rollback <target-version>over the V3 project rollback endpoint that landed in release-tracker#2219,POST /api/v3/projects/{id}/rollback. Every field of the request body is covered:namespace,reason,parameters,checkout_refandconfig_refalongside the four required ones.Design decisions worth a reviewer's attention:
--componentand--environmenttake a name or a UUID. The endpoint addresses both by id, so a name is resolved through the same component and environment list endpoints the read commands use. An ambiguous component name reports the candidate ids rather than picking one, since the wrong pick would roll back the wrong thing.--fromis optional. Omitted,current_versionis read from the component's versions filtered by the environment, which the API returns most recently deployed first. This does not weaken the endpoint's stale-state guard: the API re-checks the version, so a wrong inference fails the rollback rather than moving something unintended, and a400is reported as "rollback rejected" pointing atdeploy version list.--forceand a prompt. A rollback changes what is deployed, so it goes throughcmdutil.ConfirmOrForcelikerun cancel, with the resolved component, environment and both versions in the prompt. Non-interactive without--forceexits 6 and never sends the request.data.idis either the triggered pipeline run or the queued release-agent command;rollback_typedistinguishes them, and the two are followed in different places, so the human output names which one it is and gives therun getcommand for the pipeline case.--dry-run. The--helppage lands at exactly the 40-line budgetTestHelpenforces, and theoverBudgetallow-list is already at its 25-entry cap, so a further flag row would have meant raisingmaxOverBudget. The confirmation prompt already previews the resolved component, environment and both versions. For the same reason the target version is the positional argument rather than a--toflag paired with--from.Errors are mapped for each failure the endpoint documents:
409→ rollback already in progress (exit 4),400→ rollback rejected with the server's detail (exit 2),404→ not found with a--namespacehint (exit 5).Testing
acceptance/deploy_rollback_test.go: name resolution with an inferred--from, every optional field with the request body asserted through the recorder (including--parambool/int coercion), both rollback types,--json, missing flag and missing argument, unknown component and unknown environment, no recorded version, malformed--param,400,409, and no token. The--force-refused case also asserts the POST never left the CLI.fakes.CircleCIgrows the route plusSetRollback, withStatus/Title/Detailfor the error paths.task testpasses (2090 tests).task checkfails onmainin my environment too —golangci-lint/staticcheckcannot resolvehonnef.co/go/tools/go/irfromtools/go.mod— so it is unrelated to this branch;gofmt,go vetandtask licenseare clean and no dependencies were added.