forked from ByteInternet/hypernode-docs-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mark-release.sh
154 lines (133 loc) · 3.86 KB
/
mark-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
#!/usr/bin/env bash
read -r -d '' USAGE << EOUSAGE
Mark a release for project, ensure commits in master are in debian changelog.
If there are changes to release, update version and debian changelog,
also can tag and push the release.
If all commits are in changelog, won't change anything.
The last line of output indicates if a release is marked or not.
usage: $0 [options]
options:
-a automated mode (commit, tag, push)
-c commit the changes for marking the release
-h show this help and exit
-p git push HEAD and tags
-t tag the commit
-v verbose output
environment:
AUTHOR commit author (name <email>) format
DEBFULLNAME changelog writer name
DEBEMAIL changelog writer email
MESSAGE commit message
EOUSAGE
# ==== opts ====
COMMIT=false
PUSH=false
TAG=false
VERBOSE=false
while getopts 'achptv' flag; do
case "$flag" in
a)
COMMIT=true
TAG=true
PUSH=true
;;
c)
COMMIT=true
;;
h)
echo "$USAGE"
exit
;;
p)
PUSH=true
;;
t)
TAG=true
;;
v)
VERBOSE=true
;;
esac
done
set -o errexit
ROOT_DIR=$(realpath $(dirname $0))
CHANGELOG="$ROOT_DIR/debian/changelog"
VERSION=$(date "+%Y%m%d.%H%M%S")
LOG_USER="${SUDO_USER:-$USER}"
# === options from env ====
# committer info
AUTHOR="${AUTHOR:-}"
MESSAGE="${MESSAGE}"
if [[ -z "$MESSAGE" ]]; then
MESSAGE="[automated] Marking Release $VERSION"
fi
# changelog writer info
export DEBFULLNAME="${DEBFULLNAME:-Hypernode team}"
export DEBEMAIL="${DEBMAIL:[email protected]}"
log() {
logger --tag 'hypernode-docs-next-mark-release' "[$$ @$LOG_USER] $1"
if $VERBOSE; then
echo "$1"
fi
}
# deb_changelog_updated: returns 0 if there are changes to be released or 1 otherwise
deb_changelog_updated() {
log "checking if debian changelog needs update"
# use gbp dch itself to see if there are any changes detected.
# this way the logic of detecting changes is more consistent with
# the rest of the system.
gbp dch --debian-tag="%(version)s" --debian-branch=master
# find changelog diff to see if there new commits in changelog.
# commits are usually added like this to the changelog:
# [ author ]
# * commit message
# first look for commit messages, if nothing found, then see if there is an empty author section,
# as a fallback.
local changed=$(git diff --text --ignore-all-space --unified=0 --no-color $CHANGELOG | grep --line-regexp --perl-regexp '\+\s{2,}\* .+')
if [[ -z "$changed" ]]; then
changed=$(git diff --text --ignore-all-space --unified=0 --no-color $CHANGELOG | grep --line-regexp --perl-regexp '\+\\s{2,}\[.+\].*')
fi
log "reverting possible changes in debian changelog during update detection"
git checkout -- $CHANGELOG
if [[ -n "$changed" ]]; then
return 0
fi
return 1
}
mark_release() {
log "marking release $VERSION ..."
log "generating debian changelog"
gbp dch --debian-tag="%(version)s" --new-version=$VERSION --debian-branch=master
git add $CHANGELOG
}
commit() {
log "comitting the release changes"
if [[ -z "$AUTHOR" ]]; then
git commit --no-edit --message="$MESSAGE"
else
git commit --no-edit --message="$MESSAGE" --author "$AUTHOR"
fi
}
if ! deb_changelog_updated; then
log "detected no change, skipping marking release!"
echo 'no change'
exit
fi
mark_release
if $COMMIT; then
commit
if $TAG; then
log "creating git tag '$VERSION' ..."
git tag $VERSION
fi
if $PUSH; then
log "pushing changes to origin ..."
git push origin HEAD
if $TAG; then
git push origin $VERSION
fi
fi
else
log "not committing, skipping tagging and pushing!"
fi
echo "marked release $VERSION"