Skip to content

Commit

Permalink
Change: List changed files in VersionUpdate class
Browse files Browse the repository at this point in the history
Allow to track the changed files during a version update.
  • Loading branch information
bjoernricks committed Feb 14, 2023
1 parent ca005fa commit 514af2f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 20 deletions.
6 changes: 5 additions & 1 deletion pontos/version/cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def update_version(

new_content = cmvp.update_version(new_version, develop=develop)
self.project_file_path.write_text(new_content, encoding="utf-8")
return VersionUpdate(previous=previous_version, new=new_version)
return VersionUpdate(
previous=previous_version,
new=new_version,
changed_files=[self.project_file_path],
)

def get_current_version(self) -> str:
content = self.project_file_path.read_text(encoding="utf-8")
Expand Down
9 changes: 6 additions & 3 deletions pontos/version/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ def update_version(
try:
current_version = self.get_current_version()
except VersionError:
git = Git()
current_version = git.list_tags(sort=TagSort.VERSION)[-1]
current_version = Git().list_tags(sort=TagSort.VERSION)[-1]

if not force and versions_equal(new_version, current_version):
return VersionUpdate(previous=current_version, new=new_version)

self._update_version_file(new_version=new_version)

return VersionUpdate(previous=current_version, new=new_version)
return VersionUpdate(
previous=current_version,
new=new_version,
changed_files=[self.version_file_path],
)
38 changes: 24 additions & 14 deletions pontos/version/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,24 @@ def _update_package_json(self, new_version: str) -> None:
except json.JSONDecodeError as e:
raise VersionError("Couldn't load JSON") from e

def _update_version_file(self, new_version: str) -> None:
def _update_version_file(self, new_version: str) -> bool:
"""
Update the version file with the new version
"""
if GREENBONE_JS_VERSION_FILE.exists():
content = GREENBONE_JS_VERSION_FILE.read_text(encoding="utf-8")
content = re.sub(
pattern=(
r'VERSION = (?P<quote>[\'"])[\d+\.]{2,3}'
r"{.dev[\d]}(?P=quote);"
),
repl=f"VERSION = {new_version};",
string=content,
)
GREENBONE_JS_VERSION_FILE.write_text(content, encoding="utf-8")
if not GREENBONE_JS_VERSION_FILE.exists():
return False

content = GREENBONE_JS_VERSION_FILE.read_text(encoding="utf-8")
content = re.sub(
pattern=(
r'VERSION = (?P<quote>[\'"])[\d+\.]{2,3}'
r"{.dev[\d]}(?P=quote);"
),
repl=f"VERSION = {new_version};",
string=content,
)
GREENBONE_JS_VERSION_FILE.write_text(content, encoding="utf-8")
return True

def update_version(
self, new_version: str, *, develop: bool = False, force: bool = False
Expand All @@ -132,8 +135,15 @@ def update_version(
if not force and versions_equal(new_version, package_version):
return VersionUpdate(previous=package_version, new=new_version)

changed_files = [self.project_file_path]
self._update_package_json(new_version=new_version)

self._update_version_file(new_version=new_version)
updated = self._update_version_file(new_version=new_version)
if updated:
changed_files.append(GREENBONE_JS_VERSION_FILE)

return VersionUpdate(previous=package_version, new=new_version)
return VersionUpdate(
previous=package_version,
new=new_version,
changed_files=changed_files,
)
6 changes: 5 additions & 1 deletion pontos/version/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,8 @@ def update_version(

self._update_version_file(new_version=new_version)

return VersionUpdate(previous=current_version, new=new_version)
return VersionUpdate(
previous=current_version,
new=new_version,
changed_files=[self.version_file_path, self.project_file_path],
)
3 changes: 2 additions & 1 deletion pontos/version/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from abc import ABC, abstractmethod
from dataclasses import dataclass
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional

Expand All @@ -25,6 +25,7 @@
class VersionUpdate:
previous: str
new: str
changed_files: list[Path] = field(default_factory=list)


class VersionCommand(ABC):
Expand Down

0 comments on commit 514af2f

Please sign in to comment.