-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdeploy-test-pypi.sh
More file actions
executable file
·60 lines (50 loc) · 1.95 KB
/
deploy-test-pypi.sh
File metadata and controls
executable file
·60 lines (50 loc) · 1.95 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
#!/bin/sh
# This script finds the latest dev version on TestPyPI, increments the dev version, and then uploads the new version to TestPyPI
# Get version from __init__.py
INIT_FILE="socketsecurity/__init__.py"
ORIGINAL_VERSION=$(grep -o "__version__.*" $INIT_FILE | awk '{print $3}' | tr -d "'")
BACKUP_FILE="${INIT_FILE}.bak"
# Get existing versions from TestPyPI
echo "Checking existing versions on TestPyPI..."
EXISTING_VERSIONS=$(curl -s https://test.pypi.org/pypi/socketsecurity/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')]
print('Filtered versions:', versions, file=sys.stderr)
if versions:
versions.sort(key=lambda x: int(x.split('dev')[1]))
print('Sorted versions:', versions, file=sys.stderr)
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 __init__.py
cp $INIT_FILE $BACKUP_FILE
# Update version in __init__.py
sed -i.tmp "s/__version__ = '${ORIGINAL_VERSION}'/__version__ = '${VERSION}'/" $INIT_FILE
rm "${INIT_FILE}.tmp"
# Build and upload to test PyPI
python -m build --wheel --sdist > /dev/null 2>&1
# Restore original __init__.py
mv $BACKUP_FILE $INIT_FILE
# Upload to TestPyPI using python -m
if python -m twine upload --repository testpypi dist/*${VERSION}*; then
echo
echo "Deployed to Test PyPI. Wait a few minutes before installing the new version."
echo
echo "New version:"
echo "${VERSION}"
else
echo
echo "Failed to deploy to Test PyPI"
exit 1
fi