Skip to content

Commit

Permalink
ci/package_checks: add check for package version being a string
Browse files Browse the repository at this point in the history
Ensure that package versions are always strings and not numbers,
as might happen with versions like '1.2' and '20230102'.
  • Loading branch information
silkeh committed Dec 3, 2023
1 parent d481715 commit ba24373
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions common/CI/package_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,22 @@ def _check_path(self, path: str) -> bool:
return path.split('/') == exp


class PackageVersion(PullRequestCheck):
_error = 'Package version is not a string'
_level = Level.ERROR

def run(self) -> List[Result]:
return [Result(message=self._error, level=self._level,
file=path, line=self.file_line(path, r'^version\s*:'),)
for path in self.package_files
if not self._check_version(path)]

def _check_version(self, path: str) -> bool:
version = self.load_package_yml(path)['version']

return isinstance(version, str)


class Patch(PullRequestCheck):
_regex = r'patch -p1 <'
_error = 'Uses `patch <`, use `patch -i` instead'
Expand Down

0 comments on commit ba24373

Please sign in to comment.