This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 25e5d54192 Print selective-check traceback on stdout rather than 
stderr (#38441)
25e5d54192 is described below

commit 25e5d5419216900f6cdff0f985b5c2e37afeaa9b
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sun Mar 24 20:14:33 2024 +0100

    Print selective-check traceback on stdout rather than stderr (#38441)
    
    We are using stdout of selective-check to print diagnostic information
    and stderr is redirected to produce outputs for GIHUB_OUTPUTS
    special variable in GitHub Actions. However this means that when
    there is an error when running selective-checks, the traceback
    goes to stderr and we cannot see it, plus it makes Github Actions
    to fail with crypttic errors.
    
    This PR catches uncaught exception and uses rich mechanism to print
    the traceback to the diagnostic (stdout) console instead so that
    we can see it - in colour as well as with local variables, which
    might become handy.
---
 .../src/airflow_breeze/commands/ci_commands.py     | 44 ++++++++++++----------
 1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/dev/breeze/src/airflow_breeze/commands/ci_commands.py 
b/dev/breeze/src/airflow_breeze/commands/ci_commands.py
index 12587e55d6..54f74f8026 100644
--- a/dev/breeze/src/airflow_breeze/commands/ci_commands.py
+++ b/dev/breeze/src/airflow_breeze/commands/ci_commands.py
@@ -248,26 +248,30 @@ def selective_check(
     github_actor: str,
     github_context: str,
 ):
-    from airflow_breeze.utils.selective_checks import SelectiveChecks
-
-    github_context_dict = json.loads(github_context) if github_context else {}
-    github_event = GithubEvents(github_event_name)
-    if commit_ref is not None:
-        changed_files = get_changed_files(commit_ref=commit_ref)
-    else:
-        changed_files = ()
-    sc = SelectiveChecks(
-        commit_ref=commit_ref,
-        files=changed_files,
-        default_branch=default_branch,
-        default_constraints_branch=default_constraints_branch,
-        pr_labels=tuple(ast.literal_eval(pr_labels)) if pr_labels else (),
-        github_event=github_event,
-        github_repository=github_repository,
-        github_actor=github_actor,
-        github_context_dict=github_context_dict,
-    )
-    print(str(sc), file=sys.stderr)
+    try:
+        from airflow_breeze.utils.selective_checks import SelectiveChecks
+
+        github_context_dict = json.loads(github_context) if github_context 
else {}
+        github_event = GithubEvents(github_event_name)
+        if commit_ref is not None:
+            changed_files = get_changed_files(commit_ref=commit_ref)
+        else:
+            changed_files = ()
+        sc = SelectiveChecks(
+            commit_ref=commit_ref,
+            files=changed_files,
+            default_branch=default_branch,
+            default_constraints_branch=default_constraints_branch,
+            pr_labels=tuple(ast.literal_eval(pr_labels)) if pr_labels else (),
+            github_event=github_event,
+            github_repository=github_repository,
+            github_actor=github_actor,
+            github_context_dict=github_context_dict,
+        )
+        print(str(sc), file=sys.stderr)
+    except Exception:
+        get_console().print_exception(show_locals=True)
+        sys.exit(1)
 
 
 TEST_BRANCH_MATCHER = re.compile(r"^v.*test$")

Reply via email to