Skip to content

Commit 8d65d25

Browse files
authored
Running php in the main gitlab e2e pipeline (#8409)
1 parent 82f30f1 commit 8d65d25

4 files changed

Lines changed: 63 additions & 59 deletions

File tree

‎.gitlab-ci.yml‎

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -471,37 +471,6 @@ system_tests_param:
471471
- export EXCLUDED_SCENARIOS='DEBUGGER_EXPRESSION_LANGUAGE'
472472
- export SYSTEM_TESTS_PUSH_TO_TEST_OPTIMIZATION=true
473473

474-
# THREAD_CONTEXT_SHARING needs a dedicated runner pool, so it is run on every PR, whatever the
475-
# modified files are, to catch any breakage of this setup. It uses the official workflow, as tracer
476-
# repos do, in a child pipeline: including main.yml a second time here would override the jobs of
477-
# the include above. One PHP weblog is enough.
478-
system_tests_php_thread_context_sharing:
479-
stage: e2e
480-
needs:
481-
- job: build_ci_image
482-
artifacts: false
483-
optional: true
484-
- job: mirror_images
485-
artifacts: false
486-
optional: true
487-
- job: build_base_images
488-
artifacts: false
489-
optional: true
490-
rules:
491-
- if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
492-
trigger:
493-
include:
494-
- local: /utils/ci/gitlab/main.yml
495-
inputs:
496-
# main.yml declares no stage, so use one of GitLab's default stages
497-
stage: "test"
498-
ref: "$CI_COMMIT_SHA"
499-
libraries: "php"
500-
scenarios: "THREAD_CONTEXT_SHARING"
501-
weblogs: "apache-mod-8.0"
502-
push_to_test_optimization: true
503-
strategy: depend
504-
505474
build_ci_image:
506475
image: registry.ddbuild.io/system-tests/image-builder:496bc0863a74
507476
interruptible: false

‎tests/test_the_test/test_compute_libraries_and_scenarios.py‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,15 +966,40 @@ def test_pr_pipeline_selects_c(self, monkeypatch: pytest.MonkeyPatch, source: st
966966

967967
assert 'libraries="c"' in process(inputs)
968968

969-
def test_main_push_ignores_weblog_map(self, monkeypatch: pytest.MonkeyPatch) -> None:
969+
@staticmethod
970+
def _library_weblog_scenarios(output: list[str]) -> dict | None:
971+
line = next((line for line in output if line.startswith("library_weblog_scenarios=")), None)
972+
return None if line is None else json.loads(json.loads(line.split("=", 1)[1]))
973+
974+
@pytest.mark.parametrize("source", ["merge_request_event", "push"])
975+
def test_pr_pipeline_selects_php_weblog_map(self, monkeypatch: pytest.MonkeyPatch, source: str) -> None:
976+
monkeypatch.setenv("GITLAB_CI", "true")
977+
monkeypatch.setenv("CI_PIPELINE_SOURCE", source)
978+
monkeypatch.setenv("CI_COMMIT_REF_NAME", "feature/php")
979+
inputs = build_inputs(modified_files=["utils/build/docker/php/apache-mod-8.0.Dockerfile"])
980+
981+
output = process(inputs)
982+
assert self._library_weblog_scenarios(output) == {"php": {"apache-mod-8.0": ["THREAD_CONTEXT_SHARING"]}}
983+
assert not any(line.startswith("libraries=") for line in output)
984+
985+
def test_pr_pipeline_does_not_select_php_if_not_impacted(self, monkeypatch: pytest.MonkeyPatch) -> None:
986+
monkeypatch.setenv("GITLAB_CI", "true")
987+
monkeypatch.setenv("CI_PIPELINE_SOURCE", "push")
988+
monkeypatch.setenv("CI_COMMIT_REF_NAME", "feature/c")
989+
inputs = build_inputs(modified_files=["utils/build/docker/c/perl-mojolicious.Dockerfile"])
990+
991+
assert self._library_weblog_scenarios(process(inputs)) is None
992+
993+
def test_main_push_uses_main_weblog_maps(self, monkeypatch: pytest.MonkeyPatch) -> None:
970994
monkeypatch.setenv("GITLAB_CI", "true")
971995
monkeypatch.setenv("CI_PIPELINE_SOURCE", "push")
972996
monkeypatch.setenv("CI_COMMIT_REF_NAME", "main")
973997
inputs = build_inputs(modified_files=["utils/build/docker/python/flask-poc.Dockerfile"])
974998

975999
output = process(inputs)
9761000
assert 'libraries="python"' in output
977-
assert not any(line.startswith("library_weblog_scenarios=") for line in output)
1001+
# python runs all its weblogs on main, php only its weblog map
1002+
assert self._library_weblog_scenarios(output) == {"php": {"apache-mod-8.0": ["THREAD_CONTEXT_SHARING"]}}
9781003

9791004
@pytest.mark.parametrize(
9801005
("source", "ref"),

‎utils/scripts/compute_libraries_and_scenarios.py‎

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def _get_scenarios_by_definition_file() -> dict[str, set[str]]:
5151
# weblogs/scenarios when the library is activated.
5252
GITLAB_PR_LIBRARIES: dict[str, dict[str, list[str]] | None] = {
5353
"c": None,
54+
# THREAD_CONTEXT_SHARING needs a dedicated runner pool: checks that this setup works. One weblog is enough.
55+
"php": {"apache-mod-8.0": ["THREAD_CONTEXT_SHARING"]},
5456
# GitLab runs containers on the default bridge network: checks that the mocked backend network aliases work there
5557
"python": {
5658
"flask-poc": [
@@ -61,7 +63,11 @@ def _get_scenarios_by_definition_file() -> dict[str, set[str]]:
6163
]
6264
},
6365
}
64-
GITLAB_MAIN = {"python"}
66+
# Libraries run by GitLab end-to-end on main pushes, same format as GITLAB_PR_LIBRARIES
67+
GITLAB_MAIN: dict[str, dict[str, list[str]] | None] = {
68+
"php": GITLAB_PR_LIBRARIES["php"],
69+
"python": None,
70+
}
6571
GITLAB_SSI_LIBRARIES = tuple(sorted(COMPONENT_GROUPS.ssi & COMPONENT_GROUPS.lib_injection))
6672

6773

@@ -224,15 +230,15 @@ def is_gitlab_pr_pipeline(inputs: Inputs) -> bool:
224230
return inputs.ref != "refs/heads/main" and inputs.event_name in ("pull_request", "push")
225231

226232

227-
def filter_gitlab_libraries(inputs: Inputs, libraries: set[str]) -> set[str]:
228-
"""Limit the GitLab end-to-end rollout by pipeline context."""
233+
def get_gitlab_libraries(inputs: Inputs) -> dict[str, dict[str, list[str]] | None]:
234+
"""Libraries of the GitLab end-to-end rollout for the pipeline context (see GITLAB_PR_LIBRARIES for the format)"""
229235
if inputs.ref == "refs/heads/main" and inputs.event_name != "schedule":
230-
return libraries & GITLAB_MAIN
236+
return GITLAB_MAIN
231237

232238
if is_gitlab_pr_pipeline(inputs):
233-
return libraries & set(GITLAB_PR_LIBRARIES)
239+
return GITLAB_PR_LIBRARIES
234240

235-
return set()
241+
return {}
236242

237243

238244
def _expand_scenario_entries(entries: Iterable[str]) -> set[str]:
@@ -247,18 +253,21 @@ def _expand_scenario_entries(entries: Iterable[str]) -> set[str]:
247253

248254

249255
def get_gitlab_library_weblog_scenarios(
250-
libraries: set[str], scenario_names: set[str], scenario_group_names: set[str]
256+
gitlab_libraries: dict[str, dict[str, list[str]] | None],
257+
libraries: set[str],
258+
scenario_names: set[str],
259+
scenario_group_names: set[str],
251260
) -> dict[str, dict[str, list[str]]]:
252-
"""Return the library_weblog_scenarios map of the GitLab PR pipeline, for the libraries with a weblog map.
261+
"""Return the library_weblog_scenarios map of the GitLab pipeline, for the selected libraries with a weblog map.
253262
254-
The weblog maps of GITLAB_PR_LIBRARIES are filtered by the scenarios selected from the diff: only selected
255-
scenarios are kept, and weblogs (and libraries) with no scenario left are removed.
263+
The weblog maps of gitlab_libraries are filtered by the selected scenarios: only selected scenarios are kept,
264+
and weblogs (and libraries) with no scenario left are removed.
256265
"""
257266
selected = _expand_scenario_entries(scenario_names | scenario_group_names)
258267

259268
result: dict[str, dict[str, list[str]]] = {}
260-
for library in sorted(libraries):
261-
weblog_map = GITLAB_PR_LIBRARIES[library]
269+
for library in sorted(libraries & set(gitlab_libraries)):
270+
weblog_map = gitlab_libraries[library]
262271
if not weblog_map:
263272
continue
264273
filtered_map: dict[str, list[str]] = {}
@@ -537,16 +546,19 @@ def process(inputs: Inputs) -> list[str]:
537546
ssi_libraries = get_gitlab_ssi_libraries(inputs.pr_title, library_processor.selected)
538547
outputs["ssi_libraries"] = " ".join(sorted(ssi_libraries))
539548

540-
gitlab_libraries = filter_gitlab_libraries(inputs, library_processor.selected)
541-
if is_gitlab_pr_pipeline(inputs):
542-
library_weblog_scenarios = get_gitlab_library_weblog_scenarios(
543-
gitlab_libraries, scenario_processor.scenarios, scenario_processor.scenario_groups
544-
)
545-
if library_weblog_scenarios:
546-
# JSON in a JSON string, so the output can still be sourced by a shell
547-
outputs["library_weblog_scenarios"] = json.dumps(library_weblog_scenarios)
548-
# libraries with a weblog map are only run through library_weblog_scenarios
549-
gitlab_libraries = {library for library in gitlab_libraries if not GITLAB_PR_LIBRARIES[library]}
549+
rollout = get_gitlab_libraries(inputs)
550+
library_weblog_scenarios = get_gitlab_library_weblog_scenarios(
551+
rollout, library_processor.selected, scenario_processor.scenarios, scenario_processor.scenario_groups
552+
)
553+
if library_weblog_scenarios:
554+
# JSON in a JSON string, so the output can still be sourced by a shell
555+
outputs["library_weblog_scenarios"] = json.dumps(library_weblog_scenarios)
556+
# libraries with a weblog map are only run through library_weblog_scenarios
557+
gitlab_libraries = {
558+
library
559+
for library, weblog_map in rollout.items()
560+
if library in library_processor.selected and not weblog_map
561+
}
550562
if gitlab_libraries:
551563
outputs["libraries"] = " ".join(sorted(gitlab_libraries))
552564
# also used by the SSI pipeline (compute_pipeline job)

‎utils/scripts/libraries_and_scenarios_rules.yml‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,8 @@ patterns:
396396
libraries: null
397397
utils/ci/github/*:
398398
scenarios: DEFAULT
399-
utils/ci/gitlab/*: # end-to-end GitLab pipeline, which only runs the c library on PRs
400-
libraries: c
401-
scenario_groups: end_to_end
402-
scenarios: PARAMETRIC
399+
utils/ci/gitlab/*: # end-to-end GitLab pipeline, which only runs these libraries on PRs (see GITLAB_PR_LIBRARIES)
400+
libraries: [c, php, python]
403401

404402
############################ Library-specific rules ############################
405403
# This section contains rules to apply to library-related files. It follows the

0 commit comments

Comments
 (0)