Skip to content

Commit b0d8d4e

Browse files
authored
Added a clean up step after release tagging (#24)
1 parent 2eff476 commit b0d8d4e

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

continuous_delivery_scripts/plugins/python.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ def can_get_project_metadata(self) -> bool:
165165
"""States whether project metadata can be retrieved."""
166166
return True
167167

168+
def should_include_spdx_in_package(self) -> bool:
169+
"""States whether the SPDX documents should be included in the package."""
170+
return True
171+
168172
def get_current_spdx_project(self) -> Optional[SpdxProject]:
169173
"""Gets the current SPDX description."""
170174
return _get_current_spdx_project()

continuous_delivery_scripts/tag_and_release.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def tag_and_release(mode: CommitType, current_branch: Optional[str] = None) -> N
5050
insert_licence_header(0)
5151
_update_repository(mode, is_new_version, version, current_branch)
5252
if is_new_version:
53-
if spdx_project:
53+
if spdx_project and get_language_specifics().should_include_spdx_in_package():
5454
_generate_spdx_reports(spdx_project)
5555
get_language_specifics().package_software(version)
5656
get_language_specifics().release_package_to_repository(version)
@@ -93,6 +93,9 @@ def _update_repository(mode: CommitType, is_new_version: bool, version: str, cur
9393
logger.info("Tagging commit")
9494
git.create_tag(get_language_specifics().get_version_tag(version), message=f"release {version}")
9595
git.force_push_tag()
96+
git.fetch()
97+
git.pull()
98+
git.clean()
9699

97100

98101
def _generate_spdx_reports(project: SpdxProject) -> None:

continuous_delivery_scripts/utils/git_helpers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,21 @@ def force_push_tag(self) -> None:
478478
"""
479479
self.repo.git.push(force=True, tags=True)
480480

481+
def is_dirty(self) -> bool:
482+
"""Determines whether repository is dirty.
483+
484+
Repository is considered dirty when git status returns elements which are not committed.
485+
"""
486+
return self.repo.is_dirty(untracked_files=True)
487+
488+
def clean(self) -> None:
489+
"""Cleans the repository.
490+
491+
Performs a force clean.
492+
"""
493+
if self.is_dirty():
494+
self.repo.git.clean(force=True, x=True, d=True)
495+
481496
def configure_for_github(self) -> None:
482497
"""Reconfigures the repository.
483498

continuous_delivery_scripts/utils/language_specifics_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def can_get_project_metadata(self) -> bool:
6565
"""States whether project metadata can be retrieved."""
6666
return False
6767

68+
def should_include_spdx_in_package(self) -> bool:
69+
"""States whether the SPDX documents should be included in the package."""
70+
return False
71+
6872
@abstractmethod
6973
def generate_code_documentation(self, output_directory: Path, module_to_document: str) -> None:
7074
"""Generates the code documentation."""

news/202108241231.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a clean repository step

tests/git_helper/test_git_helpers.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_current_branch(self):
7171
self.assertIsNone(groups)
7272

7373
def test_file_addition(self):
74-
"""Test basic git branch actions on the clone."""
74+
"""Test basic git add actions on the clone."""
7575
with ProjectTempClone(desired_branch_name="main") as clone:
7676
branch = clone.create_branch(f"test-{uuid4()}")
7777
clone.checkout(branch)
@@ -89,6 +89,22 @@ def test_file_addition(self):
8989
added_files = [Path(clone.root).joinpath(f) for f in clone.list_files_added_on_current_branch()]
9090
self.assertTrue(test_file in added_files)
9191

92+
def test_repo_clean(self):
93+
"""Test basic git clean on the clone."""
94+
with ProjectTempClone(desired_branch_name="main") as clone:
95+
branch = clone.create_branch(f"test-{uuid4()}")
96+
clone.checkout(branch)
97+
self.assertTrue(len(clone.list_files_added_on_current_branch()) == 0)
98+
test_file = Path(clone.root).joinpath(f"branch-test-{uuid4()}.txt")
99+
test_file.touch()
100+
uncommitted_changes = clone.uncommitted_changes
101+
self.assertTrue(test_file in uncommitted_changes)
102+
self.assertTrue(clone.is_dirty())
103+
clone.clean()
104+
self.assertFalse(clone.is_dirty())
105+
uncommitted_changes = clone.uncommitted_changes
106+
self.assertTrue(len(uncommitted_changes) == 0)
107+
92108
def test_file_addition_with_paths_to_initial_repository(self):
93109
"""Test basic git add on the clone."""
94110
git = ProjectGitWrapper()

0 commit comments

Comments
 (0)