Skip to content

Commit 7570441

Browse files
committed
scripts: Only update content when created
1 parent 04451ef commit 7570441

1 file changed

Lines changed: 32 additions & 20 deletions

File tree

migration/promote.sh

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@ usage() {
1515
"
1616
}
1717

18-
main() {
19-
local series="${1:-}"
20-
21-
[[ -n "${series}" ]] || log.fatal "missing required argument $(esc.ylw "<release-series>"), $(usage)"
22-
23-
ver.parse next "${series}"
24-
25-
local target_version="v${ver["next-major"]}.${ver["next-minor"]}"
26-
local target_migration="${ROOT}/migration/${target_version}"
27-
18+
create() {
19+
# check if the target migration already exists
2820
if [[ -d "${target_migration}" ]]; then
2921
if log.continue "migration $(esc.ylw "${target_version}") already exists, do you want to recreate it?"; then
3022
log.warn "removing migration $(esc.ylw "${target_version}")"
3123
rm -r "${target_migration}"
3224
else
33-
log.warn "skipping"
25+
log.warn "skipping recreation"
26+
return
3427
fi
3528
fi
3629

@@ -39,8 +32,7 @@ main() {
3932
cp -Tr "${ROOT}/migration/main" "${target_migration}"
4033
fi
4134

42-
# Find prev
43-
35+
# find current migration directories
4436
local -a directories
4537
readarray -t directories < <(find "${ROOT}/migration" -maxdepth 1 -type d -name 'v*')
4638

@@ -49,6 +41,7 @@ main() {
4941
ver.parse "${directory}" "${directory}"
5042
done
5143

44+
# the previous - the greatest excluding the current
5245
local prev="prev"
5346
ver.parse "${prev}" "v0.0"
5447

@@ -65,25 +58,30 @@ main() {
6558
yq --inplace --front-matter process ".to =\"${target_version}\"" "${target_migration}/README.md"
6659
yq --inplace --front-matter process ".from =\"${target_version}\"" "${ROOT}/migration/main/README.md"
6760

68-
# Update header
61+
# update header
6962
sed -i "s/# Main upgrade and migration/# ${target_version} upgrade and migration/" "${target_migration}/README.md"
70-
# Update preamble
63+
# update preamble
7164
sed -i "/^<\!-- begin preamble --->$/,/^<\!--- end preamble --->$/c\\
7265
> [\!important]\\
7366
> This is the upgrade and migration process for Welkin Apps ${target_version}.\\
7467
>\\
7568
> Upgrade is supported from any patch version of the major or minor version stated in the \`from\` field above!" "${target_migration}/README.md"
76-
# Update changelog
69+
# update changelog
7770
sed -i "s#\.\./\.\./changelog#../../changelog/${target_version}.md#" "${target_migration}/README.md"
78-
# Update fetch
71+
# update fetch
7972
sed -i "s/Switch to the main branch and pull the latest changes/Fetch the latest changes and switch to the release tag/" "${target_migration}/README.md"
8073
sed -i "s/git switch main/git fetch/" "${target_migration}/README.md"
8174
sed -i "s/git pull/git switch -d ${target_version}.z/" "${target_migration}/README.md"
75+
}
8276

83-
# Prune
77+
prune() {
78+
# find current migration directories
79+
local -a directories
80+
readarray -t directories < <(find "${ROOT}/migration" -maxdepth 1 -type d -name 'v*')
8481

82+
# until we have five migrations left
8583
while [[ "${#directories[*]}" -gt 5 ]]; do
86-
# Find last
84+
# the last - the least including the current
8785
local last="${target_version}"
8886
ver.parse "${last}" "${target_version}"
8987

@@ -98,9 +96,23 @@ main() {
9896
log.info "pruning old migration $(esc.blu "${last}")"
9997
rm -r "${ROOT}/migration/${last}"
10098

101-
local -a directories
10299
readarray -t directories < <(find "${ROOT}/migration" -maxdepth 1 -type d -name 'v*')
103100
done
104101
}
105102

103+
main() {
104+
local series="${1:-}"
105+
106+
[[ -n "${series}" ]] || log.fatal "missing required argument $(esc.ylw "<release-series>"), $(usage)"
107+
108+
ver.parse next "${series}"
109+
110+
local target_version="v${ver["next-major"]}.${ver["next-minor"]}"
111+
local target_migration="${ROOT}/migration/${target_version}"
112+
113+
create
114+
115+
prune
116+
}
117+
106118
main "${@}"

0 commit comments

Comments
 (0)