diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1baa20a..8977f4b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,25 +23,28 @@ jobs: local_nada_mir_version_is_higher: ${{ steps.versioncheck_nada_mir.outputs.local_version_is_higher }} steps: - uses: actions/checkout@v4 - + - name: Install uv + uses: astral-sh/setup-uv@v3 + with: + version: "0.4.24" + - name: Install dependencies + run: uv sync --all-extras --dev - name: Check pypi versions - uses: maybe-hello-world/pyproject-check-version@v4 id: versioncheck - with: - pyproject-path: "./pyproject.toml" + run: >- + python scripts/version_checker.py "./pyproject.toml" - name: Check pypi versions - uses: maybe-hello-world/pyproject-check-version@v4 id: versioncheck_nada_mir - with: - pyproject-path: "nada_mir/pyproject.toml" + run: >- + python scripts/version_checker.py "nada_mir/pyproject.toml" - name: check output run: | echo "Output: ${{ steps.versioncheck.outputs.local_version_is_higher }}" # 'true' or 'false echo "Local version: ${{ steps.versioncheck.outputs.local_version }}" # e.g., 0.1.1 echo "Public version: ${{ steps.versioncheck.outputs.public_version }}" # e.g., 0.1.0 - echo "nada_mir Output: ${{ steps.versioncheck.outputs.local_version_is_higher }}" # 'true' or 'false" + echo "nada_mir Output: ${{ steps.versioncheck_nada_mir.outputs.local_version_is_higher }}" # 'true' or 'false" # Build distribution files build-distribution: @@ -85,7 +88,7 @@ jobs: uses: astral-sh/setup-uv@v3 with: version: "0.4.24" - - name: Install pypa/build + - name: Build package run: >- uv build --package nada-mir-proto -o nada_mir/dist - name: Store the distribution packages diff --git a/pyproject.toml b/pyproject.toml index aab480b..d61485b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,8 @@ dev-dependencies = [ "pytest-cov>=4,<6", "pylint>=2.17,<3.4", "nada-mir-proto[dev]", + "tomli", + "requests", ] [tool.uv.sources] diff --git a/scripts/version_checker.py b/scripts/version_checker.py new file mode 100644 index 0000000..ca98665 --- /dev/null +++ b/scripts/version_checker.py @@ -0,0 +1,43 @@ +# Checks python package version +# Based on https://github.com/maybe-hello-world/pyproject-check-version/blob/v4/version_checker.py +import re +import sys +import tomli +import os +import requests +from packaging import version +import json + +from packaging.version import Version + + +def get_public_version(project_name: str, is_test=False) -> Version: + response = requests.get( + f'https://{"test." if is_test else ""}pypi.org/pypi/{project_name}/json' + ) + if response.status_code == 200: + return version.parse(json.loads(response.content)["info"]["version"]) + else: + return Version("0.0") + + +if __name__ == "__main__": + pyproject_toml_path = sys.argv[1] + test_regex = sys.argv[2] + with open(pyproject_toml_path, "rb") as f: + project = tomli.load(f) + + project_version = version.parse(project["project"]["version"]) + is_test = False + if test_regex: + if re.compile(test_regex).search(str(project_version)): + is_test = True + public_project_version = get_public_version(project["project"]["name"], is_test) + + with open(os.environ["GITHUB_OUTPUT"], "at") as f: + f.write( + f"local_version_is_higher={str(project_version > public_project_version).lower()}\n" + ) + f.write(f"local_version={str(project_version)}\n") + f.write(f"public_version={str(public_project_version)}\n") + f.write(f"is_test={str(is_test).lower()}\n") diff --git a/uv.lock b/uv.lock index 95776db..0692ce9 100644 --- a/uv.lock +++ b/uv.lock @@ -648,9 +648,11 @@ dev = [ { name = "pylint" }, { name = "pytest" }, { name = "pytest-cov" }, + { name = "requests" }, { name = "sphinx" }, { name = "sphinx-rtd-theme" }, { name = "toml" }, + { name = "tomli" }, ] [package.metadata] @@ -673,9 +675,11 @@ dev = [ { name = "pylint", specifier = ">=2.17,<3.4" }, { name = "pytest", specifier = ">=7.4,<9.0" }, { name = "pytest-cov", specifier = ">=4,<6" }, + { name = "requests" }, { name = "sphinx", specifier = ">=5,<9" }, { name = "sphinx-rtd-theme", specifier = ">=1.0,<3.1" }, { name = "toml", specifier = "~=0.10.2" }, + { name = "tomli" }, ] [[package]]