-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.sh
executable file
·112 lines (95 loc) · 3.05 KB
/
publish.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
# Check if version argument is provided
if [ -z "$1" ]; then
echo "Please provide a version number (e.g., ./publish.sh 0.2.3)"
exit 1
fi
VERSION=$1
# Function to clean up backup files
cleanup_backups() {
find . -name "*''" -type f -delete
find . -name "*.tmp" -type f -delete
find . -name "*.bak" -type f -delete
}
# Initial cleanup of any existing backup files
cleanup_backups
# Check for .pypirc file
PYPIRC="$HOME/.pypirc"
if [ ! -f "$PYPIRC" ]; then
echo "Error: $PYPIRC not found!"
echo "Please create $PYPIRC with your PyPI credentials:"
echo "[pypi]"
echo "username = __token__"
echo "password = your-pypi-token"
exit 1
fi
# Check if .pypirc contains required sections
if ! grep -q "\[pypi\]" "$PYPIRC" || ! grep -q "username" "$PYPIRC" || ! grep -q "password" "$PYPIRC"; then
echo "Error: $PYPIRC is missing required configuration!"
echo "Please ensure it contains:"
echo "[pypi]"
echo "username = __token__"
echo "password = your-pypi-token"
exit 1
fi
# Function to check if command succeeded
check_status() {
if [ $? -ne 0 ]; then
echo "Error: $1"
cleanup_backups # Clean up on error
exit 1
fi
}
# Set up sed command based on OS
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS: create a temporary file and move it back
update_version() {
local file=$1
local pattern=$2
local replacement=$3
sed "s/$pattern/$replacement/" "$file" > "$file.tmp" && mv "$file.tmp" "$file"
cleanup_backups # Clean up after each update
}
else
# Linux: use sed -i directly
update_version() {
local file=$1
local pattern=$2
local replacement=$3
sed -i "s/$pattern/$replacement/" "$file"
cleanup_backups # Clean up after each update
}
fi
echo "Updating version to $VERSION..."
# Update version in pyproject.toml
update_version "pyproject.toml" "version = \".*\"" "version = \"$VERSION\""
check_status "Failed to update pyproject.toml"
# Update version in setup.py
update_version "setup.py" "version=\".*\"" "version=\"$VERSION\""
check_status "Failed to update setup.py"
# Update version in __init__.py
update_version "llm_catcher/__init__.py" "__version__ = \".*\"" "__version__ = \"$VERSION\""
check_status "Failed to update __init__.py"
# Clean previous builds
echo "Cleaning previous builds..."
rm -rf build/ dist/ *.egg-info/
check_status "Failed to clean previous builds"
# Build package
echo "Building package..."
python -m build
check_status "Failed to build package"
# Upload to PyPI
echo "Uploading to PyPI..."
python -m twine upload dist/*
check_status "Failed to upload to PyPI"
echo "Successfully updated version to $VERSION and uploaded to PyPI"
# Optional: Create git tag
read -p "Create git tag v$VERSION? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git add pyproject.toml setup.py llm_catcher/__init__.py
git commit -m "Bump version to $VERSION"
git tag -a "v$VERSION" -m "Version $VERSION"
git push && git push --tags
check_status "Failed to create git tag"
fi