Skip to content

Commit

Permalink
chore: Fix publish pipeline (#45)
Browse files Browse the repository at this point in the history
* feat: Add nada-mir-proto package and initial uv support

* chore: Fix publish pipeline
  • Loading branch information
navasvarela authored Nov 6, 2024
1 parent 1564c77 commit 03d0631
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ dev-dependencies = [
"pytest-cov>=4,<6",
"pylint>=2.17,<3.4",
"nada-mir-proto[dev]",
"tomli",
"requests",
]

[tool.uv.sources]
Expand Down
43 changes: 43 additions & 0 deletions scripts/version_checker.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 4 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 03d0631

Please sign in to comment.