potiuk commented on code in PR #74889:
URL: https://github.com/apache/airflow/pull/74889#discussion_r4331120617


##########
dev/breeze/src/airflow_breeze/utils/selective_checks.py:
##########
@@ -2127,6 +2130,112 @@ def amd_runners(self) -> str:
     def arm_runners(self) -> str:
         return PUBLIC_ARM_RUNNERS
 
+    @cached_property
+    def runner_type(self) -> str:
+        """Runner labels for the jobs of a CI run on this run's platform.
+
+        The RunsOn label is a template the jobs fill in with their size class.
+        """
+        # RunsOn needs the run id in the label; without one (e.g. a local run) 
the jobs would never start.
+        run_id = self._github_context_dict.get("run_id")
+        if not run_id or not self._use_runs_on_runners():
+            return PUBLIC_ARM_RUNNERS if self._platform == CI_ARM_PLATFORM 
else PUBLIC_AMD_RUNNERS
+        template = (
+            RUNS_ON_ARM_RUNNER_TEMPLATE if self._platform == CI_ARM_PLATFORM 
else RUNS_ON_AMD_RUNNER_TEMPLATE
+        )
+        return json.dumps([template.format(run_id=run_id)])
+
+    def _use_runs_on_runners(self) -> bool:
+        """Whether this run should use the self-hosted RunsOn runners.
+
+        This only routes runs; it does not keep fork code off RunsOn. A 
``pull_request`` run uses
+        the PR's own workflow files and breeze, so a fork can request a RunsOn 
label directly -
+        that restriction has to be enforced by the RunsOn stack and the 
repository's Actions
+        settings, not here. Routed there: pushes, schedules and dispatches, 
and PRs from
+        apache/airflow branches except bots' (e.g. Dependabot's). A fork PR 
goes there while it
+        carries the ``use self-hosted runners`` label, a committer has 
approved its head commit and
+        no committer's request for changes is outstanding.
+        The repository variable ``USE_PUBLIC_RUNNERS=true`` moves every run 
back to public runners.
+        """
+        if self._github_repository != APACHE_AIRFLOW_GITHUB_REPOSITORY:
+            return False
+        if os.environ.get("USE_PUBLIC_RUNNERS", "").casefold() == "true":
+            return False
+        if USE_PUBLIC_RUNNERS_LABEL in self._pr_labels:
+            return False
+        if self._github_event in [GithubEvents.PUSH, GithubEvents.SCHEDULE, 
GithubEvents.WORKFLOW_DISPATCH]:
+            return True
+        if self._github_event != GithubEvents.PULL_REQUEST:
+            return False
+        if USE_SELF_HOSTED_RUNNERS_LABEL in self._pr_labels and 
self._head_approved_by_committer():

Review Comment:
   A re-run reuses the labels of its original event, so 
`USE_SELF_HOSTED_RUNNERS_LABEL in self._pr_labels` stays true after the label 
is removed, and with the head still approved the re-run goes to RunsOn. The 
previous implementation handled this through the `unlabeled` event ("A re-run 
reuses the labels of its original event, so a later removal must count."). 
Checking the label against the PR's current labels from the API, in the same 
request flow as the reviews, would restore that.
   
   ---
   Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting



-- 
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]

Reply via email to