Skip to content
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

Stacks: run cli arguments #4005

Merged
merged 32 commits into from
Mar 12, 2025
Merged

Stacks: run cli arguments #4005

merged 32 commits into from
Mar 12, 2025

Conversation

denis256
Copy link
Member

@denis256 denis256 commented Mar 12, 2025

Description

  • Improved handling of CLI arguments for run command
  • Added integration tests to track strict stack inclusion

TODOs

Read the Gruntwork contribution guidelines.

  • Update the docs.
  • Run the relevant tests successfully, including pre-commit checks.
  • Ensure any 3rd party code adheres with our license policy or delete this line if its not applicable.
  • Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added / Removed / Updated [X].

Migration Guide

Summary by CodeRabbit

  • New Features

    • Enhanced the stack command’s configuration options, allowing users more precise control over module selection during operations.
  • Tests

    • Added an integration test to validate the updated behavior under strict inclusion parameters, ensuring reliable and expected stack operations.

Copy link

vercel bot commented Mar 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
terragrunt-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 12, 2025 9:35pm

Copy link
Contributor

coderabbitai bot commented Mar 12, 2025

📝 Walkthrough

Walkthrough

This pull request adds new functionality to the stack command. In the CLI command file, new imports and a helper function (runFlags) are introduced to combine flags for the run and runall subcommands, and the NewCommand function is updated to use these flags. Additionally, a new integration test is added to verify the stack apply behavior under strict inclusion parameters, ensuring that only the specified module is included in the process.

Changes

File Path Change Summary
cli/commands/stack/command.go Added imports for runall and run, introduced the new helper function runFlags to combine and filter flags, and updated NewCommand to incorporate a flags field for the runCommandName subcommand.
test/integration_stacks_test.go Introduced a new test function TestStackApplyStrictInclude to validate that the stack apply command behaves correctly when strict inclusion flags are used, ensuring proper module selection and absence of unintended outputs.

Sequence Diagram(s)

sequenceDiagram
    participant U as User Input
    participant NC as NewCommand
    participant RF as runFlags
    participant CMD as CLI Command

    U->>NC: Invoke command creation
    NC->>RF: Generate flags (combining run & runall)
    RF-->>NC: Return combined flags
    NC->>CMD: Configure command with flags
Loading
sequenceDiagram
    participant T as Integration Test
    participant TG as Stack Generator
    participant TS as Stack Runner

    T->>TG: Clean up and set up environment
    T->>TG: Execute "terragrunt stack generate"
    TG-->>T: Return generated stack
    T->>TS: Run "terragrunt stack run apply" with strict inclusion flags
    TS-->>T: Return execution output for verification
Loading

Possibly related PRs

Suggested reviewers

  • levkohimins
  • yhakbar

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@denis256 denis256 changed the title Stacks: tests improvements Stacks: run cli arguments Mar 12, 2025
@denis256 denis256 marked this pull request as ready for review March 12, 2025 20:08
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
cli/commands/stack/command.go (1)

110-115: Well-structured function for combining flags from run and runall commands.

The runFlags function efficiently combines flags from both commands while filtering out potentially conflicting output directory flags. This approach promotes code reuse and maintains consistency across the CLI interface.

Consider adding a brief comment explaining why specific flags are filtered out to improve maintainability for future developers.

 func runFlags(opts *options.TerragruntOptions) cli.Flags {
+  // Combine flags from runall and run commands, filtering out output directory flags
+  // that would conflict with stack command functionality
   flags := runall.NewFlags(opts, runCommandName, nil).Filter(runall.OutDirFlagName, runall.JSONOutDirFlagName)
   flags = append(flags, run.NewFlags(opts, nil)...)

   return flags
 }
test/integration_stacks_test.go (1)

695-714: Good integration test for the strict inclusion functionality.

This test effectively verifies that the --queue-strict-include and --queue-include-dir flags work correctly with the stack command by:

  1. Only running the command on the specified directory (./.terragrunt-stack/app1)
  2. Verifying other modules are not processed
  3. Confirming that dependencies aren't automatically included

The test methodology follows the established patterns in the codebase with proper setup, execution, and assertion steps.

Consider adding a descriptive comment at the beginning of the test function explaining the purpose of testing strict inclusion behavior:

 func TestStackApplyStrictInclude(t *testing.T) {
+  // Test that stack run apply with --queue-strict-include flag only processes
+  // explicitly included directories and doesn't process dependencies
   t.Parallel()

   helpers.CleanupTerraformFolder(t, testFixtureStackDependencies)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c2527e and a3953f9.

📒 Files selected for processing (2)
  • cli/commands/stack/command.go (3 hunks)
  • test/integration_stacks_test.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code for quality and correctness. M...

**/*.go: Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.

  • cli/commands/stack/command.go
  • test/integration_stacks_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (2)
cli/commands/stack/command.go (2)

5-6: Good addition of necessary imports for integrating run and runall commands.

The imports for run and runall commands are necessary for the new functionality being added, allowing the stack command to leverage existing flags from both commands.


55-55: Good implementation of flags for the run subcommand.

Adding the flags to the run subcommand enables proper CLI argument handling, which aligns with the PR objective of enhancing CLI argument handling for the run command.

@denis256 denis256 merged commit 097da81 into main Mar 12, 2025
8 of 9 checks passed
@denis256 denis256 deleted the tg-stack-tests branch March 12, 2025 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants