Skip to content

Add core git YAML functions - #2537

Merged
Andriy Knysh (aknysh) merged 8 commits into
mainfrom
osterman/atmos-prod-catalog-refs
May 29, 2026
Merged

Andriy Knysh (aknysh) merged 8 commits into
mainfrom
osterman/atmos-prod-catalog-refs

Conversation

@osterman

@osterman Erik Osterman (Cloud Posse) (osterman) commented May 28, 2026 •

Copy link
Copy Markdown
Member

what

  • Add core Git YAML functions: !git.root, !git.sha, !git.branch, and !git.ref.
  • Resolve Git metadata through pkg/git, with pkg/utils limited to compatibility shims and YAML tag registration.
  • Wire Git tag resolution through config preprocessing, stack/component YAML processing, and function registry metadata.
  • Add a changelog post and roadmap milestone for the new Git YAML functions.

why

  • Allow dev stack/component source versions to pin to the current Git SHA via !git.ref.
  • Keep prod pins explicit while giving dev environments PR-aware source refs.
  • Avoid expanding pkg/utils by placing Git behavior in the self-contained Git package.

references

  • n/a

Summary by CodeRabbit

  • New Features

    • Added Git YAML tags (!git.root / !repo-root, !git.sha, !git.ref, !git.branch) to resolve repo root, commit SHA/ref, and branch in configs and stacks; !git.ref can pin source versions.
  • Refactor

    • Centralized git tag resolution for consistent behavior, alias support, unified fallbacks, and clearer error handling.
  • Tests

    • Expanded coverage for tag resolution, fallbacks, detached‑HEAD behavior, and real-repo scenarios.
  • Documentation

    • Updated blog post and roadmap with examples and usage notes.

Review Change Stack

@atmos-pro

atmos-pro Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions github-actions Bot added the size/m Medium size PR label May 28, 2026
@github-actions

github-actions Bot commented May 28, 2026 •

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Files

None

@osterman Erik Osterman (Cloud Posse) (osterman) added the minor New features that do not break anything label May 28, 2026
@github-actions

Copy link
Copy Markdown

Warning

Release Documentation Required

This PR is labeled minor or major and requires documentation updates:

  • Changelog entry - Add a blog post in website/blog/YYYY-MM-DD-feature-name.mdx
  • Roadmap update - Update website/src/data/roadmap.js with the new milestone

Alternatively: If this change doesn't require release documentation, remove the minor or major label.

@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4999bb35-b208-4629-8f1a-5edd9ea57960

📥 Commits

Reviewing files that changed from the base of the PR and between efb459e and 4362980.

📒 Files selected for processing (2)
  • pkg/utils/git.go
  • website/blog/2026-05-28-git-yaml-functions.mdx
✅ Files skipped from review due to trivial changes (1)
  • website/blog/2026-05-28-git-yaml-functions.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/utils/git.go

📝 Walkthrough

Walkthrough

Adds pkg/git metadata helpers and YAML tag processors for !git.root, !git.sha, !git.ref, and !git.branch; registers tag constants and function handlers; routes config and exec YAML dispatch to the new processors; consolidates utils; and adds tests and documentation.

Changes

Git YAML Function Tags

Layer / File(s) Summary
All changes (single review checkpoint)
pkg/git/*, pkg/function/*, pkg/config/*, pkg/utils/*, internal/exec/*, errors/errors.go, pkg/provisioner/*, website/*, various *_test.go
Introduces pkg/git YAML tag processors and helpers (GetRoot/GetCurrentCommitSHA/GetCurrentBranch); adds TagGit* constants and GitSha/GitBranch/GitRef function handlers; wires !git.* handling into config and exec YAML processing and utils; updates error sentinels; extends and adds tests and documentation.

Sequence Diagram(s)

sequenceDiagram
  participant YAMLCaller as YAML processor / Function
  participant TagProcessor as pkg/git.ProcessTag*
  participant GitHelpers as pkg/git.GetRoot/GetCurrentCommitSHA/GetCurrentBranch
  participant LocalRepo as Local Git Repository
  participant Fallback as Provided default value

  YAMLCaller->>TagProcessor: input tag string (e.g. "!git.ref <opt>")
  TagProcessor->>TagProcessor: trimTagPrefix
  TagProcessor->>GitHelpers: request requested metadata
  GitHelpers->>LocalRepo: read HEAD/worktree
  LocalRepo-->>GitHelpers: SHA / branch / root
  alt success
    GitHelpers-->>TagProcessor: resolved value
  else failure
    TagProcessor->>Fallback: extract supplied default
    Fallback-->>TagProcessor: default or empty
  end
  TagProcessor-->>YAMLCaller: resolved or fallback result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • aknysh
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Git YAML functions to the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch osterman/atmos-prod-catalog-refs

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (3)
pkg/function/git_test.go (1)

32-54: ⚡ Quick win

Add the non-fallback counterpart for this recovery-path test.

This test verifies fallback activation outside a repository, but it should also include the opposite case (git context present) to assert fallback does not trigger when normal resolution succeeds.

As per coding guidelines: “Include negative-path tests for recovery logic: whenever a test verifies that a recovery/fallback triggers under condition X, add a corresponding test verifying the recovery does NOT trigger when condition X is absent”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/function/git_test.go` around lines 32 - 54, Add a complementary test that
sets up a real git repository context and verifies the fallback does NOT run:
create a new test (or extend
TestGitFunctions_ExecuteWithFallbackOutsideRepository) that uses t.TempDir(),
initializes a git repo (git init, create a commit, set a branch/ref), then call
Execute on NewGitShaFunction, NewGitBranchFunction and NewGitRefFunction and
assert the returned values are the actual git SHA/branch/ref (not the fallback
strings like "unknown" or "detached"); use the same
Execute(context.Background(), args, nil) invocation and require.NoError
assertions to ensure normal resolution succeeds.
pkg/utils/git.go (1)

36-37: ⚡ Quick win

Refresh the ProcessTagGitRoot comment to match the implementation.

The comment says this uses go-git directly, but the function now delegates to atmosGit.ProcessTagRoot.

📝 Suggested comment fix
-// ProcessTagGitRoot returns the root directory of the Git repository using go-git.
+// ProcessTagGitRoot returns the root directory of the current Git repository.

As per coding guidelines: "Never delete existing comments without a very strong reason; preserve helpful comments explaining why/how/what/where, and update comments to match code when refactoring."

Also applies to: 46-46

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/utils/git.go` around lines 36 - 37, Update the doc comment for
ProcessTagGitRoot to accurately describe its current behavior: instead of
claiming it uses go-git directly, state that it delegates to
atmosGit.ProcessTagRoot to obtain the repository root (and mention any relevant
behavior such as input handling or error conditions inherited from
atmosGit.ProcessTagRoot); do the same for the related comment at line 46 so
comments reflect the refactor and delegation rather than the old implementation
details.
pkg/config/process_yaml.go (1)

332-337: ⚡ Quick win

Update scalar-tag docs to include the new git tags.

The dispatch now supports !git.root alias, !git.sha/!git.ref, and !git.branch, but the function docs still describe the old tag set.

📝 Suggested doc update
-// It supports the !env, !exec, !include, !repo-root, !cwd, and !random tags; failures during evaluation return an error wrapped with ErrExecuteYamlFunctions, and unknown/unsupported tags are decoded and returned as their YAML value.
+// It supports !env, !exec, !include, !repo-root/!git.root, !git.sha/!git.ref, !git.branch, !cwd, and !random tags; failures during evaluation return an error wrapped with ErrExecuteYamlFunctions, and unknown/unsupported tags are decoded and returned as their YAML value.
...
-// It dispatches handling for !env, !exec, !include, !repo-root, !cwd, and !random tags to their respective handlers.
+// It dispatches handling for !env, !exec, !include, !repo-root/!git.root, !git.sha/!git.ref, !git.branch, !cwd, and !random tags to their respective handlers.

As per coding guidelines: "Never delete existing comments without a very strong reason; preserve helpful comments explaining why/how/what/where, and update comments to match code when refactoring."

Also applies to: 367-372

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/config/process_yaml.go` around lines 332 - 337, Update the scalar-tag
documentation/comments to reflect the new supported git tags and aliases:
include !git.root (alias), !git.sha and !git.ref (both accepted), and
!git.branch in the scalar-tag docs that currently describe the old tag set;
specifically update the comment blocks that reference dispatching to
processGitRootTag, processGitShaTag, and processGitBranchTag so their
descriptions match the actual supported tags (also apply the same update to the
other comment block near the second dispatch to these functions).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/function/git_root.go`:
- Line 44: Replace the direct fmt.Errorf wrapping on the git root failure with
the repository's static error from errors/errors.go (e.g., ErrGitRoot) and
combine it with the original err using errors.Join (or use fmt.Errorf with %w
only if you need a contextual message plus the static error); update the return
in pkg/function/git_root.go to return the empty string and
errors.Join(<staticErrorFromErrorsPackage>, err) and ensure the errors package
from errors/errors.go is imported.

In `@pkg/function/git.go`:
- Around line 37-40: Replace the ad-hoc fmt.Errorf wraps in pkg/function/git.go
(the ProcessTagSHA error and the two other fmt.Errorf sites) with the repository
static sentinel errors defined in errors/errors.go and combine them with the
underlying err using the repo pattern (errors.Join or fmt.Errorf with the
sentinel as the wrapped error per project style). Concretely, locate the failing
calls around atmosGit.ProcessTagSHA and the other two fmt.Errorf usages, import
the repo errors package and the standard errors package if needed, and return
the joined/static error (e.g., return "", errors.Join(errors.<SentinelError>,
err) or return "", fmt.Errorf("%w: additional context", errors.<SentinelError>))
instead of fmt.Errorf("...: %w", err).

In `@pkg/git/current_test.go`:
- Around line 93-95: The test uses a hardcoded Unix path "/fallback/root" when
calling ProcessTagRoot and asserting the result; replace the literal with a
cross-platform constructed path using filepath.Join (e.g. build the fallback arg
as YAMLFuncRoot + " " + filepath.Join("fallback","root") and assert.Equal
against that same filepath.Join value) and add the filepath import if missing so
the test is OS-agnostic; refer to ProcessTagRoot and YAMLFuncRoot to locate the
call and assertion.

In `@pkg/git/git.go`:
- Around line 214-222: GetRoot currently returns ad-hoc wrapped errors from
repo.Worktree() and filepath.Abs(...); replace those with the project's static
sentinel errors from errors/errors.go (e.g., ErrWorktreeNotFound /
ErrPathResolve or the appropriate named errors) by joining or wrapping the
original errors—use errors.Join(staticErr, err) or fmt.Errorf("context: %w",
staticErr) combined with %w for the original error per guideline—update the
error returns in the repo.Worktree() failure and the filepath.Abs(...) failure
sites so they consistently return the cataloged static errors plus the
underlying error.
- Around line 15-18: Remove the package-local sentinels ErrDetachedHead and
ErrEmptyBranchName from git.go and instead reference the centralized sentinel
errors you must add to the shared error catalog (define ErrDetachedHead and
ErrEmptyBranchName as exported variables in the shared errors package). Update
git.go to import that shared errors package and use the shared symbols (e.g.,
sharederrors.ErrDetachedHead, sharederrors.ErrEmptyBranchName) everywhere this
file currently creates or compares those errors so that callers can use
errors.Is() consistently.

---

Nitpick comments:
In `@pkg/config/process_yaml.go`:
- Around line 332-337: Update the scalar-tag documentation/comments to reflect
the new supported git tags and aliases: include !git.root (alias), !git.sha and
!git.ref (both accepted), and !git.branch in the scalar-tag docs that currently
describe the old tag set; specifically update the comment blocks that reference
dispatching to processGitRootTag, processGitShaTag, and processGitBranchTag so
their descriptions match the actual supported tags (also apply the same update
to the other comment block near the second dispatch to these functions).

In `@pkg/function/git_test.go`:
- Around line 32-54: Add a complementary test that sets up a real git repository
context and verifies the fallback does NOT run: create a new test (or extend
TestGitFunctions_ExecuteWithFallbackOutsideRepository) that uses t.TempDir(),
initializes a git repo (git init, create a commit, set a branch/ref), then call
Execute on NewGitShaFunction, NewGitBranchFunction and NewGitRefFunction and
assert the returned values are the actual git SHA/branch/ref (not the fallback
strings like "unknown" or "detached"); use the same
Execute(context.Background(), args, nil) invocation and require.NoError
assertions to ensure normal resolution succeeds.

In `@pkg/utils/git.go`:
- Around line 36-37: Update the doc comment for ProcessTagGitRoot to accurately
describe its current behavior: instead of claiming it uses go-git directly,
state that it delegates to atmosGit.ProcessTagRoot to obtain the repository root
(and mention any relevant behavior such as input handling or error conditions
inherited from atmosGit.ProcessTagRoot); do the same for the related comment at
line 46 so comments reflect the refactor and delegation rather than the old
implementation details.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 910bbab8-4c1b-49b6-a388-d49878d9abe3

📥 Commits

Reviewing files that changed from the base of the PR and between 7ada7db and ac00606.

📒 Files selected for processing (20)
  • internal/exec/yaml_func_utils.go
  • internal/exec/yaml_func_utils_context_test.go
  • pkg/config/process_yaml.go
  • pkg/config/process_yaml_test.go
  • pkg/function/defaults.go
  • pkg/function/git.go
  • pkg/function/git_root.go
  • pkg/function/git_root_test.go
  • pkg/function/git_test.go
  • pkg/function/registry_test.go
  • pkg/function/tags.go
  • pkg/function/tags_test.go
  • pkg/git/current_test.go
  • pkg/git/git.go
  • pkg/git/yaml_tags.go
  • pkg/provisioner/source/vendor_test.go
  • pkg/utils/git.go
  • pkg/utils/git_test.go
  • pkg/utils/yaml_utils.go
  • pkg/utils/yaml_utils_test.go

Comment thread pkg/function/git_root.go Outdated
Comment thread pkg/function/git.go
Comment thread pkg/git/current_test.go Outdated
Comment thread pkg/git/git.go Outdated
Comment thread pkg/git/git.go
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

1 similar comment
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 28, 2026
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 28, 2026
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Actionable comments posted: 0

@codecov

codecov Bot commented May 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.64948% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.60%. Comparing base (fb10bee) to head (a97f0db).

Files with missing lines Patch % Lines
pkg/config/process_yaml.go 44.64% 27 Missing and 4 partials ⚠️
pkg/git/git.go 69.23% 4 Missing and 4 partials ⚠️
internal/exec/yaml_func_utils.go 64.70% 3 Missing and 3 partials ⚠️
pkg/function/git.go 86.66% 3 Missing and 3 partials ⚠️
pkg/git/yaml_tags.go 92.30% 3 Missing ⚠️
pkg/function/git_root.go 66.66% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (71.64%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2537      +/-   ##
==========================================
+ Coverage   78.58%   78.60%   +0.02%     
==========================================
  Files        1145     1147       +2     
  Lines      110306   110458     +152     
==========================================
+ Hits        86685    86831     +146     
+ Misses      18813    18806       -7     
- Partials     4808     4821      +13     
Flag Coverage Δ
unittests 78.60% <71.64%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
errors/errors.go 100.00% <ø> (ø)
pkg/function/defaults.go 90.32% <100.00%> (+1.03%) ⬆️
pkg/function/tags.go 100.00% <100.00%> (ø)
pkg/utils/git.go 87.50% <100.00%> (+26.13%) ⬆️
pkg/utils/yaml_utils.go 85.87% <ø> (ø)
pkg/function/git_root.go 87.50% <66.66%> (-1.39%) ⬇️
pkg/git/yaml_tags.go 92.30% <92.30%> (ø)
internal/exec/yaml_func_utils.go 89.83% <64.70%> (-4.29%) ⬇️
pkg/function/git.go 86.66% <86.66%> (ø)
pkg/git/git.go 80.35% <69.23%> (-3.37%) ⬇️
... and 1 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aknysh
Andriy Knysh (aknysh) merged commit b30a4c2 into main May 29, 2026
59 checks passed
@aknysh
Andriy Knysh (aknysh) deleted the osterman/atmos-prod-catalog-refs branch May 29, 2026 05:07
@atmos-pro

atmos-pro Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Tip

Atmos Pro  

No affected stacks workflow was detected for this pull request.
If this is expected, no action is needed.
Learn More. Ask AI.

@github-actions

Copy link
Copy Markdown

These changes were released in v1.221.0-rc.1.

This branch was successfully deployed

1 active deployment
preview — a97f0db2 Deployed May 29, 2026 by github-actions[bot]
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 size/m Medium size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants