-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.sh
executable file
·154 lines (128 loc) · 4.14 KB
/
project.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
set -e
# Function to handle errors
handle_error() {
echo "Error occurred. Exiting..."
exit 1
}
trap handle_error ERR
# Get the current version
current_version=$(grep -o "__version__ = version = '[0-9.]*'" src/toPrint/_version.py | grep -o "[0-9.]*")
echo "Current version: $current_version"
# Increment the patch version
IFS='.' read -r major minor patch <<< "$current_version"
new_patch=$((patch + 1))
new_version="$major.$minor.$new_patch"
# Check if tag already exists, if so increment again
while git rev-parse "v$new_version" >/dev/null 2>&1; do
echo "Tag v$new_version already exists, incrementing..."
new_patch=$((new_patch + 1))
new_version="$major.$minor.$new_patch"
done
echo "New version: $new_version"
# Update version in _version.py
cat > src/toPrint/_version.py << EOF
# file generated by version.sh
# don't change, don't track in version control
# _version.py
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple, Union
VERSION_TUPLE = Tuple[Union[int, str], ...]
else:
VERSION_TUPLE = object
version: str
__version__: str
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE
__version__ = version = '$new_version'
__version_tuple__ = version_tuple = ($major, $minor, $new_patch)
EOF
# Create a simple setup.py for building
cat > setup.py << EOF
from setuptools import setup, find_packages
setup(
name="toPrint",
version="$new_version",
description="Convert text to formatted documents",
author="toPrint Team",
author_email="[email protected]",
url="https://github.com/toPrint/python",
packages=find_packages(where="src"),
package_dir={"": "src"},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
python_requires=">=3.7",
)
EOF
# Create increment_init.py and increment_setup.py if they don't exist
cat > increment_init.py << 'EOF'
#!/usr/bin/env python3
# Simple script to increment version in __init__.py
# This is a placeholder - adjust as needed for your project
print("Version incremented in __init__.py")
EOF
chmod +x increment_init.py
cat > increment_setup.py << 'EOF'
#!/usr/bin/env python3
# Simple script to increment version in setup.py
# This is a placeholder - adjust as needed for your project
print("Version incremented in setup.py")
EOF
chmod +x increment_setup.py
# Update changelog
echo "Updating changelog..."
changelog_file="CHANGELOG.md"
if [ -f "$changelog_file" ]; then
# Create a temporary file
temp_file=$(mktemp)
# Add new version header
echo "# $new_version ($(date +%Y-%m-%d))" > "$temp_file"
echo "" >> "$temp_file"
echo "* Version bump" >> "$temp_file"
echo "" >> "$temp_file"
# Append existing content
cat "$changelog_file" >> "$temp_file"
# Replace original file
mv "$temp_file" "$changelog_file"
echo "Updated changelog to version $new_version"
else
echo "# $new_version ($(date +%Y-%m-%d))" > "$changelog_file"
echo "" >> "$changelog_file"
echo "* Initial release" >> "$changelog_file"
echo "" >> "$changelog_file"
echo "Created changelog with version $new_version"
fi
# Commit changes
echo "Publishing new version to GitHub..."
echo "Found version: $new_version"
echo ""
echo "Changes to be published:"
echo ""
git add src/toPrint/_version.py setup.py "$changelog_file" increment_init.py increment_setup.py
git commit -m "Release version $new_version"
git tag "v$new_version"
# Push changes
echo "Pushing changes and tags to GitHub..."
git push origin main
git push origin "v$new_version"
echo "Successfully published version $new_version"
# Clean up previous builds
echo "Cleaning up previous builds..."
rm -rf build/ dist/ src/toPrint.egg-info/
# Upgrade build tools
echo "Upgrading build tools..."
python -m pip install --upgrade pip build twine setuptools wheel
# Build the package
echo "Building package..."
python setup.py sdist bdist_wheel
# Check the package
echo "Checking package..."
python -m twine check dist/*
# Publish to PyPI
echo "Publishing to PyPI..."
python -m twine upload dist/*
echo "Version $new_version has been released and published!"