Skip to content

Commit

Permalink
Resolve id discrepancy when no component changes
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed Jan 24, 2024
1 parent ed5c31f commit 8f1b17c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/run_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down
11 changes: 9 additions & 2 deletions tests/test_run_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 8f1b17c

Please sign in to comment.