-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_release.sh
executable file
·165 lines (134 loc) · 3.72 KB
/
run_release.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/bash
# Script for creating a release:
# - create a tag
# - create a release
# - upload the package
#
# Thomas Guillod - Dartmouth College
set -o nounset
set -o pipefail
function parse_arg {
# get the version and release message
if [[ "$#" -eq 2 ]]
then
VER=$(echo $1 | awk '{$1=$1;print}')
MSG=$(echo $2 | awk '{$1=$1;print}')
else
echo "error: usage : run_release.sh VER MSG"
exit 1
fi
}
function check_release {
echo "======================================================================"
echo "============================== CHECK RELEASE"
echo "======================================================================"
# init status
ret=0
# check the version number
rx='^([0-9]+)\.([0-9]+)\.([0-9]+)$'
if ! [[ $VER =~ $rx ]]
then
echo "error: invalid version number format"
ret=1
fi
# check the release message
rx='^ *$'
if [[ $MSG =~ $rx ]]
then
echo "error: invalid release message format"
ret=1
fi
# check git branch name
if [[ $(git rev-parse --abbrev-ref HEAD) != "main" ]]
then
echo "error: release should be done from main"
ret=1
fi
# check git tag existence
if [[ $(git tag -l $VER) ]]
then
echo "error: version number already exists"
ret=1
fi
# check git repository status
if ! [[ -z "$(git status --porcelain)" ]]
then
echo "error: git status is not clean"
ret=1
fi
# abort in case of failure
if [[ $ret != 0 ]]
then
echo "======================================================================"
echo "============================== RELEASE FAILURE"
echo "======================================================================"
exit $ret
fi
}
function clean_data {
echo "======================================================================"
echo "============================== CLEAN DATA"
echo "======================================================================"
# clean package
rm -rf dist
rm -rf build
rm -rf *.egg-info
# clean version file
rm -rf version.txt
}
function build_check {
echo "======================================================================"
echo "============================== BUILD AND CHECK"
echo "======================================================================"
# init status
ret=0
# create a temporary tag
git tag -a $VER -m "$MSG" > /dev/null
# build the release
python -m build
ret=$(( ret || $? ))
# check the linter
ruff check --no-cache .
ret=$(( ret || $? ))
# check the format
ruff format --no-cache --check .
ret=$(( ret || $? ))
# remove the temporary tag
git tag -d $VER > /dev/null
# abort in case of failure
if [[ $ret != 0 ]]
then
echo "======================================================================"
echo "============================== RELEASE FAILURE"
echo "======================================================================"
exit $ret
fi
}
function upload_pkg {
echo "======================================================================"
echo "============================== UPLOAD PACKAGE"
echo "======================================================================"
# create a tag
git tag -a $VER -m "$MSG"
# push the tag
git push origin --tags
# create a release
gh release create $VER --title $VER --notes "$MSG"
# upload to PyPI
twine upload dist/*
}
function ret_collect {
echo "======================================================================"
echo "============================== RELEASE SUCCESS"
echo "======================================================================"
}
# parse the arguments
parse_arg "$@"
# run the code
check_release
clean_data
build_check
upload_pkg
# collect status
ret_collect
exit 0