| 1 |
#!/usr/bin/env bash |
| 2 |
set -e |
| 3 |
|
| 4 |
REPO_PATH="$( dirname "$( cd "$(dirname "$0")" ; pwd -P )" )" |
| 5 |
|
| 6 |
if [ "$(git rev-parse --abbrev-ref HEAD)" != "dev" ]; then |
| 7 |
echo "Refusing to publish a release from a branch other than dev" |
| 8 |
exit 1 |
| 9 |
fi |
| 10 |
|
| 11 |
function generate_version { |
| 12 |
latest_tag="$(git tag --sort=committerdate | tail -1)" |
| 13 |
month="$(date +'%Y.%m')" |
| 14 |
|
| 15 |
if [[ "$latest_tag" =~ "$month".* ]]; then |
| 16 |
patch="$(echo "$latest_tag" | cut -d . -f 3)" |
| 17 |
((patch=patch+1)) |
| 18 |
echo "$month.$patch" |
| 19 |
else |
| 20 |
echo "$month.0" |
| 21 |
fi |
| 22 |
} |
| 23 |
|
| 24 |
# Temporarily uninstall pre-commit hooks so that we can push to dev and main: |
| 25 |
pre-commit uninstall |
| 26 |
|
| 27 |
# Pull the latest dev: |
| 28 |
git pull origin dev |
| 29 |
|
| 30 |
# Generate the next version (in the format YEAR.MONTH.RELEASE_NUMER): |
| 31 |
new_version=$(generate_version) |
| 32 |
|
| 33 |
# Update the PyPI package version: |
| 34 |
sed -i "" "s/^version = \".*\"/version = \"$new_version\"/g" "$REPO_PATH/pyproject.toml" |
| 35 |
git add pyproject.toml |
| 36 |
|
| 37 |
# Update the uv lockfile: |
| 38 |
uv lock |
| 39 |
git add uv.lock |
| 40 |
|
| 41 |
# Commit, tag, and push: |
| 42 |
git commit -m "Bump version to $new_version" |
| 43 |
git tag "$new_version" |
| 44 |
git push && git push --tags |
| 45 |
|
| 46 |
# Merge dev into main: |
| 47 |
git checkout main |
| 48 |
git merge dev |
| 49 |
git push |
| 50 |
git checkout dev |
| 51 |
|
| 52 |
# Re-initialize pre-commit: |
| 53 |
pre-commit install |