-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease
More file actions
executable file
·213 lines (185 loc) · 7.1 KB
/
release
File metadata and controls
executable file
·213 lines (185 loc) · 7.1 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
source bin/.bashrc
[[ $# -ne 1 ]] && label "Usage: $0 <type>" ko && exit 1
git_clean
[[ -f var/.env ]] && source var/.env
base_uri="https://github.com/msgphp"
repo="[email protected]:msgphp/msgphp.git"
curr_version() {
local version="$(git describe --abbrev=0 --tags)" && [[ ${version} == v* ]] && version=${version:1}
echo "${version}"
}
next_version() {
local version=${1:?missing version} && [[ ${version} == v* ]] && version=${version:1}
local parts=(${version//./ })
[[ ${#parts[@]} -ne 3 ]] && echo "Invalid version" && exit 1
case $2 in
major) ((++parts[0])); parts[1]=0; parts[2]=0;;
minor) ((++parts[1])); parts[2]=0;;
patch) ((++parts[2]));;
esac
echo "${parts[0]}.${parts[1]}.${parts[2]}"
}
branch_alias() {
local version=${1:?missing version} && [[ ${version} == v* ]] && version=${version:1}
local parts=(${version//./ })
[[ ${#parts[@]} -ne 3 ]] && echo "Invalid version" && exit 1
echo "${parts[0]}.${parts[1]}"
}
release_branches() {
local branches="$(git branch --remote --list "origin/[0-9].[0-9]")"
echo "${branches:-origin/master}"
}
checkout() {
local branch=${1:?missing branch}
local parts=(${branch//// })
[[ ${#parts[@]} -ne 2 ]] && echo "Invalid branch" && exit 1
git checkout --quiet -B "${parts[1]}" "${parts[0]}/${parts[1]}" && \
git pull --quiet "${parts[0]}" "${parts[1]}"
}
tag() {
local version=${1:?missing version} && [[ ${version} == v* ]] && version=${version:1}
git tag -sm enjoy "v${version}"
}
changelog() {
local branch=${1:?missing branch}
local since_version=${2:?missing since version} && [[ ${since_version} == v* ]] && since_version=${since_version:1}
local next_version=${3:?missing next version} && [[ ${next_version} == v* ]] && next_version=${next_version:1}
local filename="CHANGELOG-"$(branch_alias "${next_version}")".md"
[[ "${next_version}" == 0.* ]] && filename="CHANGELOG-1.0-dev.md"
[[ ! -d "var/changelog/${branch}" ]] && mkdir -p "var/changelog/${branch}"
[[ -d ../../var/changelog ]] && cp -R ../../var/changelog var/
[[ -z ${GITHUB_TOKEN} ]] && echo "(!) Generating changelog without GitHub token"
for package in $(find src/*/composer.json -type f); do
name="$(package_name "${package}")"
file="$(dirname "${package}")/${filename}"
[[ ! -f "${file}" ]] && echo "# Changelog" >> "${file}"
rm -f "${file}.tmp" && \
docker run --init -it --rm \
-u $(id -u):$(id -g) \
-v $(pwd):/app \
-w /app \
ferrarimarco/github-changelog-generator \
-u msgphp -p msgphp -t "${GITHUB_TOKEN}" \
--cache-file "var/changelog/${branch}" \
--output "${file}.tmp" \
--since-tag "v${since_version}" \
--future-release "v${next_version}" \
--release-branch "${branch}" \
--release-url "${base_uri}/${name}/tree/%s" \
--include-labels "${name/-/,}" \
--simple-list \
--header-label "" \
--no-issues \
--no-filter-by-milestone \
--no-author \
--no-compare-link \
--no-verbose >/dev/null && \
sed -e '/^\\\* \*This Change Log was automatically generated .*/d' -i "${file}.tmp" && \
sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' -i "${file}.tmp" && \
sed -e '1 a \\n' -i "${file}" && \
sed -e "2 r ${file}.tmp" -i "${file}" && \
sed -e :a -e '/./,$!d;/^\n*$/{$d;N;};/\n$/ba' -i "${file}" && \
rm -f "${file}.tmp" && \
git add "${file}"
[[ $? -ne 0 ]] && return 1
done
cp -R var/changelog ../../var/
git commit --quiet -m "update changelog to ${next_version}"
return 0
}
bump_version() {
local branch=${1:?missing branch}
sh -c "$(make -s entrypoint) bin/package-exec composer config extra.branch-alias.dev-master \"${branch}-dev\""
[[ $? -ne 0 ]] && return 1
[[ $(git status --porcelain) ]] && \
git add src/*/composer.json && \
git commit --quiet -m "bumped branch alias to ${branch}"
return 0
}
bump_deps() {
local branch=${1:?missing branch}
bin/package-exec sed -i -E "s/\(\\\"msgphp\\\/.+\\\":\\\s*\\\"\).+\(\\\",?\)/\\\1^${branch}\\\2/" composer.json
[[ $? -ne 0 ]] && return 1
[[ $(git status --porcelain) ]] && \
git add src/*/composer.json && \
git commit --quiet -m "bumped dependencies to ${branch}"
return 0
}
confirm "Run smoke test?" yes
if [[ $? -eq 1 ]]; then
make smoke-test
[[ $? -ne 0 ]] && label "Failed" ko && exit 1
fi
confirm "Build docs?" yes
if [[ $? -eq 1 ]]; then
bin/build-docs
[[ $? -ne 0 ]] && label "Failed" ko && exit 1
fi
confirm "Continue $1 release?"
[[ $? -ne 1 ]] && label "Aborted" ok && exit 0
label "Synchronizing source"
git_sync var/release "${repo}"
[[ $? -ne 0 ]] && label "Failed" ko && exit 1
pushd var/release &> /dev/null
restore() {
git reset HEAD . && git checkout -- . && git clean -df && popd &> /dev/null
}
case $1 in
major|minor)
curr_version="$(curr_version)"
next_version="$(next_version "${curr_version}" "$1")"
branch="$(branch_alias "${next_version}")"
label "Releasing ${curr_version} -> ${next_version}"
confirm "Generate changelog?" yes
if [[ $? -eq 1 ]]; then
changelog "$(git rev-parse --abbrev-ref HEAD)" "${curr_version}" "${next_version}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
fi;
confirm "Bump version?" yes
if [[ $? -eq 1 ]]; then
bump_version "${branch}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
confirm "Bump msgphp dependencies?" yes
if [[ $? -eq 1 ]]; then
bump_deps "${branch}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
fi
fi
if [[ "${branch}" != 0.* ]]; then
confirm "Create release branch ${branch}?"
release_branch=$?
if [[ ${release_branch} -eq 1 ]]; then
git checkout --quiet -b "${branch}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
fi;
fi;
confirm "Tag version?" yes
if [[ $? -eq 1 ]]; then
tag "${next_version}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
fi;
if [[ ${release_branch} -eq 1 ]]; then
upcoming_branch="$(branch_alias "$(next_version "${next_version}" minor)")"
git checkout --quiet master && \
bump_version "${upcoming_branch}" && \
bump_deps "${upcoming_branch}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
fi
label "Done" ok
;;
patch)
for branch in $(release_branches); do
checkout "${branch}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
curr_version="$(curr_version)"
next_version="$(next_version "${curr_version}" patch)"
label "Releasing ${curr_version} -> ${next_version}"
changelog "$(git rev-parse --abbrev-ref HEAD)" "${curr_version}" "${next_version}" && \
tag "${next_version}"
[[ $? -ne 0 ]] && label "Failed" ko && restore && exit 1
label "Done" ok
done;
;;
esac
restore