Debian Codegraph @

script/release

raw symbols SCIP
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 if [ -z "$(command -v poetry)" ]; then
12 echo "Poetry needs to be installed to run this script: pip3 install poetry"
13 exit 1
14 fi
15
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 }
28
29 # Temporarily uninstall pre-commit hooks so that we can push to dev and main:
30 pre-commit uninstall
31
32 # Pull the latest dev:
33 git pull origin dev
34
35 # Generate the next version (in the format YEAR.MONTH.RELEASE_NUMER):
36 new_version=$(generate_version)
37
38 # Update the PyPI package version:
39 sed -i "" "s/^version = \".*\"/version = \"$new_version\"/g" "$REPO_PATH/pyproject.toml"
40 git add pyproject.toml
41
42 # Commit, tag, and push:
43 git commit -m "Bump version to $new_version"
44 git tag "$new_version"
45 git push && git push --tags
46
47 # Merge dev into main:
48 git checkout main
49 git merge dev
50 git push
51 git checkout dev
52
53 # Re-initialize pre-commit:
54 pre-commit install