-
Notifications
You must be signed in to change notification settings - Fork 12
/
updateChangeLog
executable file
·263 lines (215 loc) · 8.46 KB
/
updateChangeLog
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/bin/bash
HYRAX_CHANGE_LOG=${1:-"HyraxChangeLog"}
COMMIT_UPDATES=${2:-""} # Anything not empty will trigger commits
debug=${debug:-""}
BUILD_RECIPE_FILE="./snapshot.time"
START_DIR=$PWD
COMPONENT_PROJECTS="libdap4 bes olfs"
export HR1="# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -"
export HR0="## -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"
function read_build_recipe() {
local build_recipe_file="${1}"
local build_recipe=""
if test -n "${debug}"; then
echo "${HR1}" >&2
echo "# Reading build recipe file: ${build_recipe_file}" >&2
echo "#" >&2
fi
local build_recipe=""
build_recipe=$(cat "${build_recipe_file}")
#if test -n "${debug}"; then
# echo "${build_recipe}" | awk '{print "## "$0;}' >&2
#fi
export RELEASE_DATE=""
RELEASE_DATE=${RELEASE_DATE:-$(echo "${build_recipe}" | grep hyrax | awk '{print $2;}')}
if test -n "${debug}"; then echo "# RELEASE_DATE: ${RELEASE_DATE}" >&2; fi
export HYRAX_VERSION=""
HYRAX_VERSION=${HYRAX_VERSION:-$(echo "${build_recipe}" | grep hyrax | awk '{print $1;}' | sed "s/hyrax-//g" )}
if test -n "${debug}"; then echo "# HYRAX_VERSION: ${HYRAX_VERSION}" >&2; fi
export OLFS_VERSION=""
OLFS_VERSION=${OLFS_VERSION:-$(echo "${build_recipe}" | grep olfs | sed "s/olfs-//g" | awk '{print $1;}')}
if test -n "${debug}"; then echo "# OLFS_VERSION: ${OLFS_VERSION}" >&2; fi
export BES_VERSION=""
BES_VERSION=${BES_VERSION:-$(echo "${build_recipe}" | grep bes | sed "s/bes-//g" | awk '{print $1;}')}
if test -n "${debug}"; then echo "# BES_VERSION: ${BES_VERSION}" >&2; fi
export LIBDAP_VERSION=""
LIBDAP_VERSION=${LIBDAP_VERSION:-$(echo "${build_recipe}" | grep libdap4 | sed "s/libdap4-//g"| awk '{print $1;}')}
if test -n "${debug}"; then echo "# LIBDAP_VERSION: ${LIBDAP_VERSION}" >&2; fi
if test -n "${debug}"; then echo "#" >&2; fi
}
function get_new_change_log_text(){
local proj_name="${1}"
local proj_version="${2}"
if test -n "${debug}"; then
echo "${HR1}" >&2
echo "# get_change_log_text()" >&2
echo "# proj_name: ${proj_name}" >&2
echo "# proj_version: ${proj_version}" >&2
echo "#" >&2
fi
local most_recent_entry=""
most_recent_entry=$(grep -e "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" ChangeLog | head -1 | awk '{print $1;}')
if test -n "${debug}"; then echo "# most_recent_entry: ${most_recent_entry}" >&2; fi
local orig_update_text=""
orig_update_text=$(gitlog-to-changelog --since="${most_recent_entry}")
if test -n "${debug}"; then
echo "#" >&2
echo "# orig_update_text:" >&2
echo "#" >&2
echo "${orig_update_text}" | awk '{print "## "$0;}' >&2
echo "#" >&2
fi
# Now that we have the raw change log entries, we use the canonical text
# processing system that is UNIX to make sure the lines are not too long and
# the indentation is correct.
local update_text=""
update_text=$(echo "${orig_update_text}" | \
fold -s -w 72 | \
awk '{
if(!match($0,"^[0-9]|^[\\t]")){
printf("\t%s\n",$0);
}
else{
print $0;
}
}')
# We know that the most_recent_entry date string is the most recent
# entry in the ChangeLog, but that entry already exists. And
# because of the lazy way we invoked gitlog-to-changelog using
# the most_recent_entry value, we got back that entry as well. Rather
# than doing the painful date time arithemetic we just use the fact
# that the most_recent_entry entry is in both the existing ChangeLog and
# is the last entry in the update_text, we just prune it from the
# update test and we are off to the races.
# Find the beginning of the last entry in the update text.
local location_of_most_recent_entry=""
location_of_most_recent_entry=$( echo "${update_text}" | \
grep -n "${most_recent_entry}" | \
head -1 | \
awk '{split($1,a,":");print a[1]-1;}')
# echo "${update_text}" | grep -n "${most_recent_entry}" # | head -1 | awk '{split($1,a,":");print a[1]-1;}')
if test -n "${debug}"; then
echo "# location_of_most_recent_entry: ${location_of_most_recent_entry}" >&2
echo "#" >&2
fi
if test -n "${location_of_most_recent_entry}" && \
test ${location_of_most_recent_entry} -gt 0
then
# Prune the most recent entry to avoid duplication
update_text=$(echo "${update_text}" | head -n "${location_of_most_recent_entry}")
else
echo "Warning: Did not find most_recent entry in new changes. Skipping..." >&2
fi
# Add a banner for this update
update_text=$( \
echo "${HR0}"; \
echo "## ${proj_name}-${proj_version}"; \
echo "## hyrax-${HYRAX_VERSION}"; \
echo "##"; \
echo ""; \
echo "${update_text}"; \
echo " "; )
if test -n "${debug}"; then
# Show the result for debuggin
echo "# update_text:" >&2
echo "#" >&2
echo "${update_text}" | awk '{print "### "$0;}' >&2
echo "#" >&2
echo "${HR1}" >&2
echo "" >&2
fi
# The return value from this function.
echo "${update_text}"
}
function prepend_to_file(){
prepend_text="${1}"
target_file="${2}"
#set -v
echo "${prepend_text}" > foo
cat "${target_file}" >> foo
mv foo "${target_file}"
#set +v
}
function mk_hyrax_changelog_entry(){
local libdap4_txt="${1}"
local bes_txt="${2}"
local olfs_txt="${3}"
# Print just the right stuff to stdout.
echo ""
echo "${HR0}"
echo "## Hyrax Version ${HYRAX_VERSION} (date: ${RELEASE_DATE})"
echo "##"
echo "## olfs-${OLFS_VERSION}"
echo "## bes-${BES_VERSION}"
echo "## libdap-${LIBDAP_VERSION}"
echo "##"
echo " "
echo "${libdap4_txt}"
echo "${bes_txt}"
echo "${olfs_txt}"
}
function undo_updates() {
use_git_reset="${1}"
for proj in ${COMPONENT_PROJECTS}
do
cd "../${proj}" || exit;
if test -n "${use_git_reset}"; then
git reset HEAD~
fi
git checkout -- ChangeLog;
done
cd "${START_DIR}" || exit
if test -n "${use_git_reset}"; then
git reset HEAD~
fi
git checkout -- "${HYRAX_CHANGE_LOG}"
}
function update_project_change_log(){
local proj_name="${1}"
local proj_version="${2}"
local commit_changes="${3}"
cd "../${proj_name}" || exit 1;
local change_log_text=
change_log_text=$(get_new_change_log_text "${proj_name}" "${proj_version}")
prepend_to_file "${change_log_text}" ./ChangeLog
if test -n "${commit_changes}"; then
echo "# ${proj_name}: Committing changes to git" >&2
git commit -m "Updating ChangeLog for ${proj_name}-${proj_version} (hyrax-${HYRAX_VERSION}) [skip ci]" ./ChangeLog >&2
git push
fi
cd "${START_DIR}" || exit 1;
echo "${change_log_text}"
}
function update_hyrax_combined_change_log(){
local change_log_text="${1}"
local commit_changes="${2}"
cd "${START_DIR}" || exit
prepend_to_file "${change_log_text}" "${HYRAX_CHANGE_LOG}"
if test -n "${commit_changes}"; then
echo "# hyrax-docker: Committing changes to git" >&2
git commit -m "Updating Hyrax combined ChangeLog (hyrax-${HYRAX_VERSION})
Build Version Matrix:
libdap4-${LIBDAP_VERSION}
bes-${BES_VERSION}
olfs-${OLFS_VERSION}
hyrax-${HYRAX_VERSION}
" "${HYRAX_CHANGE_LOG}" >&2
fi
}
function updateHyraxChangeLogs() {
if test -n "${debug}"; then
echo "${HR0}";
echo "# "$(basename $0)
echo "#"
fi
read_build_recipe "${BUILD_RECIPE_FILE}"
libdap4_change_log_text=$(update_project_change_log libdap4 "${LIBDAP_VERSION}" "${COMMIT_UPDATES}")
bes_change_log_text=$(update_project_change_log bes "${BES_VERSION}" "${COMMIT_UPDATES}")
olfs_change_log_text=$(update_project_change_log olfs "${OLFS_VERSION}" "${COMMIT_UPDATES}")
hyrax_clog_entry=$(mk_hyrax_changelog_entry \
"${libdap4_change_log_text}" \
"${bes_change_log_text}" \
"${olfs_change_log_text}")
update_hyrax_combined_change_log "${hyrax_clog_entry}" "${COMMIT_UPDATES}"
}
updateHyraxChangeLogs