Add JSON output to bundle init reporting where the template materialized - #6161
Draft
pavloKozlov wants to merge 3 commits into
Draft
Add JSON output to bundle init reporting where the template materialized#6161pavloKozlov wants to merge 3 commits into
bundle init reporting where the template materialized#6161pavloKozlov wants to merge 3 commits into
Conversation
…lized
`bundle init` gave callers no machine-readable indication of where it wrote
the template. The success message is the template's own rendered text, so a
caller that passes `--output-dir` could not learn which subdirectory under it
became the bundle root, and had to assume it is named after the project. That
assumption holds for the built-in templates, which output `{{.project_name}}/`,
but not for a custom template whose output path is nested.
Add an `InitResult` reported by `bundle init -o json`:
{
"template_name": "custom",
"output_dir": "/path/to/output",
"bundle_roots": ["projects/alpha/yz"]
}
`bundle_roots` are the directories that received a bundle configuration file,
relative to the resolved output directory, slash-separated and sorted. They are
derived from the files `persistToDisk` actually persisted, so a configuration
file removed by a `{{skip}}` directive is not reported. Paths stay relative and
slash-based so the contract is identical for the local and workspace filers.
A template may emit more than one bundle configuration file, in which case each
root is an independent bundle, so this is a list; callers that expect exactly
one should handle len != 1 explicitly.
The default text output is unchanged: rendering is gated on JSON output, and
the success message is still printed by `Materialize`. `Configure` now resolves
the output directory with `filepath.Abs` and retains it, so a relative
`--output-dir` such as `..` can be joined with a bundle root by the caller.
Collaborator
Integration test reportCommit: 01ee4b0
8 interesting tests: 4 RECOVERED, 4 SKIP
Top 6 slowest tests (at least 2 minutes):
|
The two new acceptance tests compared `output_dir` verbatim, but it is an OS path, so Windows rendered it backslash-separated and the golden files only matched on Unix. Pipe the JSON through sed to normalize the separators, keeping a single golden per case. `bundle_roots` are always slash-separated, so they are unaffected. Also drop the unit cases that the acceptance tests already cover end to end (nested root, a root at the output directory, and the empty input). The remaining rows cover what the acceptance tests cannot reach without a template fixture each: the four configuration file names, ordering, de-duplication, and files merely named like a configuration file.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
bundle initgives callers no machine-readable indication of where it wrote the template, so a caller that passes--output-dirhas to assume the bundle root is named after the project. That holds for the built-in templates, which output{{.project_name}}/, but not for a custom template whose output path is nested: with output pathprojects/{{.group}}/{{.project_name}}/the bundle lands at<output-dir>/projects/alpha/yz/, and a caller looking for<output-dir>/yz/misses it.Related: #6142.
Adds an
InitResultrendered bybundle init -o json:{ "template_name": "custom", "output_dir": "/path/to/output", "bundle_roots": ["projects/alpha/yz"] }bundle_rootsare the directories that received a bundle configuration file, relative to the resolvedoutput_dir, slash-separated and sorted (a root that isoutput_diritself is"."). They come from the filespersistToDiskactually persisted, so a file removed by a{{skip}}directive is not reported, and all four names inbundle/config.FileNamesare recognised. Paths usepathrather thanfilepathand stay relative, so the contract is identical for the local and workspace filers.Configurenow resolves--output-dirwithfilepath.Absand retains it, so a relative value such as..can be joined with a bundle root.A template can emit several bundle configuration files, in which case each root is an independent bundle, so this is a list; callers expecting one root should handle
len != 1explicitly. Field names are part of the JSON contract — new fields should be additive.Compatibility. Default text output is unchanged: rendering is gated on
flags.OutputJSON, and the success message is still printed byMaterialize. No existing golden files change, andMaterialize's signature is untouched, socmd/pipelines/init.gois unaffected.Tests. Unit coverage of the root derivation (nested, multiple sorted,
".", all four file names, de-duplication, and a{{skip}}-removed file driven throughpersistToDisk), plus two acceptance cases: a nested-output custom template asserting["projects/alpha/yz"]and no stray top-levelyz/, and a built-in template pinning the standard shape. Both scripts redirect stderr so the goldens pin only the JSON.