-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_release.sh
More file actions
executable file
·212 lines (180 loc) · 8.04 KB
/
prepare_release.sh
File metadata and controls
executable file
·212 lines (180 loc) · 8.04 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
echo "Script started"
set -e # Exit immediately if a command exits with a non-zero status
echo "Version argument: $1"
# Check if a version argument was provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <version>"
echo "Example: $0 v0.1.1"
exit 1
fi
VERSION=$1
VERSION_NO_V="${VERSION#v}" # Remove the 'v' prefix for use in pyproject.toml
# Validate version format
if ! [[ $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format vX.Y.Z (e.g., v0.1.1)"
exit 1
fi
# Ensure we're on the dev branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "dev" ]; then
echo "Error: You must be on the dev branch to publish a new version"
exit 1
fi
# Make sure test output files are in .gitignore
if ! grep -q "discriminator_tests.json" .gitignore 2>/dev/null; then
echo "Adding test output files to .gitignore..."
cat >> .gitignore << EOF
# Test output files
discriminator_tests.json
discriminator_tests.log
.coverage
coverage.xml
EOF
git add .gitignore
git commit -m "Add test output files to .gitignore"
echo "Updated .gitignore and committed changes."
fi
# Clean up any test output files that might interfere with branch switching
echo "Cleaning up test output files..."
rm -f discriminator_tests.json discriminator_tests.log .coverage coverage.xml
# Make sure the working directory is clean (except for ignored files)
if ! git diff-index --quiet HEAD --; then
echo "Error: Working directory has uncommitted changes"
exit 1
fi
# Pull the latest changes from the dev branch
echo "Pulling latest changes from dev branch..."
git pull origin dev
# Run unit tests before proceeding
echo "Running unit tests..."
echo "Installing package with development dependencies..."
pip install -e ".[dev]" # Install the package with dev dependencies
if ! python -m pytest; then
echo "Error: Tests failed. Please fix the failing tests before publishing."
exit 1
fi
echo "All tests passed successfully!"
# Clean up test output files again
echo "Cleaning up test output files..."
rm -f discriminator_tests.json discriminator_tests.log .coverage coverage.xml
# Update version in pyproject.toml
echo "Updating version in pyproject.toml to $VERSION_NO_V..."
sed -i.bak "s/^version = \".*\"/version = \"$VERSION_NO_V\"/" pyproject.toml
rm pyproject.toml.bak # Remove backup file
# Update version in __init__.py (accounting for src layout)
INIT_PATH="src/pydantic_discriminated/__init__.py"
if [ -f "$INIT_PATH" ]; then
if grep -q "__version__" "$INIT_PATH"; then
# Update existing version
echo "Updating version in $INIT_PATH..."
sed -i.bak "s/__version__ = \".*\"/__version__ = \"$VERSION_NO_V\"/" "$INIT_PATH"
else
# Add version if it doesn't exist
echo "Adding version to $INIT_PATH..."
echo "" >> "$INIT_PATH" # Add a newline
echo "__version__ = \"$VERSION_NO_V\"" >> "$INIT_PATH"
fi
rm -f "${INIT_PATH}.bak" # Remove backup file if it exists
else
echo "Warning: $INIT_PATH not found, skipping version update in __init__.py"
fi
# Update documentation URL in pyproject.toml to point to the docs site
echo "Updating documentation URL in pyproject.toml..."
sed -i.bak 's|"Documentation" = ".*"|"Documentation" = "https://talbotknighton.github.io/trendify/"|' pyproject.toml
rm pyproject.toml.bak # Remove backup file
# Check if email in pyproject.toml contains .org and fix it if needed
if grep -q "talbotknighton@gmail.org" pyproject.toml; then
echo "Fixing email address in pyproject.toml..."
sed -i.bak 's/talbotknighton@gmail.org/talbotknighton@gmail.com/g' pyproject.toml
rm pyproject.toml.bak # Remove backup file
fi
# Update README.md if it contains badge.fury.io badges
if [ -f "README.md" ] && grep -q "badge.fury.io" README.md; then
echo "Updating badges in README.md..."
sed -i.bak 's|https://badge.fury.io/py/trendify.svg|https://img.shields.io/pypi/v/trendify.svg|g' README.md
sed -i.bak 's|https://badge.fury.io/py/trendify|https://pypi.org/project/trendify/|g' README.md
rm README.md.bak # Remove backup file
fi
# Make sure to add README.md to the commit
git add README.md
# Update docs/index.md badges if needed
if [ -f "docs/index.md" ]; then
echo "Checking badges in docs/index.md..."
if grep -q "badge.fury.io" docs/index.md; then
echo "Updating PyPI badge in docs/index.md..."
sed -i.bak 's|https://badge.fury.io/py/trendify.svg|https://img.shields.io/pypi/v/trendify.svg|g' docs/index.md
sed -i.bak 's|https://badge.fury.io/py/trendify|https://pypi.org/project/trendify/|g' docs/index.md
rm docs/index.md.bak # Remove backup file
fi
# Update documentation badge to be more useful (not link to itself)
if grep -q "docs-mkdocs-blue" docs/index.md; then
echo "Updating documentation badge in docs/index.md..."
sed -i.bak 's|[](https://talbotknighton.github.io/trendify/)|[](https://talbotknighton.github.io/trendify/api-reference/)|g' docs/index.md
rm docs/index.md.bak # Remove backup file
fi
fi
# Update changelog if it exists
if [ -f "CHANGELOG.md" ]; then
echo "Adding new version entry to CHANGELOG.md..."
DATE=$(date +%Y-%m-%d)
sed -i.bak "s/^# Changelog/# Changelog\n\n## $VERSION ($DATE)\n\n- TODO: Add release notes\n/" CHANGELOG.md
rm CHANGELOG.md.bak # Remove backup file
# Open the changelog for editing
echo "Opening CHANGELOG.md for editing. Please add release notes and save..."
${EDITOR:-vi} CHANGELOG.md
fi
# Check for consistency in version numbers
echo "Checking for version consistency..."
PYPROJECT_VERSION=$(grep "^version = " pyproject.toml | sed 's/version = "\(.*\)"/\1/')
INIT_VERSION=$(grep "__version__" "$INIT_PATH" 2>/dev/null | sed 's/__version__ = "\(.*\)"/\1/')
if [ "$PYPROJECT_VERSION" != "$VERSION_NO_V" ]; then
echo "Error: Version in pyproject.toml ($PYPROJECT_VERSION) doesn't match requested version ($VERSION_NO_V)"
exit 1
fi
if [ -n "$INIT_VERSION" ] && [ "$INIT_VERSION" != "$VERSION_NO_V" ]; then
echo "Error: Version in $INIT_PATH ($INIT_VERSION) doesn't match requested version ($VERSION_NO_V)"
exit 1
fi
echo "Version consistency check passed."
# Commit the version changes
echo "Committing version changes..."
git add pyproject.toml README.md docs/index.md
if [ -f "$INIT_PATH" ]; then
git add "$INIT_PATH"
fi
if [ -f "CHANGELOG.md" ]; then
git add CHANGELOG.md
fi
git commit -m "Bump version to $VERSION"
# Push changes to dev branch
echo "Pushing changes to dev branch..."
git push origin dev
# Build and deploy documentation locally
echo "Building and deploying documentation version $VERSION_NO_V locally..."
mike deploy "$VERSION_NO_V" latest --update-aliases
mike set-default latest
echo "Documentation built and deployed locally."
echo "To view the documentation locally, run: mike serve"
# Create pull request from dev to main
echo "Creating a pull request from dev to main..."
# Try to create PR with GitHub CLI if available
if command -v gh &> /dev/null; then
echo "GitHub CLI found. Attempting to create PR automatically..."
PR_URL=$(gh pr create --title "Release $VERSION" \
--body "This PR prepares the release of version $VERSION. Please review the changes carefully." \
--base main \
--head dev)
if [ $? -eq 0 ]; then
echo "Pull request created successfully!"
echo "PR URL: $PR_URL"
echo "After the PR is reviewed and merged, run publish_release.sh $VERSION to complete the release process."
else
echo "Failed to create PR automatically. Please create it manually:"
echo "https://github.com/TalbotKnighton/trendify/compare/main...dev"
fi
else
echo "GitHub CLI not found. Please create the PR manually:"
echo "https://github.com/TalbotKnighton/trendify/compare/main...dev"
echo "After the PR is reviewed and merged, run publish_release.sh $VERSION to complete the release process."
fi