-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(action): add check for package versions
- Loading branch information
Showing
12 changed files
with
397 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: CI | ||
|
||
on: [ push ] | ||
|
||
jobs: | ||
lint-and-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: moneymeets/action-setup-python-poetry@master | ||
|
||
- uses: moneymeets/moneymeets-composite-actions/lint-python@master | ||
|
||
- run: poetry run python -m pytest --cov --cov-fail-under=45 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="invalid_package_versions" type="PythonConfigurationType" factoryName="Python"> | ||
<module name="action-setup-python-poetry" /> | ||
<option name="ENV_FILES" value="" /> | ||
<option name="INTERPRETER_OPTIONS" value="" /> | ||
<option name="PARENT_ENVS" value="true" /> | ||
<envs> | ||
<env name="PYTHONUNBUFFERED" value="1" /> | ||
</envs> | ||
<option name="SDK_HOME" value="" /> | ||
<option name="SDK_NAME" value="Python 3.12" /> | ||
<option name="WORKING_DIRECTORY" value="" /> | ||
<option name="IS_MODULE_SDK" value="false" /> | ||
<option name="ADD_CONTENT_ROOTS" value="true" /> | ||
<option name="ADD_SOURCE_ROOTS" value="true" /> | ||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" /> | ||
<option name="SCRIPT_NAME" value="action_setup_python_poetry.invalid_package_versions" /> | ||
<option name="PARAMETERS" value="" /> | ||
<option name="SHOW_COMMAND_LINE" value="false" /> | ||
<option name="EMULATE_TERMINAL" value="false" /> | ||
<option name="MODULE_MODE" value="true" /> | ||
<option name="REDIRECT_INPUT" value="false" /> | ||
<option name="INPUT_FILE" value="" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import itertools | ||
import sys | ||
import tomllib | ||
from pathlib import Path | ||
from typing import Sequence | ||
|
||
|
||
def get_version(version: str | dict) -> str | None: | ||
return version if isinstance(version, str) else version.get("version") | ||
|
||
|
||
def get_invalid_package_versions(pyproject_toml_file_text: str) -> Sequence[tuple[str, str]]: | ||
toml_file_text = "\n".join( | ||
tuple(line for line in pyproject_toml_file_text.splitlines() if "@mm-version-check-ignore" not in line), | ||
) | ||
pyproject_data = tomllib.loads(toml_file_text) | ||
poetry_data = pyproject_data["tool"]["poetry"] | ||
|
||
return tuple( | ||
(package, version_str) | ||
for package, version in ( | ||
*poetry_data["dependencies"].items(), | ||
*poetry_data["dev-dependencies"].items(), | ||
*itertools.chain.from_iterable( | ||
(group["dependencies"].items() for _, group in poetry_data.get("group", {}).items()), | ||
), | ||
) | ||
if (version_str := get_version(version)) not in ("*", None) and not version_str.startswith("~") | ||
) | ||
|
||
|
||
def main(): | ||
if invalid_versions := get_invalid_package_versions(Path("pyproject.toml").read_text()): | ||
print(f"Invalid package versions found in pyproject.toml: {invalid_versions}") | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
Empty file.
34 changes: 34 additions & 0 deletions
34
action_setup_python_poetry/tests/data/pyproject_mock_invalid.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[tool.poetry] | ||
name = "test-project" | ||
version = "0.1.0" | ||
description = "Testing only" | ||
authors = ["moneymeets GmbH <service@moneymeets.com>"] | ||
|
||
|
||
[tool.poetry.scripts] | ||
merge_checks_runner = 'invalid_package_versions.runner:run' | ||
|
||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.12" | ||
boto3 = ">=1.26.148" # @mm-version-check-ignore | ||
|
||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = ">=8" | ||
pytest-cov = "*" | ||
|
||
ruff = "*" | ||
|
||
|
||
[tool.poetry.group.test-group-1.dependencies] | ||
test-package-1 = ">=1" | ||
|
||
|
||
[tool.poetry.group.test-group-2.dependencies] | ||
test-package-2 = ">=1" | ||
|
||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
34 changes: 34 additions & 0 deletions
34
action_setup_python_poetry/tests/data/pyproject_mock_valid.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[tool.poetry] | ||
name = "test-project" | ||
version = "0.1.0" | ||
description = "Testing only" | ||
authors = ["moneymeets GmbH <service@moneymeets.com>"] | ||
|
||
|
||
[tool.poetry.scripts] | ||
merge_checks_runner = 'invalid_package_versions.runner:run' | ||
|
||
|
||
[tool.poetry.dependencies] | ||
python = "~3.12" | ||
boto3 = ">=1.26.148" # @mm-version-check-ignore | ||
|
||
|
||
[tool.poetry.dev-dependencies] | ||
pytest = "*" | ||
pytest-cov = "*" | ||
|
||
ruff = "*" | ||
|
||
|
||
[tool.poetry.group.test-group-1.dependencies] | ||
test-package-1 = "*" | ||
|
||
|
||
[tool.poetry.group.test-group-2.dependencies] | ||
test-package-2 = "*" | ||
|
||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" |
25 changes: 25 additions & 0 deletions
25
action_setup_python_poetry/tests/test_get_invalid_package_versions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pathlib import Path | ||
from unittest import TestCase | ||
|
||
from action_setup_python_poetry.invalid_package_versions import get_invalid_package_versions | ||
|
||
TEST_DATA_DIR = Path(__file__).parent / "data" | ||
|
||
|
||
class GetInvalidPackageVersionsTest(TestCase): | ||
valid_pyproject_toml = (TEST_DATA_DIR / "pyproject_mock_valid.toml").read_text() | ||
invalid_pyproject_toml = (TEST_DATA_DIR / "pyproject_mock_invalid.toml").read_text() | ||
|
||
def test_get_invalid_package_versions_success(self): | ||
self.assertEqual((), get_invalid_package_versions(self.valid_pyproject_toml)) | ||
|
||
def test_get_invalid_package_versions_failed(self): | ||
self.assertEqual( | ||
( | ||
("python", ">=3.12"), | ||
("pytest", ">=8"), | ||
("test-package-1", ">=1"), | ||
("test-package-2", ">=1"), | ||
), | ||
get_invalid_package_versions(self.invalid_pyproject_toml), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from unittest import TestCase | ||
|
||
from action_setup_python_poetry.invalid_package_versions import get_version | ||
|
||
|
||
class GetVersionTest(TestCase): | ||
def test_get_version_success(self): | ||
self.assertEqual("*", get_version("*")) | ||
self.assertEqual("*", get_version({"version": "*"})) | ||
|
||
def test_get_version_failed(self): | ||
self.assertEqual(None, get_version({})) |
Oops, something went wrong.