Update publish.yml (#16967)
This commit is contained in:
parent
03a1f58e03
commit
822e5a5e70
1 changed files with 2 additions and 40 deletions
42
.github/workflows/publish.yml
vendored
42
.github/workflows/publish.yml
vendored
|
|
@ -41,49 +41,11 @@ jobs:
|
||||||
shell: python
|
shell: python
|
||||||
run: |
|
run: |
|
||||||
import os
|
import os
|
||||||
import requests
|
from actions.utils import check_pypi_version
|
||||||
import toml
|
local_version, online_version, publish = check_pypi_version()
|
||||||
|
|
||||||
# Load version and package name from pyproject.toml
|
|
||||||
pyproject = toml.load('pyproject.toml')
|
|
||||||
package_name = pyproject['project']['name']
|
|
||||||
local_version = pyproject['project'].get('version', 'dynamic')
|
|
||||||
|
|
||||||
# If version is dynamic, extract it from the specified file
|
|
||||||
if local_version == 'dynamic':
|
|
||||||
version_attr = pyproject['tool']['setuptools']['dynamic']['version']['attr']
|
|
||||||
module_path, attr_name = version_attr.rsplit('.', 1)
|
|
||||||
with open(f"{module_path.replace('.', '/')}/__init__.py") as f:
|
|
||||||
local_version = next(line.split('=')[1].strip().strip("'\"") for line in f if line.startswith(attr_name))
|
|
||||||
|
|
||||||
print(f"Local Version: {local_version}")
|
|
||||||
|
|
||||||
# Get online version from PyPI
|
|
||||||
response = requests.get(f"https://pypi.org/pypi/{package_name}/json")
|
|
||||||
online_version = response.json()['info']['version'] if response.status_code == 200 else None
|
|
||||||
print(f"Online Version: {online_version or 'Not Found'}")
|
|
||||||
|
|
||||||
# Determine if a new version should be published
|
|
||||||
publish = False
|
|
||||||
if online_version:
|
|
||||||
local_ver = tuple(map(int, local_version.split('.')))
|
|
||||||
online_ver = tuple(map(int, online_version.split('.')))
|
|
||||||
major_diff = local_ver[0] - online_ver[0]
|
|
||||||
minor_diff = local_ver[1] - online_ver[1]
|
|
||||||
patch_diff = local_ver[2] - online_ver[2]
|
|
||||||
|
|
||||||
publish = (
|
|
||||||
(major_diff == 0 and minor_diff == 0 and 0 < patch_diff <= 2) or
|
|
||||||
(major_diff == 0 and minor_diff == 1 and local_ver[2] == 0) or
|
|
||||||
(major_diff == 1 and local_ver[1] == 0 and local_ver[2] == 0)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
publish = True # First release
|
|
||||||
|
|
||||||
os.system(f'echo "increment={publish}" >> $GITHUB_OUTPUT')
|
os.system(f'echo "increment={publish}" >> $GITHUB_OUTPUT')
|
||||||
os.system(f'echo "current_tag=v{local_version}" >> $GITHUB_OUTPUT')
|
os.system(f'echo "current_tag=v{local_version}" >> $GITHUB_OUTPUT')
|
||||||
os.system(f'echo "previous_tag=v{online_version}" >> $GITHUB_OUTPUT')
|
os.system(f'echo "previous_tag=v{online_version}" >> $GITHUB_OUTPUT')
|
||||||
|
|
||||||
if publish:
|
if publish:
|
||||||
print('Ready to publish new version to PyPI ✅.')
|
print('Ready to publish new version to PyPI ✅.')
|
||||||
id: check_pypi
|
id: check_pypi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue