31
31
- name : Get package info
32
32
id : package_info
33
33
run : |
34
- python - <<EOF >> "$GITHUB_OUTPUT"
34
+ python - <<EOF
35
35
import tomli
36
36
import json
37
+ import os
37
38
38
39
try:
39
40
with open("pyproject.toml", "rb") as f:
50
51
name = data["tool"]["poetry"]["name"]
51
52
else:
52
53
raise KeyError("Could not find version/name in pyproject.toml")
53
-
54
- print(f"version={version}")
55
- print(f"package_name={name}")
54
+
55
+ with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
56
+ print(f"version={version}", file=fh)
57
+ print(f"package_name={name}", file=fh)
56
58
57
59
except Exception as e:
58
60
print(f"Error parsing pyproject.toml: {e}")
63
65
- name : Check if version exists on PyPI
64
66
id : check_version
65
67
run : |
66
- python - <<EOF >> "$GITHUB_OUTPUT"
68
+ python - <<EOF
67
69
import requests
68
70
import sys
69
71
import os
@@ -78,27 +80,29 @@ jobs:
78
80
url = f"https://pypi.org/pypi/{package_name}/json"
79
81
response = requests.get(url)
80
82
81
- if response.status_code == 200:
82
- data = response.json()
83
- releases = data.get('releases', {})
84
-
85
- # Normalize the version for comparison
86
- current_ver = packaging_version.parse(current_version)
87
-
88
- # Check if version exists
89
- if str(current_ver) in releases:
90
- print("Version already exists on PyPI")
91
- print("should_publish=false")
92
- else:
93
- print("Version is new")
94
- print("should_publish=true")
83
+ # Open the GitHub output file in append mode
84
+ with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
85
+ if response.status_code == 200:
86
+ data = response.json()
87
+ releases = data.get('releases', {})
95
88
96
- elif response.status_code == 404:
97
- print("Package not found on PyPI - this is a new package")
98
- print("should_publish=true")
99
- else:
100
- print(f"Error checking PyPI API: HTTP status {response.status_code}")
101
- sys.exit(1)
89
+ # Normalize the version for comparison
90
+ current_ver = packaging_version.parse(current_version)
91
+
92
+ # Check if version exists
93
+ if str(current_ver) in releases:
94
+ print("Version already exists on PyPI")
95
+ print("should_publish=false", file=fh)
96
+ else:
97
+ print("Version is new")
98
+ print("should_publish=true", file=fh)
99
+
100
+ elif response.status_code == 404:
101
+ print("Package not found on PyPI - this is a new package")
102
+ print("should_publish=true", file=fh)
103
+ else:
104
+ print(f"Error checking PyPI API: HTTP status {response.status_code}")
105
+ sys.exit(1)
102
106
EOF
103
107
env :
104
108
PACKAGE_NAME : ${{ steps.package_info.outputs.package_name }}
0 commit comments