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..a3924233b6 100644 --- a/tests/test_run_build.py +++ b/tests/test_run_build.py @@ -259,16 +259,23 @@ 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("manifests.build_manifest.BuildManifest.from_path") @patch("run_build.BuildIncremental.rebuild_plugins", return_value=MagicMock()) @patch("run_build.logging.info") def test_build_incremental_no_change(self, mock_logging_info: MagicMock, - mock_build_incremental: MagicMock, *mocks: Any) -> None: + mock_build_incremental: MagicMock, mock_build_manifest: MagicMock, + *mocks: Any) -> None: mock_build_incremental.return_value = [] + mock_build_manifest.return_value = self.BUILD_MANIFEST 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"])