From 19efb305369bb05de04a657b7d498702e70a5fe0 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Fri, 12 Jan 2024 08:57:26 +0100 Subject: [PATCH 1/2] ci: print report url master/release pipelines does not have a mr comment, print it here --- tools/ci/dynamic_pipelines/report.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/ci/dynamic_pipelines/report.py b/tools/ci/dynamic_pipelines/report.py index 5ed2ab2605..a070c125c1 100644 --- a/tools/ci/dynamic_pipelines/report.py +++ b/tools/ci/dynamic_pipelines/report.py @@ -71,6 +71,7 @@ class ReportGenerator: Full {self.title} here: {url}/-/jobs/{job_id}/artifacts/{self.output_filepath} (with commit {commit_id}) ''' + print(comment) if self.mr is None: print('No MR found, skip posting comment') From b581d81fc1dea4f54eaab857a383b8e0673f7507 Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Sun, 14 Jan 2024 21:18:20 +0100 Subject: [PATCH 2/2] ci: support build only label --- tools/ci/dynamic_pipelines/constants.py | 2 ++ .../scripts/generate_build_child_pipeline.py | 3 +++ .../generate_target_test_child_pipeline.py | 23 +++++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tools/ci/dynamic_pipelines/constants.py b/tools/ci/dynamic_pipelines/constants.py index a90e6769f2..e583397a2c 100644 --- a/tools/ci/dynamic_pipelines/constants.py +++ b/tools/ci/dynamic_pipelines/constants.py @@ -29,3 +29,5 @@ TEST_RELATED_APPS_DOWNLOAD_URLS_FILENAME = 'test_related_apps_download_urls.yml' REPORT_TEMPLATE_FILEPATH = os.path.join( IDF_PATH, 'tools', 'ci', 'dynamic_pipelines', 'templates', 'report.template.html' ) + +BUILD_ONLY_LABEL = 'For Maintainers: Only Build Tests' diff --git a/tools/ci/dynamic_pipelines/scripts/generate_build_child_pipeline.py b/tools/ci/dynamic_pipelines/scripts/generate_build_child_pipeline.py index 5194d73671..c9b8d842de 100644 --- a/tools/ci/dynamic_pipelines/scripts/generate_build_child_pipeline.py +++ b/tools/ci/dynamic_pipelines/scripts/generate_build_child_pipeline.py @@ -100,6 +100,9 @@ def main(arguments: argparse.Namespace) -> None: ) build_jobs.append(non_test_apps_build_job) + if mr_labels := os.getenv('CI_MERGE_REQUEST_LABELS'): + print(f'MR labels: {mr_labels}') + # check if there's no jobs if not build_jobs: print('No apps need to be built. Create one empty job instead') diff --git a/tools/ci/dynamic_pipelines/scripts/generate_target_test_child_pipeline.py b/tools/ci/dynamic_pipelines/scripts/generate_target_test_child_pipeline.py index 28e8d335cd..e9eb70d6db 100644 --- a/tools/ci/dynamic_pipelines/scripts/generate_target_test_child_pipeline.py +++ b/tools/ci/dynamic_pipelines/scripts/generate_target_test_child_pipeline.py @@ -15,8 +15,8 @@ import typing as t from collections import Counter, defaultdict import __init__ # noqa: F401 # inject the system path -from dynamic_pipelines.constants import (DEFAULT_CASES_TEST_PER_JOB, DEFAULT_TARGET_TEST_CHILD_PIPELINE_FILEPATH, - DEFAULT_TEST_PATHS) +from dynamic_pipelines.constants import (BUILD_ONLY_LABEL, DEFAULT_CASES_TEST_PER_JOB, + DEFAULT_TARGET_TEST_CHILD_PIPELINE_FILEPATH, DEFAULT_TEST_PATHS) from dynamic_pipelines.models import EmptyJob, Job, TargetTestJob from dynamic_pipelines.utils import dump_jobs_to_yaml from gitlab.v4.objects import Project @@ -41,7 +41,17 @@ def get_tags_with_amount(s: str) -> t.List[str]: return sorted(res) -def generate_target_test_child_pipeline(project: Project, paths: str, apps: t.List[App], output_filepath: str) -> None: +def get_target_test_jobs(project: Project, paths: str, apps: t.List[App]) -> t.Tuple[t.List[Job], t.List[str]]: + """ + Return the target test jobs and the extra yaml files to include + """ + if mr_labels := os.getenv('CI_MERGE_REQUEST_LABELS'): + print(f'MR labels: {mr_labels}') + + if BUILD_ONLY_LABEL in mr_labels.split(','): + print('MR has build only label, skip generating target test child pipeline') + return [EmptyJob()], [] + pytest_cases = get_pytest_cases( paths, apps=apps, @@ -78,13 +88,18 @@ def generate_target_test_child_pipeline(project: Project, paths: str, apps: t.Li target_test_jobs.append(target_test_job) + extra_include_yml: t.List[str] = [] if not target_test_jobs: print('No target test cases required, create one empty job instead') target_test_jobs.append(EmptyJob()) - extra_include_yml = [] else: extra_include_yml = ['tools/ci/dynamic_pipelines/templates/generate_target_test_report.yml'] + return target_test_jobs, extra_include_yml + + +def generate_target_test_child_pipeline(project: Project, paths: str, apps: t.List[App], output_filepath: str) -> None: + target_test_jobs, extra_include_yml = get_target_test_jobs(project, paths, apps) dump_jobs_to_yaml(target_test_jobs, output_filepath, extra_include_yml) print(f'Generate child pipeline yaml file {output_filepath} with {sum(j.parallel for j in target_test_jobs)} jobs')