rusackas commented on code in PR #40719:
URL: https://github.com/apache/superset/pull/40719#discussion_r3351724874
##########
scripts/change_detector.py:
##########
@@ -109,6 +109,37 @@ def is_int(s: str) -> bool:
return bool(re.match(r"^-?\d+$", s))
+def resolve_workflow_run_files(repo: str, sha: str) -> Optional[List[str]]:
+ """Resolve changed files for a workflow_run-triggered run.
+
+ When a workflow is gated behind another (e.g. running only after
+ pre-commit succeeds), GitHub re-dispatches it as a `workflow_run` event
+ whose context points at the default branch rather than the originating
+ diff. Recover the original event and head SHA from the workflow_run
+ payload, exposed via the WF_RUN_* env vars. Returns ``None`` (meaning
+ "assume all changed") when the diff can't be resolved.
+ """
+ original_event = os.getenv("WF_RUN_EVENT") or "push"
+ print("ORIGINAL_EVENT", original_event)
+ if original_event == "pull_request":
+ pr_number = os.getenv("WF_RUN_PR_NUMBER", "")
+ if not is_int(pr_number):
+ # Fork PRs don't populate workflow_run.pull_requests, so we can't
+ # resolve the diff -> assume all changed (run everything).
+ print("workflow_run without PR context, assuming all changed")
+ return None
+ files = fetch_changed_files_pr(repo, pr_number)
+ print("PR files:")
+ print_files(files)
+ return files
+
+ head_sha = os.getenv("WF_RUN_HEAD_SHA") or sha
+ files = fetch_changed_files_push(repo, head_sha)
+ print("Files touched since previous commit:")
+ print_files(files)
+ return files
Review Comment:
Good call — added unit tests in
`tests/unit_tests/scripts/change_detector_test.py` covering
`resolve_workflow_run_files`: the pull_request and push success paths
(asserting the right fetch function is called and its return value propagates),
the head-SHA-vs-fallback-SHA behavior, and the missing/invalid
`WF_RUN_PR_NUMBER` cases that return `None` (assume all changed).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]