Skip to content

Commit d4e5489

Browse files
authored
Migrate versioning to CalVer (#278)
1 parent 276a865 commit d4e5489

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

script/release

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22
set -e
33

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

6-
if [ -z "$1" ]; then
7-
echo "Usage: script/release [patch | minor | major]"
8-
exit 1
9-
fi
10-
116
if [ "$(git rev-parse --abbrev-ref HEAD)" != "dev" ]; then
127
echo "Refusing to publish a release from a branch other than dev"
138
exit 1
@@ -18,23 +13,34 @@ if [ -z "$(command -v poetry)" ]; then
1813
exit 1
1914
fi
2015

21-
# Make sure the latest dev is pulled:
22-
git pull origin dev
16+
function generate_version {
17+
latest_tag="$(git tag --sort=committerdate | tail -1)"
18+
month="$(date +'%Y.%m')"
19+
20+
if [[ "$latest_tag" =~ "$month".* ]]; then
21+
patch="$(echo "$latest_tag" | cut -d . -f 3)"
22+
((patch=patch+1))
23+
echo "$month.$patch"
24+
else
25+
echo "$month.0"
26+
fi
27+
}
2328

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

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

29-
poetry version "$1"
35+
# Generate the next version (in the format YEAR.MONTH.RELEASE_NUMER):
36+
new_version=$(generate_version)
3037

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

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

4046
# Commit, tag, and push:

0 commit comments

Comments
 (0)