forked from LREN-CHUV/mri-preprocessing-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpublish.sh
executable file
·103 lines (93 loc) · 2.69 KB
/
publish.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
#!/usr/bin/env bash
set -e
count=$(git status --porcelain | wc -l)
# shellcheck disable=SC2086
if test $count -gt 0; then
git status
echo "Not all files have been committed in Git. Release aborted"
exit 1
fi
git checkout deploy
git pull origin deploy --tags
select_part() {
local choice=$1
case "$choice" in
"Patch release")
bumpversion patch
;;
"Minor release")
bumpversion minor
;;
"Major release")
bumpversion major
;;
*)
read -p "Version > " version
bumpversion --new-version="$version" all
;;
esac
}
if test -z "$(git rev-list --max-count 1 deploy..master)"; then
git merge --no-ff master
latest_version=$(git describe --abbrev=00 || \
(bumpversion --dry-run --list patch | grep current_version | sed -r s,"^.*=",,) || echo '0.0.1')
echo
echo "Current commit has not been tagged with a version. Latest known version is $latest_version."
echo
echo 'What do you want to release?'
PS3='Select the version increment> '
options=("Patch release" "Minor release" "Major release" "Release with a custom version")
select choice in "${options[@]}";
do
select_part "$choice"
break
done
updated_version=$(bumpversion --dry-run --list patch | grep current_version | sed -r s,"^.*=",,)
echo "Add a signoff for this deployment"
echo "* $(date +"%d/%m/%Y") v$updated_version - $USER" >> signoffs.md
until false
do
vi signoffs.md
git diff
read -p "Are you happy with the signoff message? [N/y/q] > " ok
case "$ok" in
y|Y)
break
;;
q|Q|x|X)
echo "Release aborted"
exit 1
;;
esac
done
git commit -S -m "Signoff" signoffs.md
# Bumpversion v0.5.3 does not support annotated tags nor signed tags
git tag -s -a -m "Signoff from $USER" "$updated_version"
else
echo "You need to merge deploy branch with master branch"
echo "git merge master"
exit 1
fi
git push origin deploy
git push origin deploy --tags
git checkout master
git merge deploy
git push
# Notify on slack
set -e
get_script_dir () {
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$( readlink "$SOURCE" )"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done
cd -P "$( dirname "$SOURCE" )"
pwd
}
export WORKSPACE=$(get_script_dir)
sed "s/USER/${USER^}/" $WORKSPACE/slack.json > $WORKSPACE/.slack.json
sed -i.bak "s/VERSION/$(git describe)/" $WORKSPACE/.slack.json
curl -k -X POST --data-urlencode payload@$WORKSPACE/.slack.json https://hbps1.chuv.ch/slack/dev-activity
rm -f $WORKSPACE/.slack.json
rm -f $WORKSPACE/.slack.json.bak