-
-
Notifications
You must be signed in to change notification settings - Fork 135
Add vendor update and diff commands #1694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
osterman
wants to merge
22
commits into
main
Choose a base branch
from
feat/vendor-diff-and-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7,111
−738
Open
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9b57ef4
Add vendor update and diff commands
osterman 058a3ec
Add version constraints support for vendor updates
osterman 22b89d6
Update vendor diff documentation to reflect GitHub-only implementation
osterman c8b4f89
Add vendor source provider interface for multi-provider support
osterman 54c8fa6
Fix code quality and documentation issues per review
osterman 9bc2952
docs: Add comprehensive version constraints documentation
osterman 79e8ab8
docs: Add blog post for vendor update and diff feature
osterman 92ea64c
docs: Strengthen blog post messaging on update debt and shared respon…
osterman 4064d98
Merge main into feat/vendor-diff-and-update
osterman af9f14a
[autofix.ci] apply automated fixes
autofix-ci[bot] bb1ff4b
fix: Add performance tracking and update deprecated imports
osterman 84c89fa
[autofix.ci] apply automated fixes
autofix-ci[bot] 9fcde50
Merge origin/main into feat/vendor-diff-and-update
osterman 4d8ce52
refactor: Move vendor commands to cmd/vendor/ and logic to pkg/vendor…
osterman 280d390
fix: Address CodeRabbit review comments for vendor commands
osterman 76bdbf4
refactor: Split pkg/vendoring into source/ and version/ subpackages
osterman ccb5be3
Merge remote-tracking branch 'origin/main' into feat/vendor-diff-and-…
osterman a01f0d2
fix: Address CodeRabbit review comments for GitHub provider
osterman 16adbc8
Merge remote-tracking branch 'origin/main' into feat/vendor-diff-and-…
osterman 00eab04
Merge origin/main into feat/vendor-diff-and-update
osterman 6002313
Merge origin/main into feat/vendor-diff-and-update
osterman 22134ca
fix: Address CodeRabbit PR review comments
osterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| package vendor | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
|
|
||
| errUtils "github.com/cloudposse/atmos/errors" | ||
| "github.com/cloudposse/atmos/pkg/flags" | ||
| "github.com/cloudposse/atmos/pkg/flags/global" | ||
| "github.com/cloudposse/atmos/pkg/perf" | ||
| "github.com/cloudposse/atmos/pkg/schema" | ||
| vendor "github.com/cloudposse/atmos/pkg/vendoring" | ||
| ) | ||
|
|
||
| // DiffOptions contains all options for vendor diff command. | ||
| type DiffOptions struct { | ||
| global.Flags // Embedded global flags (chdir, logs-level, etc.). | ||
| AtmosConfig *schema.AtmosConfiguration // Populated after config init. | ||
| Component string // --component, -c (required). | ||
| ComponentType string // --type, -t (default: "terraform"). | ||
| From string // --from (source version/ref). | ||
| To string // --to (target version/ref). | ||
| File string // --file (specific file to diff). | ||
| Context int // --context (lines of context, default: 3). | ||
| Unified bool // --unified (unified diff format, default: true). | ||
| } | ||
|
|
||
| // SetAtmosConfig implements AtmosConfigSetter for DiffOptions. | ||
| func (o *DiffOptions) SetAtmosConfig(cfg *schema.AtmosConfiguration) { | ||
| o.AtmosConfig = cfg | ||
| } | ||
|
|
||
| // Validate checks that diff options are consistent. | ||
| func (o *DiffOptions) Validate() error { | ||
| defer perf.Track(nil, "vendor.DiffOptions.Validate")() | ||
|
|
||
| if o.Component == "" { | ||
| return errUtils.ErrComponentFlagRequired | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| var diffParser *flags.StandardParser | ||
|
|
||
| var diffCmd = &cobra.Command{ | ||
| Use: "diff", | ||
| Short: "Show differences between vendor component versions", | ||
| Long: "Compare vendor component versions and display the differences between the current version and a target version or between two specified versions.", | ||
| FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false}, | ||
| Args: cobra.NoArgs, | ||
| RunE: runDiff, | ||
| } | ||
|
|
||
| func init() { | ||
| // Create parser with all diff-specific flags. | ||
| diffParser = flags.NewStandardParser( | ||
| // String flags. | ||
| flags.WithStringFlag("component", "c", "", "Component to diff (required)"), | ||
| flags.WithStringFlag("type", "t", "terraform", "Component type (terraform or helmfile)"), | ||
| flags.WithStringFlag("from", "", "", "Source version/ref to compare from (default: current version)"), | ||
| flags.WithStringFlag("to", "", "", "Target version/ref to compare to (default: latest)"), | ||
| flags.WithStringFlag("file", "", "", "Specific file to diff within the component"), | ||
|
|
||
| // Int flags. | ||
| flags.WithIntFlag("context", "", 3, "Number of context lines to show in diff"), | ||
|
|
||
| // Bool flags. | ||
| flags.WithBoolFlag("unified", "", true, "Use unified diff format"), | ||
|
|
||
| // Environment variable bindings. | ||
| flags.WithEnvVars("component", "ATMOS_VENDOR_COMPONENT"), | ||
| flags.WithEnvVars("type", "ATMOS_VENDOR_TYPE"), | ||
| flags.WithEnvVars("from", "ATMOS_VENDOR_FROM"), | ||
| flags.WithEnvVars("to", "ATMOS_VENDOR_TO"), | ||
| flags.WithEnvVars("context", "ATMOS_VENDOR_CONTEXT"), | ||
| ) | ||
|
|
||
| // Register flags with cobra command. | ||
| diffParser.RegisterFlags(diffCmd) | ||
|
|
||
| // Shell completions. | ||
| _ = diffCmd.RegisterFlagCompletionFunc("component", componentsArgCompletion) | ||
| } | ||
|
|
||
| func runDiff(cmd *cobra.Command, args []string) error { | ||
| defer perf.Track(nil, "vendor.runDiff")() | ||
|
|
||
| // Parse options with Viper precedence (CLI > ENV > config). | ||
| opts, err := parseDiffOptions(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Validate options. | ||
| if err := opts.Validate(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Initialize Atmos config. | ||
| // Vendor diff doesn't use stack flag, so skip stack validation. | ||
| if err := initAtmosConfig(opts, true); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Execute via pkg/vendoring. | ||
| return vendor.Diff(opts.AtmosConfig, &vendor.DiffParams{ | ||
| Component: opts.Component, | ||
| ComponentType: opts.ComponentType, | ||
| From: opts.From, | ||
| To: opts.To, | ||
| File: opts.File, | ||
| Context: opts.Context, | ||
| Unified: opts.Unified, | ||
| NoColor: false, // This would come from global flags if needed. | ||
| }) | ||
| } | ||
|
|
||
| func parseDiffOptions(cmd *cobra.Command) (*DiffOptions, error) { | ||
| defer perf.Track(nil, "vendor.parseDiffOptions")() | ||
|
|
||
| v := viper.GetViper() | ||
| if err := diffParser.BindFlagsToViper(cmd, v); err != nil { | ||
| return nil, fmt.Errorf("%w: %w", errUtils.ErrParseFlag, err) | ||
| } | ||
|
|
||
| return &DiffOptions{ | ||
| // global.Flags embedded - would be populated from root persistent flags. | ||
| Component: v.GetString(flagComponent), | ||
| ComponentType: v.GetString(flagType), | ||
| From: v.GetString("from"), | ||
| To: v.GetString("to"), | ||
| File: v.GetString("file"), | ||
| Context: v.GetInt("context"), | ||
| Unified: v.GetBool("unified"), | ||
| }, nil | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| package vendor | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/viper" | ||
|
|
||
| errUtils "github.com/cloudposse/atmos/errors" | ||
| "github.com/cloudposse/atmos/pkg/flags" | ||
| "github.com/cloudposse/atmos/pkg/flags/global" | ||
| "github.com/cloudposse/atmos/pkg/perf" | ||
| "github.com/cloudposse/atmos/pkg/schema" | ||
| vendor "github.com/cloudposse/atmos/pkg/vendoring" | ||
| ) | ||
|
|
||
| // PullOptions contains all options for vendor pull command. | ||
| type PullOptions struct { | ||
| global.Flags // Embedded global flags (chdir, logs-level, etc.). | ||
| AtmosConfig *schema.AtmosConfiguration // Populated after config init. | ||
| Component string // --component, -c. | ||
| Stack string // --stack, -s. | ||
| ComponentType string // --type, -t (default: "terraform"). | ||
| Tags string // --tags (comma-separated). | ||
| DryRun bool // --dry-run. | ||
| Everything bool // --everything. | ||
| } | ||
|
|
||
| // SetAtmosConfig implements AtmosConfigSetter for PullOptions. | ||
| func (o *PullOptions) SetAtmosConfig(cfg *schema.AtmosConfiguration) { | ||
| o.AtmosConfig = cfg | ||
| } | ||
|
|
||
| // Validate checks that pull options are consistent. | ||
| func (o *PullOptions) Validate() error { | ||
| defer perf.Track(nil, "vendor.PullOptions.Validate")() | ||
|
|
||
| if o.Component != "" && o.Stack != "" { | ||
| return fmt.Errorf("%w: --component and --stack cannot be used together", errUtils.ErrMutuallyExclusiveFlags) | ||
| } | ||
| if o.Component != "" && o.Tags != "" { | ||
| return fmt.Errorf("%w: --component and --tags cannot be used together", errUtils.ErrMutuallyExclusiveFlags) | ||
| } | ||
| if o.Everything && (o.Component != "" || o.Stack != "" || o.Tags != "") { | ||
| return fmt.Errorf("%w: --everything cannot be combined with --component, --stack, or --tags", errUtils.ErrMutuallyExclusiveFlags) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| var pullParser *flags.StandardParser | ||
|
|
||
| var pullCmd = &cobra.Command{ | ||
| Use: "pull", | ||
| Short: "Pull the latest vendor configurations or dependencies", | ||
| Long: "Pull and update vendor-specific configurations or dependencies to ensure the project has the latest required resources.", | ||
| FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false}, | ||
| Args: cobra.NoArgs, | ||
| RunE: runPull, | ||
| } | ||
|
|
||
| func init() { | ||
| // Create parser with all pull-specific flags. | ||
| pullParser = flags.NewStandardParser( | ||
| // String flags. | ||
| flags.WithStringFlag("component", "c", "", "Only vendor the specified component"), | ||
| flags.WithStringFlag("stack", "s", "", "Only vendor the specified stack"), | ||
| flags.WithStringFlag("type", "t", "terraform", "Component type (terraform or helmfile)"), | ||
| flags.WithStringFlag("tags", "", "", "Only vendor components with specified tags (comma-separated)"), | ||
|
|
||
| // Bool flags. | ||
| flags.WithBoolFlag("dry-run", "", false, "Simulate without making changes"), | ||
| flags.WithBoolFlag("everything", "", false, "Vendor all components"), | ||
|
|
||
| // Environment variable bindings. | ||
| flags.WithEnvVars("component", "ATMOS_VENDOR_COMPONENT"), | ||
| flags.WithEnvVars("stack", "ATMOS_VENDOR_STACK", "ATMOS_STACK"), | ||
| flags.WithEnvVars("type", "ATMOS_VENDOR_TYPE"), | ||
| flags.WithEnvVars("tags", "ATMOS_VENDOR_TAGS"), | ||
| flags.WithEnvVars("dry-run", "ATMOS_VENDOR_DRY_RUN"), | ||
| ) | ||
|
|
||
| // Register flags with cobra command. | ||
| pullParser.RegisterFlags(pullCmd) | ||
|
|
||
| // Shell completions. | ||
| _ = pullCmd.RegisterFlagCompletionFunc("component", componentsArgCompletion) | ||
| addStackCompletion(pullCmd) | ||
| } | ||
|
|
||
| func runPull(cmd *cobra.Command, args []string) error { | ||
| defer perf.Track(nil, "vendor.runPull")() | ||
|
|
||
| // Parse options with Viper precedence (CLI > ENV > config). | ||
| opts, err := parsePullOptions(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Validate options. | ||
| if err := opts.Validate(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Initialize Atmos config. | ||
| skipStackValidation := opts.Stack == "" | ||
| if err := initAtmosConfig(opts, skipStackValidation); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Execute via pkg/vendoring. | ||
| return vendor.Pull(opts.AtmosConfig, &vendor.PullParams{ | ||
| Component: opts.Component, | ||
| Stack: opts.Stack, | ||
| ComponentType: opts.ComponentType, | ||
| DryRun: opts.DryRun, | ||
| Tags: opts.Tags, | ||
| Everything: opts.Everything, | ||
| }) | ||
| } | ||
|
|
||
| func parsePullOptions(cmd *cobra.Command) (*PullOptions, error) { | ||
| defer perf.Track(nil, "vendor.parsePullOptions")() | ||
|
|
||
| v := viper.GetViper() | ||
| if err := pullParser.BindFlagsToViper(cmd, v); err != nil { | ||
| return nil, fmt.Errorf("%w: %w", errUtils.ErrParseFlag, err) | ||
| } | ||
|
|
||
| return &PullOptions{ | ||
| // global.Flags embedded - would be populated from root persistent flags. | ||
| Component: v.GetString(flagComponent), | ||
| Stack: v.GetString("stack"), | ||
| ComponentType: v.GetString(flagType), | ||
| Tags: v.GetString("tags"), | ||
| DryRun: v.GetBool("dry-run"), | ||
| Everything: v.GetBool("everything"), | ||
| }, nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.