Skip to content

Commit 629af09

Browse files
authored
Update python-publish.yml
1 parent 534baa8 commit 629af09

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

.github/workflows/python-publish.yml

+29-25
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ jobs:
3131
- name: Get package info
3232
id: package_info
3333
run: |
34-
python - <<EOF >> "$GITHUB_OUTPUT"
34+
python - <<EOF
3535
import tomli
3636
import json
37+
import os
3738
3839
try:
3940
with open("pyproject.toml", "rb") as f:
@@ -50,9 +51,10 @@ jobs:
5051
name = data["tool"]["poetry"]["name"]
5152
else:
5253
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)
5658
5759
except Exception as e:
5860
print(f"Error parsing pyproject.toml: {e}")
@@ -63,7 +65,7 @@ jobs:
6365
- name: Check if version exists on PyPI
6466
id: check_version
6567
run: |
66-
python - <<EOF >> "$GITHUB_OUTPUT"
68+
python - <<EOF
6769
import requests
6870
import sys
6971
import os
@@ -78,27 +80,29 @@ jobs:
7880
url = f"https://pypi.org/pypi/{package_name}/json"
7981
response = requests.get(url)
8082
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', {})
9588
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)
102106
EOF
103107
env:
104108
PACKAGE_NAME: ${{ steps.package_info.outputs.package_name }}

0 commit comments

Comments
 (0)