-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish_package.sh
executable file
·57 lines (45 loc) · 1.48 KB
/
publish_package.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
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Use Python from virtual environment or system
PYTHON="/opt/homebrew/opt/[email protected]/bin/python3.11"
echo -e "${GREEN}Starting package publication process...${NC}"
# Ensure we're in the correct directory
if [ ! -f "setup.py" ]; then
echo -e "${RED}Error: setup.py not found. Are you in the correct directory?${NC}"
exit 1
fi
# Function to check if command succeeded
check_status() {
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ $1 successful${NC}"
else
echo -e "${RED}✗ $1 failed${NC}"
exit 1
fi
}
# Extract version from setup.py using grep
VERSION=$(grep -E "version='[^']*'" setup.py | cut -d"'" -f2)
if [ -z "$VERSION" ]; then
echo -e "${RED}Error: Could not extract version from setup.py${NC}"
exit 1
fi
echo -e "${GREEN}Publishing version: ${VERSION}${NC}"
# Check if tag already exists
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
echo -e "${RED}Error: Tag v$VERSION already exists. Please increment the version in setup.py${NC}"
exit 1
fi
# Create and push tag
echo "Creating tag v$VERSION..."
git tag -a "v$VERSION" -m "Version $VERSION"
check_status "Create tag"
# Push tag
echo "Pushing tag..."
git push origin "v$VERSION"
check_status "Push tag"
echo -e "${GREEN}Tag v$VERSION created and pushed successfully!${NC}"
echo -e "${YELLOW}Now create a release on GitHub with tag v$VERSION to trigger PyPI publication${NC}"