Skip to content

Commit 8c241bc

Browse files
committed
refactor: create generic function to increment version in simple version files
1 parent beaf189 commit 8c241bc

File tree

1 file changed

+14
-45
lines changed

1 file changed

+14
-45
lines changed

docs/devbook/bump-versions/bump_versions.sh

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -153,58 +153,26 @@ update_openapi_version() {
153153
OPEN_API_UPDATE_MESSAGE=" and \`$OPEN_API_FILE\` version"
154154
}
155155

156-
update_infra_version() {
156+
update_plain_version_file() {
157157
local -r dry_run=$1
158-
local -r version_line=$(cat $INFRA_VERSION_FILE | head -n 1)
159-
local -r patch_number=$(echo "$version_line" | cut -d . -f 3)
160-
local -r next_patch_number=$((patch_number + 1))
161-
local -r new_version=$(echo "$version_line" | cut -d . -f 1-2).$next_patch_number
162-
163-
echo -e " ${GREEN}Upgrading${RESET} $INFRA_VERSION_FILE from ${version_line} to ${new_version}"
164-
if [ true = "$dry_run" ]
165-
then
166-
echo -e "${ORANGE}warning${RESET}: aborting $INFRA_VERSION_FILE update due to dry run"
167-
else
168-
echo -e "$new_version\n" > $INFRA_VERSION_FILE
169-
fi
170-
INFRA_UPDATE="\n* $INFRA_VERSION_FILE from \`${version_line}\` to \`${new_version}\`"
171-
INFRA_UPDATE_MESSAGE=" and \`$INFRA_VERSION_FILE\` version"
172-
}
173-
174-
update_devnet_version() {
175-
local -r dry_run=$1
176-
local -r version_line=$(cat $DEVNET_VERSION_FILE | head -n 1)
177-
local -r patch_number=$(echo "$version_line" | cut -d . -f 3)
178-
local -r next_patch_number=$((patch_number + 1))
179-
local -r new_version=$(echo "$version_line" | cut -d . -f 1-2).$next_patch_number
158+
local -r version_file=$2
159+
local -r var_name_prefix=$3
180160

181-
echo -e " ${GREEN}Upgrading${RESET} $DEVNET_VERSION_FILE from ${version_line} to ${new_version}"
182-
if [ true = "$dry_run" ]
183-
then
184-
echo -e "${ORANGE}warning${RESET}: aborting $DEVNET_VERSION_FILE update due to dry run"
185-
else
186-
echo -e "$new_version\n" > $DEVNET_VERSION_FILE
187-
fi
188-
DEVNET_UPDATE="\n* $DEVNET_VERSION_FILE from \`${version_line}\` to \`${new_version}\`"
189-
DEVNET_UPDATE_MESSAGE=" and \`$DEVNET_VERSION_FILE\` version"
190-
}
191-
192-
update_benchmark_version() {
193-
local -r dry_run=$1
194-
local -r version_line=$(cat $BENCHMARK_VERSION_FILE | head -n 1)
161+
local -r version_line=$(head -n 1 "$version_file")
195162
local -r patch_number=$(echo "$version_line" | cut -d . -f 3)
196163
local -r next_patch_number=$((patch_number + 1))
197164
local -r new_version=$(echo "$version_line" | cut -d . -f 1-2).$next_patch_number
198165

199-
echo -e " ${GREEN}Upgrading${RESET} $BENCHMARK_VERSION_FILE from ${version_line} to ${new_version}"
166+
echo -e " ${GREEN}Upgrading${RESET} $version_file from ${version_line} to ${new_version}"
200167
if [ true = "$dry_run" ]
201168
then
202-
echo -e "${ORANGE}warning${RESET}: aborting $BENCHMARK_VERSION_FILE update due to dry run"
169+
echo -e "${ORANGE}warning${RESET}: aborting $version_file update due to dry run"
203170
else
204-
echo -e "$new_version\n" > $BENCHMARK_VERSION_FILE
171+
echo -e "$new_version\n" > "$version_file"
205172
fi
206-
BENCHMARK_UPDATE="\n* $BENCHMARK_VERSION_FILE from \`${version_line}\` to \`${new_version}\`"
207-
BENCHMARK_UPDATE_MESSAGE=" and \`$BENCHMARK_VERSION_FILE\` version"
173+
174+
eval "${var_name_prefix}_UPDATE=\"\n* $version_file from \\\`${version_line}\\\` to \\\`${new_version}\\\`\""
175+
eval "${var_name_prefix}_UPDATE_MESSAGE=\" and \\\`$version_file\\\` version\""
208176
}
209177

210178
################
@@ -237,19 +205,20 @@ fi
237205

238206
if [ "$(echo "${FILES_MODIFY[@]}" | grep -c "^mithril-infra/.*\.tf$")" -gt 0 ]
239207
then
240-
update_infra_version $DRY_RUN
208+
update_plain_version_file $DRY_RUN "$INFRA_VERSION_FILE" "INFRA"
241209
fi
242210

243211
if [ "$(echo "${FILES_MODIFY[@]}" | grep -c "^mithril-test-lab/mithril-devnet/.*\.sh$")" -gt 0 ]
244212
then
245-
update_devnet_version $DRY_RUN
213+
update_plain_version_file $DRY_RUN "$DEVNET_VERSION_FILE" "DEVNET"
246214
fi
247215

248216
if [ "$(echo "${FILES_MODIFY[@]}" | grep -c "^mithril-test-lab/benchmark/aggregator-prover/.*\.sh$")" -gt 0 ]
249217
then
250-
update_benchmark_version $DRY_RUN
218+
update_plain_version_file $DRY_RUN "$BENCHMARK_VERSION_FILE" "BENCHMARK"
251219
fi
252220

221+
253222
if [ true = $DRY_RUN ]
254223
then
255224
echo -e "${ORANGE}warning${RESET}: script is run in dry mode. To apply the changes, run ${GREEN}$0 --run${RESET}"

0 commit comments

Comments
 (0)