-
Notifications
You must be signed in to change notification settings - Fork 61
95 lines (81 loc) · 2.78 KB
/
_Version.yml
File metadata and controls
95 lines (81 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: _Check version
on:
workflow_call:
inputs:
skipper:
type: string
required: false
env:
PROJECT: PyMca5
PROJECT_LOWER: pymca5
jobs:
check-version-exists:
runs-on: ubuntu-latest
if: ${{ inputs.skipper != 'dry-run' }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip requests
- name: Extract version from __init__.py
id: extract_version
shell: python
run: |
import os
path = 'src/PyMca5/__init__.py'
version = None
with open(path, 'r') as f:
for line in f:
if line.startswith('__version__'):
version = line.replace(' ', '').split('=')[-1].strip().strip('"\'')
break
assert version is not None, "Version not found in __init__.py"
print(version)
# Save version to GitHub output
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"version={version}\n")
- name: Check if git tag exists for the version
run: |
VERSION=${{ steps.extract_version.outputs.version }}
TAG="v$VERSION"
git fetch --tags
if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then
echo "❌ Git tag '$TAG' already exists."
exit 1
else
echo "✅ Git tag '$TAG' does not exist."
fi
- name: Check if version exists on PyPI and TestPyPI
env:
PACKAGE_NAME: ${{ env.PROJECT_LOWER }}
VERSION: ${{ steps.extract_version.outputs.version }}
shell: python
run: |
import requests
version = "${{ env.VERSION }}"
pkg_name = "${{ env.PACKAGE_NAME }}"
def version_exists(index_url):
url = f"{index_url}/{pkg_name}/json"
response = requests.get(url)
if response.status_code != 200:
return False
data = response.json()
return version in data.get("releases", {})
exists_pypi = version_exists("https://pypi.org/pypi")
exists_testpypi = version_exists("https://test.pypi.org/pypi")
if exists_pypi or exists_testpypi:
print(f"❌ Version {version} already exists on PyPI and/or TestPyPI")
exit(1)
else:
print(f"✅ Version {version} is new and OK to publish")
skipper:
runs-on: ubuntu-latest
if: ${{ inputs.skipper == 'dry-run' }}
steps:
- name: Pass
run: echo "Skipping version check because of dry-run"