Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/promote/rollback_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import "strings"
// hotfix integration branch, tags, or release drafts exist.
const RollbackRefPrefix = "rollback/"

// RollbackRef returns the divergence ref recorded on an environment rolled back
// under component. The default (empty) component yields rollback/<env>,
// byte-identical to the historical single-component form; a named component
// yields rollback/<component>/<env> so each component's rollback divergence
// occupies a disjoint namespace, mirroring the env/<component>/<env> integration
// branch namespacing a hotfix uses.
func RollbackRef(component, env string) string {
if component == "" {
return RollbackRefPrefix + env
}
return RollbackRefPrefix + component + "/" + env
}

// IsRollbackRef reports whether ref is a rollback-divergence ref (set by a
// manual rollback) rather than a hotfix integration ref. The rejoin cleanup
// uses this to skip integration-branch and hotfix-release deletion for an env
Expand Down
5 changes: 5 additions & 0 deletions internal/rollback/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func NewCommand() *cobra.Command {
env string
to string
deployable string
component string
actor string
dryRun bool
jsonOutput bool
Expand Down Expand Up @@ -62,6 +63,7 @@ Examples:
env: env,
to: to,
deployable: deployable,
component: component,
actor: actor,
dryRun: dryRun,
jsonOutput: jsonOutput,
Expand All @@ -74,6 +76,7 @@ Examples:
cmd.Flags().StringVar(&env, "env", "", "Target environment to roll back (required)")
cmd.Flags().StringVar(&to, "to", "", "Prior version or SHA to re-promote (optional; defaults to the previous version)")
cmd.Flags().StringVar(&deployable, "deployable", "", "Scope the rollback to a single deployable")
cmd.Flags().StringVar(&component, "component", "", "Scope the rollback to a declared component (reads and records state.components.<component>.<env>)")
cmd.Flags().StringVar(&actor, "actor", "", "Actor recorded on the rollback (default: $GITHUB_ACTOR)")
cmd.Flags().BoolVar(&dryRun, "dry-run", false, "Resolve and print the plan without modifying the manifest")
cmd.Flags().BoolVar(&jsonOutput, "json", false, "Output the resolved plan as JSON")
Expand All @@ -96,6 +99,7 @@ type runOptions struct {
env string
to string
deployable string
component string
actor string
dryRun bool
jsonOutput bool
Expand All @@ -106,6 +110,7 @@ func run(opts runOptions) error {
ConfigPath: opts.configPath,
ManifestKey: opts.manifestKey,
Actor: opts.actor,
Component: opts.component,
})
if err != nil {
return err
Expand Down
12 changes: 11 additions & 1 deletion internal/rollback/command_subcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func newPreflightCommand() *cobra.Command {
env string
to string
deployable string
component string
ghaOutput bool
jsonOutput bool
)
Expand All @@ -46,6 +47,7 @@ target_version, and can_proceed to $GITHUB_OUTPUT. It writes no manifest state.`
env: env,
to: to,
deployable: deployable,
component: component,
ghaOutput: ghaOutput,
jsonOutput: jsonOutput,
})
Expand All @@ -57,6 +59,7 @@ target_version, and can_proceed to $GITHUB_OUTPUT. It writes no manifest state.`
cmd.Flags().StringVar(&env, "env", "", "Target environment to roll back (required)")
cmd.Flags().StringVar(&to, "to", "", "Prior version or SHA to re-promote (optional; defaults to the previous version)")
cmd.Flags().StringVar(&deployable, "deployable", "", "Scope the rollback to a single deployable")
cmd.Flags().StringVar(&component, "component", "", "Scope the rollback to a declared component")
cmd.Flags().BoolVar(&ghaOutput, "gha-output", false, "Write resolved target to $GITHUB_OUTPUT")
cmd.Flags().BoolVar(&jsonOutput, "json", false, "Print the resolved plan as JSON")

Expand All @@ -71,6 +74,7 @@ type preflightOptions struct {
env string
to string
deployable string
component string
ghaOutput bool
jsonOutput bool
}
Expand All @@ -79,6 +83,7 @@ func runPreflight(opts preflightOptions) error {
rb, err := New(Options{
ConfigPath: opts.configPath,
ManifestKey: opts.manifestKey,
Component: opts.component,
})
if err != nil {
if opts.ghaOutput {
Expand Down Expand Up @@ -136,6 +141,7 @@ func newFinalizeCommand() *cobra.Command {
env string
to string
deployable string
component string
actor string
commitPush bool
)
Expand All @@ -156,6 +162,7 @@ promotion guards treat it as off-trunk until a promotion rejoins it), and, with
env: env,
to: to,
deployable: deployable,
component: component,
actor: actor,
commitPush: commitPush,
})
Expand All @@ -167,6 +174,7 @@ promotion guards treat it as off-trunk until a promotion rejoins it), and, with
cmd.Flags().StringVar(&env, "env", "", "Target environment to roll back (required)")
cmd.Flags().StringVar(&to, "to", "", "Prior version or SHA to re-promote (optional; defaults to the previous version)")
cmd.Flags().StringVar(&deployable, "deployable", "", "Scope the rollback to a single deployable")
cmd.Flags().StringVar(&component, "component", "", "Scope the rollback to a declared component")
cmd.Flags().StringVar(&actor, "actor", "", "Actor recorded on the rollback (default: $GITHUB_ACTOR)")
cmd.Flags().BoolVar(&commitPush, "commit-push", false, "Commit and push the updated manifest to the trunk branch")

Expand All @@ -181,6 +189,7 @@ type finalizeOptions struct {
env string
to string
deployable string
component string
actor string
commitPush bool
}
Expand All @@ -190,6 +199,7 @@ func runFinalize(opts finalizeOptions) error {
ConfigPath: opts.configPath,
ManifestKey: opts.manifestKey,
Actor: opts.actor,
Component: opts.component,
})
if err != nil {
return err
Expand All @@ -214,7 +224,7 @@ func runFinalize(opts finalizeOptions) error {
}

if opts.commitPush {
if err := commitAndPush(rb.ConfigPath(), plan.Environment, rb.GitIdentity()); err != nil {
if err := rb.CommitAndPush(); err != nil {
return fmt.Errorf("failed to commit and push: %w", err)
}
fmt.Printf("State updated and committed for %s\n", plan.Environment)
Expand Down
Loading