1
+ #! /bin/sh
2
+
3
+ # Get version from version.py
4
+ VERSION_FILE=" socketdev/version.py"
5
+ ORIGINAL_VERSION=$( grep -o " __version__.*" $VERSION_FILE | awk ' {print $3}' | sed ' s/"//g' | sed " s/'//g" | tr -d ' \r' )
6
+ BACKUP_FILE=" ${VERSION_FILE} .bak"
7
+
8
+ # Get existing versions from TestPyPI
9
+ echo " Checking existing versions on TestPyPI..."
10
+ EXISTING_VERSIONS=$( curl -s https://test.pypi.org/pypi/socket-sdk-python/json | python -c "
11
+ import sys, json
12
+ data = json.load(sys.stdin)
13
+ versions = [v for v in data.get('releases', {}).keys() if v.startswith('$ORIGINAL_VERSION .dev')]
14
+ if versions:
15
+ versions.sort(key=lambda x: int(x.split('dev')[1]))
16
+ print(versions[-1])
17
+ " )
18
+
19
+ # Determine new version
20
+ if [ -z " $EXISTING_VERSIONS " ]; then
21
+ VERSION=" ${ORIGINAL_VERSION} .dev1"
22
+ echo " No existing dev versions found. Using ${VERSION} "
23
+ else
24
+ LAST_DEV_NUM=$( echo $EXISTING_VERSIONS | grep -o ' dev[0-9]*' | grep -o ' [0-9]*' )
25
+ NEXT_DEV_NUM=$(( LAST_DEV_NUM + 1 ))
26
+ VERSION=" ${ORIGINAL_VERSION} .dev${NEXT_DEV_NUM} "
27
+ echo " Found existing version ${EXISTING_VERSIONS} . Using ${VERSION} "
28
+ fi
29
+
30
+ echo " Deploying version ${VERSION} to Test PyPI"
31
+
32
+ # Backup original version.py
33
+ cp $VERSION_FILE $BACKUP_FILE
34
+
35
+ # Update version in version.py
36
+ sed -i.tmp " s/__version__ = [\" ']${ORIGINAL_VERSION} [\" ']/__version__ = '${VERSION} '/" $VERSION_FILE
37
+ rm " ${VERSION_FILE} .tmp"
38
+
39
+ # Build and upload to test PyPI (with suppressed output)
40
+ python -m build --wheel --sdist > /dev/null 2>&1
41
+
42
+ # Restore original version.py
43
+ mv $BACKUP_FILE $VERSION_FILE
44
+
45
+ # Upload to TestPyPI
46
+ python -m twine upload --verbose --repository testpypi dist/* ${VERSION} *
47
+
48
+ echo " Deployed to Test PyPI. Wait a few minutes before installing the new version."
49
+ echo -e " \nNew version deployed:"
50
+ echo " ${VERSION} "
0 commit comments