forked from zerothi/sisl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.sh
executable file
·133 lines (112 loc) · 2.7 KB
/
tag.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# This small bash script tags the git-revision
# by updating the appropriate files with the
# revision numbers
# Ensure we have access to module command
source ~/.bashrc
function read_num {
local n=$1 ; shift
grep -e "^$n" setup.py | sed -e "s!$n[[:space:]]*=[[:space:]]*\(.*\)!\1!"
}
MAJOR=$(read_num MAJOR)
MINOR=$(read_num MINOR)
MICRO=$(read_num MICRO)
_shifted=0
function _help {
echo "Use the following commands:"
echo " $0 M : steps the major revision, minor, micro turns 0"
echo " $0 m : steps the minor revision, micro turns 0"
echo " $0 u : steps the minor revision"
echo ""
echo "Example, previous version is 0.1.3"
echo " $0 M => 1.0.0"
echo " $0 m => 0.2.0"
echo " $0 u => 0.1.4"
echo ""
echo "Current sisl version is $MAJOR.$MINOR.$MICRO"
}
if [ $# -eq 0 ]; then
echo "You *must* supply at least one step option"
echo ""
_help
exit 1
fi
# Figure out what to step
no_commit=0
while [ $# -gt 0 ]; do
opt=$1 ; shift
case $opt in
-h|--h|--help|-help)
_help
exit 0
;;
-no-commit|-nc)
no_commit=1
;;
a|A|M|major|ma)
let MAJOR++
MINOR=0
MICRO=0
_shifted=1
;;
b|m|minor|mi)
let MINOR++
MICRO=0
_shifted=1
;;
c|u|micro|mic)
let MICRO++
_shifted=1
;;
esac
done
if [ $_shifted -eq 0 ]; then
let MICRO++
fi
# Create version string
v=$MAJOR.$MINOR.$MICRO
# Git revision
rev=$(git rev-parse HEAD)
# Message for release
MSG="Releasing v$v"
# Set version numbers in setup.py
sed -i -e "s:\(MAJOR[[:space:]]*=\).*:\1 $MAJOR:" setup.py
sed -i -e "s:\(MINOR[[:space:]]*=\).*:\1 $MINOR:" setup.py
sed -i -e "s:\(MICRO[[:space:]]*=\).*:\1 $MICRO:" setup.py
# Update release tag and git revision
sed -i -e "s:\(ISRELEASED[[:space:]]*=\).*:\1 True:" setup.py
sed -i -e "s:\(GIT_REVISION[[:space:]]*=\).*:\1 \"$rev\":" setup.py
if [ $no_commit -eq 1 ]; then
python setup.py sdist bdist_wheel
git checkout setup.py
exit 0
fi
echo "Tagging with message:"
echo " -m '$MSG'"
# Tagging and releasing
git add setup.py
git commit -s -m "sisl release: $v"
git tag -a "v$v" -m "$MSG"
# This requires ~/.pypirc to exist with this content:
#[distutils]
#index-servers =
# pypi
# testpypi
#
#[pypi]
#repository = https://upload.pypi.org/legacy/
#username = zeroth
#
#[testpypi]
#repository = https://test.pypi.org/legacy/
#username = zeroth
# Publish on testpypi
python setup.py sdist bdist_wheel
twine upload --repository testpypi dist/sisl-$v*.tar.gz
exit 0
# Revert release tag
sed -i -e "s:\(ISRELEASED[[:space:]]*=\).*:\1 False:" setup.py
git add setup.py
git commit -s -m "Reverting internal release"
git push
git push --follow-tags