-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·128 lines (109 loc) · 3.71 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·128 lines (109 loc) · 3.71 KB
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
#!/bin/bash
######################################################################################
# Release a plugin #
# #
# Usage: #
# $ release.sh all #
# $ release.sh v5/broker/http #
# $ release.sh v5/broker/http,v5/broker/redis #
# $ release.sh v5/* #
# #
######################################################################################
CHANGELOG_TEMPLATE="scripts/template/changelog.md"
CHANGELOG_FILE="/tmp/changelog.md"
function increment_minor_version() {
declare -a part=(${1//\./ })
part[2]=0
part[1]=$((part[1] + 1))
new="${part[*]}"
echo -e "${new// /.}"
}
function increment_patch_version() {
declare -a part=(${1//\./ })
part[2]=$((part[2] + 1))
new="${part[*]}"
echo -e "${new// /.}"
}
function remove_prefix() {
echo "${1//\.\//}"
}
function check_if_changed() {
local pkg="$1"
local last_tag=$(git tag --list --sort='-creatordate' "${pkg}/*" | head -n1)
if [[ "${last_tag}" == "" ]]; then
echo -e "# No previous tag\n# Run:\ngh release create "${pkg}/v1.0.0" -n 'Initial release'"
return 1
fi
local changes="$(git --no-pager log "${last_tag}..HEAD" --format="%s" "${pkg}")"
if [[ "${#changes}" == "0" ]]; then
# echo "# No changes detected in package '${pkg}'"
return 1
fi
return 0
}
function release() {
if [[ ! -f "${1}/go.mod" ]]; then
echo "Unknown package '${1}' given."
return 1
fi
local pkg="${1}"
if ! check_if_changed "${pkg}"; then
return 1
fi
cat $CHANGELOG_TEMPLATE >$CHANGELOG_FILE
local last_tag=$(git tag --list --sort='-creatordate' "${pkg}/*" | head -n1)
# Create changelog file
git log "${last_tag}..HEAD" --format="%s" "${pkg}" |
xargs -d'\n' -I{} bash -c "echo \" * {}\" >> $CHANGELOG_FILE"
declare -a last_tag_split=(${last_tag//\// })
local v_version=${last_tag_split[-1]}
local version=${v_version:1}
# Remove the version from last_tag_split
unset last_tag_split[-1]
# Increment minor version if "feat:" commit found, otherwise patch version
git --no-pager log "${last_tag}..HEAD" --format="%s" "${pkg}/*" | grep -q -E "^feat:"
if [[ "$?" == "0" ]]; then
local tmp_new_tag="$(printf "/%s" "${last_tag_split[@]}")/v$(increment_minor_version ${version})"
local new_tag=${tmp_new_tag:1}
else
local tmp_new_tag="$(printf "/%s" "${last_tag_split[@]}")/v$(increment_patch_version ${version})"
local new_tag=${tmp_new_tag:1}
fi
# echo -e "# Run:\n"
echo "# Upgrading pkg ${last_tag} >> ${new_tag}"
# echo "gh release create \"${new_tag}\" --generate-notes --notes-start-tag ${last_tag}"
gh release create "${new_tag}" --notes-file "${CHANGELOG_FILE}"
}
function release_all() {
while read -r pkg; do
pkg=$(remove_prefix "${pkg}")
if echo "${pkg}" | grep -q "^v2"; then
continue
fi
release "${pkg}"
done < <(find . -name 'go.mod' -printf "%h\n")
}
function release_specific() {
set +o noglob
while read -r pkg; do
# If path contains a star find all relevant packages
echo releasing ${pkg}
if echo "${pkg}" | grep -q "\*"; then
while read -r p; do
release "$(remove_prefix "${p}")"
done < <(find $pkg -name 'go.mod' -printf "%h\n")
else
release "${pkg}"
fi
done < <(echo "${1}" | tr "," "\n")
# set -o noglob
# set +o noglob
}
case $1 in
"all")
release_all
;;
*)
release_specific "${1}"
;;
esac