From 4c5062b6e00002d44847270c0d680f5fcc055bf8 Mon Sep 17 00:00:00 2001 From: Zelin Hao Date: Tue, 23 Jan 2024 15:57:11 -0800 Subject: [PATCH] Resolve id discrepancy when no component changes Signed-off-by: Zelin Hao --- src/run_build.py | 18 +++++++++++------- tests/test_run_build.py | 6 +++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/run_build.py b/src/run_build.py index cf4e590f21..e58c633baf 100755 --- a/src/run_build.py +++ b/src/run_build.py @@ -9,6 +9,7 @@ import logging import os import sys +import uuid from build_workflow.build_args import BuildArgs from build_workflow.build_incremental import BuildIncremental @@ -49,19 +50,22 @@ def main() -> int: buildIncremental = BuildIncremental(manifest, args.distribution) list_of_updated_plugins = buildIncremental.commits_diff(manifest) components = buildIncremental.rebuild_plugins(list_of_updated_plugins, manifest) - if not components: - logging.info("No commit difference found between any components. Skipping the build") - return 0 - - logging.info(f"Plugins for incremental build: {components}") build_manifest_path = os.path.join(args.distribution, "builds", manifest.build.filename, "manifest.yml") if not os.path.exists(build_manifest_path): logging.error(f"Previous build manifest missing at path: {build_manifest_path}") + build_manifest = BuildManifest.from_path(build_manifest_path) - logging.info(f"Build {components} incrementally.") + if not components: + logging.info("No commit difference found between any components. Skipping the build.") + build_manifest.build.id = os.getenv("BUILD_NUMBER") or uuid.uuid4().hex + build_manifest.to_file(build_manifest_path) + logging.info(f"Updating the build ID of build manifest to {build_manifest.build.id}.") + return 0 - build_manifest = BuildManifest.from_path(build_manifest_path) + logging.info(f"Plugins for incremental build: {components}") + + logging.info(f"Build {components} incrementally.") with TemporaryDirectory(keep=args.keep, chdir=True) as work_dir: logging.info(f"Building in {work_dir.name}") diff --git a/tests/test_run_build.py b/tests/test_run_build.py index 92443f9618..b616334882 100644 --- a/tests/test_run_build.py +++ b/tests/test_run_build.py @@ -259,6 +259,7 @@ def test_main_incremental(self, mock_build_incremental: MagicMock, mock_temp: Ma mock_build_incremental.return_value.commits_diff.assert_called() mock_build_incremental.return_value.rebuild_plugins.assert_called() + @patch.dict(os.environ, {"BUILD_NUMBER": "1234"}) @patch("argparse._sys.argv", ["run_build.py", INPUT_MANIFEST_PATH, "--incremental", "-p", "linux"]) @patch("run_build.BuildIncremental.commits_diff", return_value=MagicMock()) @patch("run_build.BuildIncremental.rebuild_plugins", return_value=MagicMock()) @@ -268,7 +269,10 @@ def test_build_incremental_no_change(self, mock_logging_info: MagicMock, mock_build_incremental.return_value = [] main() mock_logging_info.assert_has_calls([ - call("No commit difference found between any components. Skipping the build") + call("No commit difference found between any components. Skipping the build.") + ], any_order=True) + mock_logging_info.assert_has_calls([ + call("Updating the build ID of build manifest to 1234.") ], any_order=True) @patch("argparse._sys.argv", ["run_build.py", INPUT_MANIFEST_PATH, "--incremental"])