Migration from old pyutilz package name (which, in turn, came from
[pyutils.git] / cut_version.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 # Ask a yes or no question
6 function ask_y_n() {
7     local prompt default reply
8     if [ "${2:-}" = "Y" ]; then
9         prompt="Y/n"
10         default=Y
11     elif [ "${2:-}" = "N" ]; then
12         prompt="y/N"
13         default=N
14     else
15         prompt="y/n"
16         default=
17     fi
18     while true; do
19         echo -ne "$1 [$prompt] "
20         read -n 1 -t 5 reply </dev/tty
21         if [ -z "$reply" ]; then
22             echo
23             echo "(timeout, assuming $default)"
24             reply=$default
25         fi
26         case "$reply" in
27             [Yy]* ) echo && return 0 ;;
28             [Nn]* ) echo && return 1 ;;
29             * ) echo && echo "Please answer Yes or No." ;;
30         esac
31     done
32 }
33
34 function pause() {
35     read -rsp $'Press any key to continue...' -n1 key
36 }
37
38
39 if [ $# -ne 1 ]; then
40     echo "Usage: $0 <required_version_number>"
41     exit 1
42 fi
43
44 VERSION=$1
45 if ! ask_y_n "About to cut and upload $VERSION, ok?" "N"; then
46     echo "Ok, exiting instead."
47     exit 0
48 fi
49 echo
50
51 echo "Ok, here's the commit message of changes since the last version..."
52 LAST_TAG=$(git tag | tail -1)
53 git log $LAST_TAG..HEAD
54 pause
55 echo
56 echo
57
58 echo "Ok, running scottutilz tests including test_some_dependencies.py..."
59 cd ../scottutilz/tests
60 ./run_tests.py --all --coverage
61 cd ../../pyutilz
62 pause
63 echo
64 echo
65
66 git tag -a "${VERSION}" -m "cut_version.sh ${VERSION}"
67 CHANGES=$(git log --pretty="- %s" $VERSION...$LAST_TAG)
68 printf "# 🎁 Release notes (\`$VERSION\`)\n\n## Changes\n$CHANGES\n\n## Metadata\n\`\`\`\nThis version -------- $VERSION\nPrevious version ---- $PREVIOUS_VERSION\nTotal commits ------- $(echo "$CHANGES" | wc -l)\n\`\`\`\n" >> release_notes.md
69
70 cat ./pyproject.template | sed s/##VERSION##/$VERSION/g > ./pyproject.toml
71 git commit -a -m "Cut version ${VERSION}" -m "${CHANGES}"
72 git push
73
74 python -m build
75 echo "To upload, run: \"twine upload --verbose --repository testpypi dist/*\""