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

Include a materialized copy of built-in templates #2146

Merged
merged 22 commits into from
Jan 17, 2025

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Jan 14, 2025

Changes

Include a materialized copy of built-in templates as reference output.

This updates the output comparison logic to work against an output directory. The doComparison function now always works on real files. It can now tell apart non-existing files and empty files (e.g., the .gitkeep files in templates).

@pietern pietern temporarily deployed to test-trigger-is January 14, 2025 19:25 — with GitHub Actions Inactive
@pietern
Copy link
Contributor Author

pietern commented Jan 14, 2025

@denik I tried using testutil.ReplaceOutput instead of using the replacement context directly. This takes care of a UUID in the output. But it also replaces numbers with <NUMID> which is not valid JSON.

@denik
Copy link
Contributor

denik commented Jan 15, 2025

@denik I tried using testutil.ReplaceOutput instead of using the replacement context directly. This takes care of a UUID in the output. But it also replaces numbers with which is not valid JSON.

We could easily fix that with by using "<NUMID>" instead.

@denik
Copy link
Contributor

denik commented Jan 15, 2025

I think it would be useful (could be a follow up) to also run "bundle validate" and "bundle deploy" and other commands on these, so bundle/init is not a great name, because it's not just init. bundle/templates ?

pietern added a commit that referenced this pull request Jan 15, 2025
## Changes

Replacement was split between the type `ReplacementContext` and the
`ReplaceOutput` function. The latter also ran a couple of regular
expressions. This change consolidates them such that it is up to the
caller to compose the set of replacements to use.

This change is required to accommodate UUID replacement in #2146.
@pietern pietern temporarily deployed to test-trigger-is January 15, 2025 11:20 — with GitHub Actions Inactive
@pietern pietern temporarily deployed to test-trigger-is January 15, 2025 12:20 — with GitHub Actions Inactive
@pietern pietern temporarily deployed to test-trigger-is January 15, 2025 12:25 — with GitHub Actions Inactive
@pietern pietern force-pushed the acceptance-init-with-output branch from 3884a71 to f45b156 Compare January 16, 2025 15:45
@pietern pietern temporarily deployed to test-trigger-is January 16, 2025 15:45 — with GitHub Actions Inactive
@pietern
Copy link
Contributor Author

pietern commented Jan 16, 2025

#2166 makes sure that initialized templates are formatted per ruff.

@pietern pietern marked this pull request as ready for review January 16, 2025 15:46
@pietern pietern changed the title Include the materialized template as reference output Include a materialized copy of built-in templates Jan 16, 2025
@pietern pietern requested a review from denik January 16, 2025 15:49
t.Logf("Overwriting: %s", pathExpected)
testutil.WriteFile(t, pathExpected, valueNew)
} else {
t.Logf("Removing: %s", pathExpected)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove this? It's helpful to update golden test files when files are deleted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Auto-removal functionality is quite helpful actually. I'd prefer that we keep it.

We can do so by changing readIfExists to return (contents string, exists bool) to distinguish between empty and missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed this nuance, thanks.

I updated the code to deal with all combinations of missing files in a single place.

Please re-review the changes to acceptance_test.go.

acceptance/acceptance_test.go Show resolved Hide resolved
acceptance/acceptance_test.go Outdated Show resolved Hide resolved
github-merge-queue bot pushed a commit that referenced this pull request Jan 17, 2025
## Changes

The materialized templates included in #2146 include Python code that we
require to be formatted. Instead of running ruff as part of the
testcase, we can enforce that all Python code in the repository is
formatted. It won't be possible to have a passing acceptance test for
template initialization with unformatted code.
@pietern pietern temporarily deployed to test-trigger-is January 17, 2025 13:24 — with GitHub Actions Inactive
@pietern pietern temporarily deployed to test-trigger-is January 17, 2025 13:27 — with GitHub Actions Inactive
}

if !errors.Is(err, os.ErrNotExist) {
t.Fatalf("%s: %s", path, err)
}
return []byte{}
return []byte{}, false
}

func CopyDir(src, dst string, inputs, outputs map[string]bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have a unit test for this since this is part of the acceptance test infra.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree. The amount of logic here has grown. While the coverage is implied through passing tests, something could slip through.

acceptance/acceptance_test.go Show resolved Hide resolved
} else {
t.Logf("Removing: %s", pathExpected)
_ = os.Remove(pathExpected)
func doComparison(t *testing.T, repls testdiff.ReplacementsContext, dirRef, dirNew, relPath string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, I like having all the possible cases in one place.

@pietern pietern added this pull request to the merge queue Jan 17, 2025
Merged via the queue into main with commit 50f6269 Jan 17, 2025
9 checks passed
@pietern pietern deleted the acceptance-init-with-output branch January 17, 2025 15:09
andrewnester added a commit that referenced this pull request Jan 23, 2025
CLI:
 * Added text output templates for apps list and list-deployments ([#2175](#2175)).
 * Fix duplicate "apps" entry in help output ([#2191](#2191)).

Bundles:
 * Allow yaml-anchors in schema ([#2200](#2200)).
 * Show an error when non-yaml files used in include section ([#2201](#2201)).
 * Set WorktreeRoot to sync root outside git repo ([#2197](#2197)).
 * fix: Detailed message for using source-linked deployment with file_path specified ([#2119](#2119)).
 * Allow using variables in enum fields ([#2199](#2199)).
 * Add experimental-jobs-as-code template ([#2177](#2177)).
 * Reading variables from file ([#2171](#2171)).
 * Fixed an apps message order and added output test ([#2174](#2174)).
 * Default to forward slash-separated paths for path translation ([#2145](#2145)).
 * Include a materialized copy of built-in templates ([#2146](#2146)).
github-merge-queue bot pushed a commit that referenced this pull request Jan 23, 2025
CLI:
* Added text output templates for apps list and list-deployments
([#2175](#2175)).
* Fix duplicate "apps" entry in help output
([#2191](#2191)).

Bundles:
* Allow yaml-anchors in schema
([#2200](#2200)).
* Show an error when non-yaml files used in include section
([#2201](#2201)).
* Set WorktreeRoot to sync root outside git repo
([#2197](#2197)).
* fix: Detailed message for using source-linked deployment with
file_path specified
([#2119](#2119)).
* Allow using variables in enum fields
([#2199](#2199)).
* Add experimental-jobs-as-code template
([#2177](#2177)).
* Reading variables from file
([#2171](#2171)).
* Fixed an apps message order and added output test
([#2174](#2174)).
* Default to forward slash-separated paths for path translation
([#2145](#2145)).
* Include a materialized copy of built-in templates
([#2146](#2146)).
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.

3 participants