-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·118 lines (90 loc) · 2.99 KB
/
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
#!/usr/bin/env bash
# Requirements
# brew install hub
# npm install -g git-release-notes
# pip install twine
set -e
INIT_FILE='rosetta/__init__.py'
TMP_INIT_FILE='./__init__.py.tmp'
VER_TAG='__version__ = '
SOURCE_ORIGIN='origin'
function escape_slashes {
sed 's/\//\\\//g'
}
function change_line {
local OLD_LINE_PATTERN=$1
local NEW_LINE=$2
local FILE=$3
local NEW=$(echo "${NEW_LINE}" | escape_slashes)
sed -i .bak '/'"${OLD_LINE_PATTERN}"'/s/.*/'"${NEW}"'/' "${FILE}"
mv "${FILE}.bak" ${TMP_INIT_FILE}
}
function clean_build {
rm -rf dist
rm -rf *.egg-info
rm -rf build
}
function pub_pypi {
# publish to pypi
clean_build
python setup.py sdist bdist_wheel
twine upload dist/*
clean_build
}
function pub_gittag {
git add $INIT_FILE
git commit -m "chore(version): bumping version to $VER"
git tag $VER -m "$(cat ./CHANGELOG.tmp)"
# git remote add $SOURCE_ORIGIN https://hanxiao:${GITHUB_ACCESS_TOKEN}@github.com/gnes-ai/gnes.git
git push $SOURCE_ORIGIN $VER
git checkout master
}
function make_chore_pr {
git checkout -B "chore-bumping-version"
git add ./CHANGELOG.md
git add $INIT_FILE
git commit -m "chore(changelog): update change log to $1"
git push $SOURCE_ORIGIN chore-bumping-version --force
# hub pull-request -m "chore(changelog): update change log to $1" --no-edit -l new-release
rm ./CHANGELOG.tmp
git checkout master
# merge chore-bumping locally
git merge chore-bumping-version
}
function make_release_note {
git-release-notes $1..HEAD .github/release-template.ejs > ./CHANGELOG.tmp
printf '\n%s\n%s\n%s\n%s\n' "# Release Note (\`$2\`)" "> Release time: $(date +'%Y-%m-%d %H:%M:%S')" "$(cat ./CHANGELOG.tmp)" "$(cat ./CHANGELOG.md)" > ./CHANGELOG.md
}
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "$BRANCH" != "master" ]]; then
printf "You are not at master branch, exit\n";
exit 1;
fi
LAST_UPDATE=`git show --no-notes --format=format:"%H" $BRANCH | head -n 1`
LAST_COMMIT=`git show --no-notes --format=format:"%H" origin/$BRANCH | head -n 1`
if [ $LAST_COMMIT != $LAST_UPDATE ]; then
printf "Your local $BRANCH is behind the remote master, exit\n"
exit 1;
fi
# if [[ -z "${GITHUB_TOKEN}" ]]; then
# printf "GITHUB_TOKEN is not set! Need to export GITHUB_TOKEN=xxx"
# exit 1;
# fi
#$(grep "$VER_TAG" $CLIENT_CODE | sed -n 's/^.*'\''\([^'\'']*\)'\''.*$/\1/p')
OLDVER=$(git tag -l | sort -V |tail -n1)
printf "current version:\t\e[1;33m$OLDVER\e[0m\n"
VER=$(echo $OLDVER | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}')
printf "bump version to:\t\e[1;32m$VER\e[0m\n"
make_release_note $OLDVER $VER
head -n10 ./CHANGELOG.md
read -p "release this version? " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
# write back tag to client and server code
VER_VAL=$VER_TAG"'"${VER#"v"}"'"
change_line "$VER_TAG" "$VER_VAL" $INIT_FILE
# pub_pypi
pub_gittag
make_chore_pr $VER
fi