@@ -22,27 +22,42 @@ jobs:
22
22
- name : Install build dependencies
23
23
run : |
24
24
python -m pip install --upgrade pip
25
- pip install build twine packaging requests
25
+ pip install build twine packaging requests tomli
26
26
27
27
- name : Build package
28
28
run : python -m build
29
29
30
- # Get current version and package name
30
+ # Get current version and package name using Python
31
31
- name : Get package info
32
32
id : package_info
33
33
run : |
34
- if [ -f "pyproject.toml" ]; then
35
- VERSION=$(grep -Po "(?<=version = \")[^\"]*" pyproject.toml)
36
- PACKAGE_NAME=$(grep -Po "(?<=name = \")[^\"]*" pyproject.toml)
37
- elif [ -f "setup.py" ]; then
38
- VERSION=$(python setup.py --version)
39
- PACKAGE_NAME=$(python setup.py --name)
40
- else
41
- echo "No version file found"
42
- exit 1
43
- fi
44
- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
45
- echo "package_name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
34
+ python - <<EOF >> "$GITHUB_OUTPUT"
35
+ import tomli
36
+ import json
37
+
38
+ try:
39
+ with open("pyproject.toml", "rb") as f:
40
+ data = tomli.load(f)
41
+
42
+ # Handle different possible TOML structures
43
+ if "project" in data:
44
+ # PEP 621 metadata
45
+ version = data["project"]["version"]
46
+ name = data["project"]["name"]
47
+ elif "tool" in data and "poetry" in data["tool"]:
48
+ # Poetry metadata
49
+ version = data["tool"]["poetry"]["version"]
50
+ name = data["tool"]["poetry"]["name"]
51
+ else:
52
+ raise KeyError("Could not find version/name in pyproject.toml")
53
+
54
+ print(f"version={version}")
55
+ print(f"package_name={name}")
56
+
57
+ except Exception as e:
58
+ print(f"Error parsing pyproject.toml: {e}")
59
+ exit(1)
60
+ EOF
46
61
47
62
# Check PyPI version using API
48
63
- name : Check if version exists on PyPI
0 commit comments