Skip to content

Commit

Permalink
Migrate versioning to CalVer (#278)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya authored Oct 26, 2021
1 parent 276a865 commit d4e5489
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions script/release
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/bin/sh
#!/usr/bin/env bash
set -e

REPO_PATH="$( dirname "$( cd "$(dirname "$0")" ; pwd -P )" )"

if [ -z "$1" ]; then
echo "Usage: script/release [patch | minor | major]"
exit 1
fi

if [ "$(git rev-parse --abbrev-ref HEAD)" != "dev" ]; then
echo "Refusing to publish a release from a branch other than dev"
exit 1
Expand All @@ -18,23 +13,34 @@ if [ -z "$(command -v poetry)" ]; then
exit 1
fi

# Make sure the latest dev is pulled:
git pull origin dev
function generate_version {
latest_tag="$(git tag --sort=committerdate | tail -1)"
month="$(date +'%Y.%m')"

if [[ "$latest_tag" =~ "$month".* ]]; then
patch="$(echo "$latest_tag" | cut -d . -f 3)"
((patch=patch+1))
echo "$month.$patch"
else
echo "$month.0"
fi
}

# Temporarily uninstall pre-commit hooks so that we can push to dev and master:
pre-commit uninstall

old_version="$(poetry version | awk -F' ' '{ print $2 }')"
# Pull the latest dev:
git pull origin dev

poetry version "$1"
# Generate the next version (in the format YEAR.MONTH.RELEASE_NUMER):
new_version=$(generate_version)

# Update the PyPI package version:
new_version="$(poetry version | awk -F' ' '{ print $2 }')"
sed -i "" "s/^version = \".*\"/version = \"$new_version\"/g" "$REPO_PATH/pyproject.toml"
git add pyproject.toml

# Update the docs version:
sphinx_conf=$(sed "s/$old_version/$new_version/g" "$REPO_PATH/docs/conf.py")
echo "$sphinx_conf" > "$REPO_PATH/docs/conf.py"
sed -i "" "s/^release = \".*\"/release = \"$new_version\"/g" "$REPO_PATH/docs/conf.py"
git add docs/conf.py

# Commit, tag, and push:
Expand Down

0 comments on commit d4e5489

Please sign in to comment.