8000 Always template vendor source and targets by mss · Pull Request #712 · cloudposse/atmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Always template vendor source and targets #712

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

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

mss
Copy link
Contributor
@mss mss commented Oct 8, 2024

what

This change improves the templating within vendor manifests slightly: It officially adds support for the Component field to both source and targets.

These features were already supported but mostly undocumented and hidden behind an implicit switch: The templating was only triggered if the Version field was set. Which was also the only officially supported field.

In reality though all fields from the current source definition were available but in the state they were currently in, depending on the order of the templates.

With this change

  • It is clearly documented which fields are supported in which YAML values.
  • Only the two static fields are supported.
  • The values are always templated.

Theoretically this could be a breaking change if somebody used no version field but curly braces in their paths. Or relied on the half-populated source data structure to refer to unsupported fields. If xkcd 1172 applies it should be possible to amend this logic to add more officially supported fields.

why

I was looking for a way to restructure our vendoring like the examples in examples/demo-vendoring/vendor.yaml to avoid copy and paste errors when we release new component versions.

I actually only found out about that demo when I was done writing this code since the templating was never triggered without a version field and the documentation didn't mention it.

references

Summary by CodeRabbit

  • New Features

    • Enhanced vendoring configuration with support for dynamic component referencing in vendor.yaml.
    • Improved handling of source and targets attributes for better organization and flexibility.
  • Documentation

    • Updated documentation for vendoring configuration, including clearer instructions and examples for managing multiple vendor manifests.
    • Added explanations for included_paths and excluded_paths attributes to improve understanding.

@mss mss requested review from a team as code owners October 8, 2024 12:20
@mss mss requested review from johncblandii and nitrocode October 8, 2024 12:20
This change improves the templating within vendor manifests slightly: It
officially adds support for the `Component` field to both `source` and
`targets`.

These features were already supported but mostly undocumented and hidden
behind an implicit switch: The templating was only triggered if the `Version`
field was set. Which was also the only officially supported field.

In reality though all fields from the current source definition were
available but in the state they were currently in, depending on the
order of the templates.

With this change
 * It is clearly documented which fields are supported in which YAML
   values.
 * Only the two static fields are supported.
 * The values are always templated.

Theoretically this could be a breaking change if somebody used no
`version` field but curly braces in their paths. Or relied on the
half-populated source data structure to refer to unsupported fields.
If xkcd 1172 applies it should be possible to amend this logic to add
more officially supported fields.
@mss mss force-pushed the feature/vendor-templating branch from e1fd706 to 270fdd8 Compare October 8, 2024 12:28
@mcalhoun
Copy link
Member

@coderabbitai full review

Copy link
Contributor
coderabbitai bot commented Oct 11, 2024
✅ Actions performed

Full review triggered.

Copy link
Contributor
coderabbitai bot commented Oct 11, 2024
📝 Walkthrough

Walkthrough

The changes involve enhancements to the handling of vendor sources and targets in the internal/exec/vendor_utils.go file, including the introduction of a new tmplData struct for improved URI and target parsing. Additionally, updates to the website/docs/core-concepts/vendor/vendor-manifest.mdx file clarify the vendor.yaml manifest structure, allowing for dynamic component referencing and improved documentation on vendoring practices.

Changes

File Path Change Summary
internal/exec/vendor_utils.go Introduced tmplData struct for component/version encapsulation; simplified URI processing; adjusted logic for uri and target construction; retained error handling for missing specifications.
website/docs/core-concepts/vendor/vendor-manifest.mdx Enhanced vendor.yaml structure to support Golang templates for source and targets; added {{.Component}} template variable; clarified usage of imports, included_paths, and excluded_paths; refined examples for better maintainability.

Poem

In the garden where vendors bloom,
A struct was born to clear the gloom.
With templates dancing, paths align,
Components sing in perfect rhyme.
Oh, joyous code, so neat and bright,
In every change, we find delight! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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: 4

🧹 Outside diff range comments (2)
website/docs/core-concepts/vendor/vendor-manifest.mdx (2)

Line range hint 201-213: Excellent enhancement to templating documentation!

The addition of detailed explanations for Go templates and Sprig Functions, along with the advanced example, significantly improves the documentation. This aligns perfectly with the PR objectives of clarifying supported fields and enhancing templating capabilities.

To further improve user understanding, consider adding a brief explanation of what the advanced example does. For instance, you could add a comment like:

targets:
  # Vendor a component into a major-minor versioned folder (e.g., "1.2" for version "1.2.3")
  - "components/terraform/infra/vpc-flow-logs-bucket/{{ (first 2 (splitList \".\" .Version)) | join \".\" }}"

This would help users quickly grasp the purpose of this complex templating example.


Line range hint 1-524: Consider adding a note about potential breaking changes

The documentation updates are comprehensive and well-explained. However, to fully align with the PR objectives and ensure a smooth transition for users, consider adding a note about potential breaking changes.

Suggest adding a callout or warning section that mentions:

  1. This change could potentially break existing configurations that relied on the absence of a 'version' field.
  2. Configurations using unsupported fields in their paths may need to be updated.

This addition would help users anticipate and address any issues when updating to the new version, aligning with the PR's goal of clear communication about the changes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between fecba15 and 531fae9.

📒 Files selected for processing (2)
  • internal/exec/vendor_utils.go (2 hunks)
  • website/docs/core-concepts/vendor/vendor-manifest.mdx (3 hunks)
🧰 Additional context used
🪛 LanguageTool
website/docs/core-concepts/vendor/vendor-manifest.mdx

[style] ~96-~96: To make your text as clear as possible to all readers, do not use this foreign term. Possible alternatives are “below” or “further on” (in a document).
Context: ...argets: - "components/terraform/infra/{{.Component}}/{{.Version}}" excl...

(INFRA)

🔇 Additional comments (2)
website/docs/core-concepts/vendor/vendor-manifest.mdx (1)

Line range hint 1-524: Excellent documentation updates aligned with PR objectives

The changes throughout this file consistently support the PR objectives:

  1. Enhanced templating capabilities are clearly explained, including support for '{{.Component}}' and '{{.Version}}' in both 'source' and 'targets' fields.
  2. The documentation now provides better visibility of existing features, addressing the author's initial difficulty in finding relevant examples.
  3. The additions clarify which fields are supported in the YAML values, improving overall user understanding.

These updates significantly enhance the documentation's clarity and usefulness, making it easier for users to understand and implement the vendoring features in Atmos.

internal/exec/vendor_utils.go (1)

285-289: LGTM!

The tmplData struct is correctly initialized with s.Component and s.Version.

@aknysh aknysh added the minor New features that do not break anything label Oct 14, 2024
Copy link
Member
@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @mss

@aknysh aknysh merged commit 94e0226 into cloudposse:main Oct 14, 2024
23 of 24 checks passed
Copy link

These changes were released in v1.90.0.

@osterman
Copy link
Member
osterman commented Oct 14, 2024

@mss can you join us in SweetOps slack in #atmos? I think thi 8000 s might have broken something. @jamengual reported an issue.

slack.cloudposse.com

@jamengual
Copy link
Contributor
jamengual commented Oct 14, 2024

@mss can you join us in SweetOps slack in #atmos? I think this might have broken something. @jamengual reported an issue.

slack.cloudposse.com

the {{`{{ ... }}`}} did the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants
0