Skip to content

Commit bfa6811

Browse files
potiukpankajkotiamoghrajesh
authored andcommitted
Add "use self-hosted runners" to CI setup (#38779)
* Add "use self-hosted runners" to CI setup In anticipation of switching commiter PRs to use public runners, we are adding the feature of applying the "use self-hosted runner" to a PR to make it use self-hosted runners. * Update dev/breeze/doc/ci/04_selective_checks.md Co-authored-by: Pankaj Koti <[email protected]> * Update dev/breeze/doc/ci/04_selective_checks.md Co-authored-by: Pankaj Koti <[email protected]> * Update dev/breeze/doc/ci/04_selective_checks.md Co-authored-by: Amogh Desai <[email protected]> * Update dev/breeze/doc/ci/04_selective_checks.md Co-authored-by: Amogh Desai <[email protected]> * Update dev/breeze/src/airflow_breeze/utils/selective_checks.py Co-authored-by: Amogh Desai <[email protected]> --------- Co-authored-by: Pankaj Koti <[email protected]> Co-authored-by: Amogh Desai <[email protected]> (cherry picked from commit d2f11f0)
1 parent 551b550 commit bfa6811

File tree

3 files changed

+154
-66
lines changed

3 files changed

+154
-66
lines changed

dev/breeze/doc/ci/04_selective_checks.md

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
- [Suspended providers](#suspended-providers)
2929
- [Selective check outputs](#selective-check-outputs)
3030
- [Committer vs. non-committer PRs](#committer-vs-non-committer-prs)
31-
- [PR labels](#pr-labels)
31+
- [Changing behaviours of the CI runs by setting labels](#changing-behaviours-of-the-ci-runs-by-setting-labels)
3232

3333
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
3434

@@ -267,17 +267,29 @@ This is controlled by `Selective checks <04_selective_checks.md>`__ that set app
267267
the build-info job of the workflow (see`is-committer-build` to `true`) if the actor is in the committer's
268268
list and can be overridden by `non committer build` label in the PR.
269269

270-
Also, for most of the jobs, committer builds by default use "Self-hosted" runners, while non-committer
271-
builds use "Public" runners. For committers, this can be overridden by setting the
272-
`use public runners` label in the PR.
270+
## Changing behaviours of the CI runs by setting labels
271+
272+
Also, currently for most of the jobs, committer builds by default use "Self-hosted" runners, while
273+
non-committer builds use "Public" runners. For committers, this can be overridden by setting the
274+
`use public runners` label in the PR. In the future when we might also switch committers to public runners.
275+
Committers will be able to use `use self-hosted runners` label in the PR to force using self-hosted runners.
276+
The `use public runners` label will still be available for committers and they will be able to set it for
277+
builds that also have `canary` label set to also switch the `canary` builds to public runners.
273278

274279
If you are testing CI workflow changes and want to test it for more complete matrix combinations generated by
275280
the jobs - you can set `all versions` label in the PR. This will run the PRs with the same combinations
276-
of versions as the `canary` main build. Using `all versions` is automatically set when build or project
277-
dependencies change in `pyproject.toml`.
278-
279-
If you are testing CI workflow changes and change `pyproject.toml` or `generated/provider_dependencies.json` and you
280-
want to limit the number of matrix combinations generated by
281+
of versions as the `canary` main build. Using `all versions` is automatically set when build dependencies
282+
change in `pyproject.toml` or when dependencies change for providers in `generated/provider_dependencies.json`
283+
or when `hatch_build.py` changes.
284+
285+
If you are running an `apache` PR, you can also set `canary` label for such PR and in this case, all the
286+
`canary` properties of build will be used: `self-hosted` runners, `full tests needed` mode, `all versions`
287+
as well as all canary-specific jobs will run there. You can modify this behaviour of the `canary` run by
288+
applying `use public runners`, and `default versions only` labels to the PR as well which will still run
289+
a `canary` equivalent build but with public runners an default Python/K8S versions only - respectively.
290+
291+
If you are testing CI workflow changes and change `pyproject.toml` or `generated/provider_dependencies.json`
292+
and you want to limit the number of matrix combinations generated by
281293
the jobs - you can set `default versions only` label in the PR. This will limit the number of versions
282294
used in the matrix to the default ones (default Python version and default Kubernetes version).
283295

@@ -288,30 +300,28 @@ used in the matrix to the latest ones (latest Python version and latest Kubernet
288300
You can also disable cache if you want to make sure your tests will run with image that does not have
289301
left-over package installed from the past cached image - by setting `disable image cache` label in the PR.
290302

291-
By default all outputs of successful parallel tests are not shown. You can enable them by setting
303+
By default, all outputs of successful parallel tests are not shown. You can enable them by setting
292304
`include success outputs` label in the PR. This makes the logs of mostly successful tests a lot longer
293305
and more difficult to sift through, but it might be useful in case you want to compare successful and
294306
unsuccessful runs of the tests.
295307

296-
## PR labels
297-
298-
As mentioned below, you can influence the outputs of selected checks by setting labels to the PR. Here is
299-
am overview of possible labels and their meaning:
300-
301-
| Label | Affected outputs | Meaning |
302-
|-------------------------------|-------------------------------|-----------------------------------------------------------------------------------------------------------------|
303-
| canary | is-canary-run | If set, the PR run from apache/airflow repo behaves as `canary` run (can only be run by maintainer). |
304-
| debug ci resources | debug-ci-resources | If set, then debugging resources is enabled during parallel tests and you can see them in the output. |
305-
| default versions only | all-versions, *-versions-* | If set, the number of Python and Kubernetes, DB versions used by the build will be limited to the default ones. |
306-
| disable image cache | docker-cache | If set, the image cache is disables when building the image. |
307-
| include success outputs | include-success-outputs | By default, outputs of successful parallel tests are not shown - enabling this flag will make then shown. |
308-
| latest versions only | *-versions-*, *-versions-* | If set, the number of Python, Kubernetes, DB versions used by the build will be limited to the latest ones. |
309-
| all versions | all-versions, *-versions-* | Run tests for all python and k8s versions. |
310-
| full tests needed | full-tests-needed | Run complete set of tests (might be with default or all python/k8s versions) |
311-
| non committer build | is-committer-build | If set then even for non-committer builds, the scripts used for images are used from target branch. |
312-
| upgrade to newer dependencies | upgrade-to-newer-dependencies | If set to true (default false) then dependencies in the CI image build are upgraded to the newer ones. |
313-
| use public runners | runs-on-as-json-default | Force using public runners even for Committer runs. |
314-
308+
This table summarizes the labels you can use on PRs to control the selective checks and the CI runs:
309+
310+
| Label | Affected outputs | Meaning |
311+
|----------------------------------|----------------------------------|-------------------------------------------------------------------------------------------|
312+
| all versions | all-versions, *-versions-* | Run tests for all python and k8s versions. |
313+
| allow suspended provider changes | allow-suspended-provider-changes | Allow changes to suspended providers. |
314+
| canary | is-canary-run | If set, the PR run from apache/airflow repo behaves as `canary` run. |
315+
| debug ci resources | debug-ci-resources | If set, then debugging resources is enabled during parallel tests and you can see them. |
316+
| default versions only | all-versions, *-versions-* | If set, the number of Python and Kubernetes, DB versions are limited to the default ones. |
317+
| disable image cache | docker-cache | If set, the image cache is disables when building the image. |
318+
| full tests needed | full-tests-needed | If set, complete set of tests are run |
319+
| include success outputs | include-success-outputs | If set, outputs of successful parallel tests are shown not only failed outputs. |
320+
| latest versions only | *-versions-*, *-versions-* | If set, the number of Python, Kubernetes, DB versions will be limited to the latest ones. |
321+
| non committer build | is-committer-build | If set, the scripts used for images are used from target branch for committers. |
322+
| upgrade to newer dependencies | upgrade-to-newer-dependencies | If set to true (default false) then dependencies in the CI image build are upgraded. |
323+
| use public runners | runs-on-as-json-default | Force using public runners as default runners. |
324+
| use self-hosted runners | runs-on-as-json-default | Force using self-hosted runners as default runners. |
315325

316326
-----
317327

dev/breeze/src/airflow_breeze/utils/selective_checks.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@
6363
from airflow_breeze.utils.provider_dependencies import DEPENDENCIES, get_related_providers
6464
from airflow_breeze.utils.run_utils import run_command
6565

66-
FULL_TESTS_NEEDED_LABEL = "full tests needed"
66+
ALL_VERSIONS_LABEL = "all versions"
6767
DEBUG_CI_RESOURCES_LABEL = "debug ci resources"
68-
USE_PUBLIC_RUNNERS_LABEL = "use public runners"
69-
NON_COMMITTER_BUILD_LABEL = "non committer build"
7068
DEFAULT_VERSIONS_ONLY_LABEL = "default versions only"
71-
ALL_VERSIONS_LABEL = "all versions"
72-
LATEST_VERSIONS_ONLY_LABEL = "latest versions only"
7369
DISABLE_IMAGE_CACHE_LABEL = "disable image cache"
70+
FULL_TESTS_NEEDED_LABEL = "full tests needed"
7471
INCLUDE_SUCCESS_OUTPUTS_LABEL = "include success outputs"
72+
LATEST_VERSIONS_ONLY_LABEL = "latest versions only"
73+
NON_COMMITTER_BUILD_LABEL = "non committer build"
7574
UPGRADE_TO_NEWER_DEPENDENCIES_LABEL = "upgrade to newer dependencies"
75+
USE_PUBLIC_RUNNERS_LABEL = "use public runners"
76+
USE_SELF_HOSTED_RUNNERS_LABEL = "use self-hosted runners"
7677

7778

7879
ALL_CI_SELECTIVE_TEST_TYPES = (
@@ -1114,7 +1115,11 @@ def affected_providers_list_as_string(self) -> str | None:
11141115
def runs_on_as_json_default(self) -> str:
11151116
if self._github_repository == APACHE_AIRFLOW_GITHUB_REPOSITORY:
11161117
if self._github_event in [GithubEvents.SCHEDULE, GithubEvents.PUSH]:
1118+
# Canary and Scheduled runs
11171119
return RUNS_ON_SELF_HOSTED_RUNNER
1120+
if self._pr_labels and USE_PUBLIC_RUNNERS_LABEL in self._pr_labels:
1121+
# Forced public runners
1122+
return RUNS_ON_PUBLIC_RUNNER
11181123
actor = self._github_actor
11191124
if self._github_event in (GithubEvents.PULL_REQUEST, GithubEvents.PULL_REQUEST_TARGET):
11201125
try:
@@ -1129,8 +1134,23 @@ def runs_on_as_json_default(self) -> str:
11291134
f"[info]Could not find the actor from pull request, "
11301135
f"falling back to the actor who triggered the PR: {actor}[/]"
11311136
)
1132-
if actor in COMMITTERS and USE_PUBLIC_RUNNERS_LABEL not in self._pr_labels:
1137+
if (
1138+
actor not in COMMITTERS
1139+
and self._pr_labels
1140+
and USE_SELF_HOSTED_RUNNERS_LABEL in self._pr_labels
1141+
):
1142+
get_console().print(
1143+
f"[error]The PR has `{USE_SELF_HOSTED_RUNNERS_LABEL}` label, but "
1144+
f"{actor} is not a committer. This is not going to work.[/]"
1145+
)
1146+
sys.exit(1)
1147+
if USE_SELF_HOSTED_RUNNERS_LABEL in self._pr_labels:
1148+
# Forced self-hosted runners
1149+
return RUNS_ON_SELF_HOSTED_RUNNER
1150+
if actor in COMMITTERS:
11331151
return RUNS_ON_SELF_HOSTED_RUNNER
1152+
else:
1153+
return RUNS_ON_PUBLIC_RUNNER
11341154
return RUNS_ON_PUBLIC_RUNNER
11351155

11361156
@cached_property

0 commit comments

Comments
 (0)