-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdeploy-test-pypi.sh
More file actions
executable file
·50 lines (40 loc) · 1.69 KB
/
deploy-test-pypi.sh
File metadata and controls
executable file
·50 lines (40 loc) · 1.69 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
#!/bin/sh
# Get version from version.py
VERSION_FILE="socketdev/version.py"
ORIGINAL_VERSION=$(grep -o "__version__.*" $VERSION_FILE | awk '{print $3}' | sed 's/"//g' | sed "s/'//g" | tr -d '\r')
BACKUP_FILE="${VERSION_FILE}.bak"
# Get existing versions from TestPyPI
echo "Checking existing versions on TestPyPI..."
EXISTING_VERSIONS=$(curl -s https://test.pypi.org/pypi/socketdev/json | python -c "
import sys, json
data = json.load(sys.stdin)
versions = [v for v in data.get('releases', {}).keys() if v.startswith('$ORIGINAL_VERSION.dev')]
if versions:
versions.sort(key=lambda x: int(x.split('dev')[1]))
print(versions[-1])
")
# Determine new version
if [ -z "$EXISTING_VERSIONS" ]; then
VERSION="${ORIGINAL_VERSION}.dev1"
echo "No existing dev versions found. Using ${VERSION}"
else
LAST_DEV_NUM=$(echo $EXISTING_VERSIONS | grep -o 'dev[0-9]*' | grep -o '[0-9]*')
NEXT_DEV_NUM=$((LAST_DEV_NUM + 1))
VERSION="${ORIGINAL_VERSION}.dev${NEXT_DEV_NUM}"
echo "Found existing version ${EXISTING_VERSIONS}. Using ${VERSION}"
fi
echo "Deploying version ${VERSION} to Test PyPI"
# Backup original version.py
cp $VERSION_FILE $BACKUP_FILE
# Update version in version.py
sed -i.tmp "s/__version__ = [\"']${ORIGINAL_VERSION}[\"']/__version__ = '${VERSION}'/" $VERSION_FILE
rm "${VERSION_FILE}.tmp"
# Build and upload to test PyPI (with suppressed output)
python -m build --wheel --sdist > /dev/null 2>&1
# Restore original version.py
mv $BACKUP_FILE $VERSION_FILE
# Upload to TestPyPI
python -m twine upload --verbose --repository testpypi dist/*${VERSION}*
echo "Deployed to Test PyPI. Wait a few minutes before installing the new version."
echo -e "\nNew version deployed:"
echo "${VERSION}"