1+ #! /bin/bash
2+
3+ # This script does the following:
4+ # - does some sanity checks
5+ # - updates RELEASE and src/psij/version.py
6+ # - commits and pushes the version files
7+ # - creates a release tag
8+ # - builds packages
9+ # - pushes said packages to PyPi
10+ # - triggers github workflows to rebuild the web page (including documentation)
11+
12+ set -e
13+
14+ error () {
15+ echo $@
16+ exit 1
17+ }
18+
19+ if [ " $1 " == " " ]; then
20+ error " Missing required version argument"
21+ else
22+ TARGET_VERSION=" $1 "
23+ fi
24+
25+ # Ensure that we are on the main branch
26+ CRT_BRANCH=` git rev-parse --abbrev-ref HEAD`
27+
28+ if [ " $CRT_BRANCH " != " main" ]; then
29+ error " Must be on the main branch to make a release."
30+ fi
31+
32+ STATUS=` git status --untracked-files=no --porcelain`
33+
34+ # Ensure current dir is clean
35+ if [ ! -z " $STATUS " ]; then
36+ error " Working directory is not clean. Please run this script on a clean checkout."
37+ echo
38+ fi
39+
40+ # Make sure version in newer than other releases
41+ TAGS=` git tag`
42+ if echo " $TAGS " | grep " $TARGET_VERSION " 2>&1 > /dev/null; then
43+ error " Version $TARGET_VERSION is already tagged."
44+ fi
45+
46+ LAST=` echo -e " $TAGS \n$TARGET_VERSION " | sed ' /^\s*$/d' | sort -V | tail -n 1`
47+ if [ " $LAST " != " $TARGET_VERSION " ]; then
48+ error " Version $TARGET_VERSION is lower than the latest tagged version ($LAST )."
49+ fi
50+
51+ echo " This will tag and release psij-python to version $TARGET_VERSION ."
52+ echo -n " Type 'yes' if you want to continue: "
53+ read REPLY
54+
55+ if [ " $REPLY " != " yes" ]; then
56+ error " Release canceled."
57+ fi
58+
59+ # There are mutable operations from here on
60+
61+ echo " Creating release branch"
62+ git checkout -b " releases/$TARGET_VERSION "
63+
64+ # Update the two version files and push them
65+ echo " Updating version and tagging..."
66+
67+ echo -n " $TARGET_VERSION " > RELEASE
68+ cat << EOF >src/psij/version.py
69+ """This module stores the current version of this library."""
70+
71+ # Do not change this file manually. It is updated automatically by the release script.
72+ VERSION = '$TARGET_VERSION '
73+ EOF
74+
75+ git commit -m " Updated version files to $TARGET_VERSION ." RELEASE src/psij/version.py
76+ git push --set-upstream origin releases/$TARGET_VERSION
77+
78+ git tag -a " $TARGET_VERSION " -m " Tagging $TARGET_VERSION "
79+ git push origin --tags
80+
81+ echo " Building packages..."
82+ python3 setup.py sdist
83+ python3 setup.py bdist_wheel
84+
85+ echo " Releasing PyPi package..."
86+ twine upload dist/*
87+
88+ echo " Triggering web docs build..."
89+ git commit --allow-empty -m " Trigger web build for $TARGET_VERSION "
90+ git push
91+
92+ echo " All done!"
0 commit comments