Skip to content

Commit

Permalink
SNOW-1509249 Hide diff output when running snow app validate (#1267)
Browse files Browse the repository at this point in the history
Since `snow app validate` throws away the scratch stage every time, the diff will always show that all files are being uploaded, which isn't necessary to show to the user in this case.
  • Loading branch information
sfc-gh-fcampbell authored Jul 2, 2024
1 parent d2b06d2 commit 6c6e2e4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* Improve terminal output sanitization to avoid ASCII escape codes.
* The `snow sql` command will show query text before executing it.
* Improved stage diff output in `snow app` commands
* Hid the diff from `snow app validate` output since it was redundant

# v2.5.0
## Backward incompatibility
Expand Down
17 changes: 12 additions & 5 deletions src/snowflake/cli/plugins/nativeapp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def sync_deploy_root_with_stage(
recursive: bool,
stage_fqn: str,
local_paths_to_sync: List[Path] | None = None,
print_diff: bool = True,
) -> DiffResult:
"""
Ensures that the files on our remote stage match the artifacts we have in
Expand All @@ -337,6 +338,7 @@ def sync_deploy_root_with_stage(
stage_fqn (str): The name of the stage to diff against and upload to.
local_paths_to_sync (List[Path], optional): List of local paths to sync. Defaults to None to sync all
local paths. Note that providing an empty list here is equivalent to None.
print_diff (bool): Whether to print the diff between the local files and the remote stage. Defaults to True
Returns:
A `DiffResult` instance describing the changes that were performed.
Expand All @@ -359,10 +361,11 @@ def sync_deploy_root_with_stage(
)

# Perform a diff operation and display results to the user for informational purposes
cc.step(
"Performing a diff between the Snowflake stage and your local deploy_root ('%s') directory."
% self.deploy_root.resolve()
)
if print_diff:
cc.step(
"Performing a diff between the Snowflake stage and your local deploy_root ('%s') directory."
% self.deploy_root.resolve()
)
diff: DiffResult = compute_stage_diff(self.deploy_root, stage_fqn)

if local_paths_to_sync:
Expand Down Expand Up @@ -411,7 +414,8 @@ def sync_deploy_root_with_stage(
f"The following files exist only on the stage:\n{files_not_removed_str}\n\nUse the --prune flag to delete them from the stage."
)

print_diff_to_console(diff, bundle_map)
if print_diff:
print_diff_to_console(diff, bundle_map)

# Upload diff-ed files to application package stage
if diff.has_changes():
Expand Down Expand Up @@ -568,6 +572,7 @@ def deploy(
stage_fqn: Optional[str] = None,
local_paths_to_sync: List[Path] | None = None,
validate: bool = True,
print_diff: bool = True,
) -> DiffResult:
"""app deploy process"""

Expand All @@ -587,6 +592,7 @@ def deploy(
recursive=recursive,
stage_fqn=stage_fqn,
local_paths_to_sync=local_paths_to_sync,
print_diff=print_diff,
)

if validate:
Expand Down Expand Up @@ -625,6 +631,7 @@ def get_validation_result(self, use_scratch_stage: bool):
recursive=True,
stage_fqn=stage_fqn,
validate=False,
print_diff=False,
)
prefixed_stage_fqn = StageManager.get_standard_stage_prefix(stage_fqn)
try:
Expand Down
2 changes: 2 additions & 0 deletions tests/nativeapp/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ def test_validate_use_scratch_stage(
recursive=True,
stage_fqn=native_app_manager.scratch_stage_fqn,
validate=False,
print_diff=False,
)
assert mock_execute.mock_calls == expected

Expand Down Expand Up @@ -1137,6 +1138,7 @@ def test_validate_failing_drops_scratch_stage(
recursive=True,
stage_fqn=native_app_manager.scratch_stage_fqn,
validate=False,
print_diff=False,
)
assert mock_execute.mock_calls == expected

Expand Down

0 comments on commit 6c6e2e4

Please sign in to comment.