Adds a __repr__ to graph.
[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 PREVIOUS_VERSION=$(git tag --sort=-creatordate | head -1)
46 git tag --format='%(creatordate:short)%09%(refname:strip=2)'
47 echo
48 echo "PREVIOUS_VERSION=${PREVIOUS_VERSION}"
49 echo
50 if ! ask_y_n "About to cut (build, test, package, give you the command to upload) $VERSION, ok?" "N"; then
51     echo "Ok, exiting instead."
52     exit 0
53 fi
54 LAST_TAG=$(git tag | tail -1)
55 if [ "${LAST_TAG}" == "${VERSION}" ]; then
56     echo "Last tag is the same as ${VERSION}?!  Aborted."
57     exit 1
58 fi
59 echo
60
61 echo "Ok, here are the commit message of changes since the last version..."
62 git log $LAST_TAG..HEAD
63 pause
64 echo
65 echo
66
67 echo "Ok, running pyutils and scottutilz tests including test_some_dependencies.py..."
68 cd ../scottutilz/tests
69 ./run_tests.py --all --coverage
70 cd ../../pyutils
71 pause
72 echo
73 echo
74
75 echo "Creating a git tag for version ${VERSION}"
76 git tag -a "${VERSION}" -m "cut_version.sh ${VERSION}"
77 CHANGES=$(git log --pretty="- %s" $VERSION...$LAST_TAG)
78 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
79
80 echo "Updating pyproject.toml with this version number"
81 cat ./pyproject.template | sed s/##VERSION##/$VERSION/g > ./pyproject.toml
82
83 echo "Building wheel..."
84 python -m build
85
86 echo "Checking in wheel package under dist/"
87 cd dist
88 WHEEL=pyutils-${VERSION}-py3-none-any.whl
89 if [ ! -f ${WHEEL} ]; then
90     echo "Can't find ${WHEEL}?!"
91     exit 1
92 fi
93 LINK=pyutils-latest-py3-none-any.whl
94 git rm -f ${LINK}
95 ln -s ${WHEEL} ${LINK}
96 git add ${WHEEL}
97 git add ${LINK}
98 for FILE in *.whl; do
99     md5 ${FILE} > ${FILE}.md5
100 done
101 git add *.md5
102 cd ..
103 git commit -a -m "Cut version ${VERSION}" -m "${CHANGES}"
104
105 echo "Pushing changes to git"
106 git push
107
108 echo "Done.  To upload, run: \"twine upload --verbose --repository pypi dist/pyutils-${VERSION}*.whl\""