-
Notifications
You must be signed in to change notification settings - Fork 254
Add --extra-yaml flag to cci flow run/info and task run/info #3969
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
Open
jstvz
wants to merge
14
commits into
main
Choose a base branch
from
extra-yaml-cli-flag
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a836976
chore: unblock pyright for pre-commit hook
jstvz 9d650ac
feat(cli): add resolve_extra_yaml helper for --extra-yaml flag
jstvz 470c1e9
test(cli): cover resolve_extra_yaml env var and error paths
jstvz 29c75aa
feat(cli): add CliRuntime.reload_project_config for post-init overrides
jstvz f5a89df
feat(cli): add --extra-yaml to cci flow run and cci flow info
jstvz 220b230
feat(cli): add --extra-yaml to cci task info
jstvz d2b2436
feat(cli): add --extra-yaml to cci task run
jstvz 4ed8bc2
test(cli): end-to-end --extra-yaml merge behavior
jstvz 7d0c39e
test(cli): -o overrides --extra-yaml for the same task option
jstvz 6166142
docs(cli): document --extra-yaml flag and CUMULUSCI_EXTRA_YAML
jstvz 2823e9d
docs(config): document --extra-yaml as per-invocation scope
jstvz 6f892cc
docs: add CUMULUSCI_EXTRA_YAML env var entry
jstvz 62e27c4
fix: parse CUMULUSCI_EXTRA_YAML as comma-separated, use pathlib
jstvz 89e325d
docs(config): correct CUMULUSCI_EXTRA_YAML separator to comma
jstvz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,4 +35,4 @@ repos: | |
| types: [python] | ||
| pass_filenames: false | ||
| additional_dependencies: | ||
| - pyright | ||
| - pyright@1.1.408 | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """Resolve ``--extra-yaml`` CLI flag and ``CUMULUSCI_EXTRA_YAML`` env var. | ||
|
|
||
| The returned string is passed as ``BaseProjectConfig``'s ``additional_yaml`` | ||
| kwarg, which already merges into the project config via the existing YAML | ||
| merge stack. | ||
| """ | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
| from typing import Optional, Tuple | ||
|
|
||
| import click | ||
| import yaml | ||
|
|
||
| from cumulusci.core.exceptions import CumulusCIUsageError | ||
| from cumulusci.core.utils import dictmerge, process_list_arg | ||
|
|
||
| ENV_VAR = "CUMULUSCI_EXTRA_YAML" | ||
|
|
||
|
|
||
| def resolve_extra_yaml(paths: Tuple[str, ...]) -> Optional[str]: | ||
| """Read extra-yaml paths from the CLI flag (preferred) or env var (fallback). | ||
|
|
||
| Args: | ||
| paths: Tuple of paths from Click's ``multiple=True`` option. Empty | ||
| means the flag was not supplied; fall back to | ||
| ``CUMULUSCI_EXTRA_YAML`` (comma-separated paths). | ||
|
|
||
| Returns: | ||
| A single YAML document representing the deep-merge of all input files | ||
| (later files override earlier files), or ``None`` if no paths were | ||
| resolved. The returned string is a valid single-document YAML stream | ||
| suitable for ``BaseProjectConfig(additional_yaml=...)``. | ||
|
|
||
| Raises: | ||
| CumulusCIUsageError: If any listed path does not exist or is unreadable. | ||
| """ | ||
| effective_paths = paths | ||
| if not effective_paths: | ||
| env_value = os.environ.get(ENV_VAR) | ||
| if env_value: | ||
| effective_paths = tuple(p for p in (process_list_arg(env_value) or []) if p) | ||
|
|
||
| if not effective_paths: | ||
| return None | ||
|
|
||
| click.echo( | ||
| f"Loading extra YAML from: {', '.join(effective_paths)}. " | ||
| "Extra YAML can redefine task class_path entries and run arbitrary " | ||
| "Python code; only load files you trust.", | ||
| err=True, | ||
| ) | ||
|
|
||
| merged: dict = {} | ||
| for path in effective_paths: | ||
| file_path = Path(path) | ||
| if not file_path.is_file(): | ||
| raise CumulusCIUsageError(f"--extra-yaml file not found: {path}") | ||
| try: | ||
| raw = file_path.read_text(encoding="utf-8") | ||
| except OSError as e: | ||
| raise CumulusCIUsageError(f"--extra-yaml could not read {path}: {e}") | ||
| try: | ||
| parsed = yaml.safe_load(raw) or {} | ||
| except yaml.YAMLError as e: | ||
| raise CumulusCIUsageError(f"--extra-yaml could not parse {path}: {e}") | ||
| if not isinstance(parsed, dict): | ||
| raise CumulusCIUsageError( | ||
| f"--extra-yaml expects a YAML mapping at the top level in {path}" | ||
| ) | ||
| merged = dictmerge(merged, parsed) | ||
| return yaml.safe_dump(merged, default_flow_style=False) | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jstvz dictmerge appends lists instead of replacing them. So, if file1.yml defines a flow with 3 steps and file2.yml defines the same flow with 2 different steps, the result is 5 steps (concatenated), not 2 (replaced). Should we document this behavior explicitly in cli.md specifying the lists have this behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/cli.mdalready calls this out at the--extra-yamlsection: "Mappings and scalars are overridden; lists are concatenated, not replaced."