Skip to content

Commit af7c9a9

Browse files
committed
chore: update update_refs.sh script to make output more digestable
1 parent 7da653f commit af7c9a9

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

_scripts/update_refs.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -euo pipefail
55
# repository branch references as well as the stackableRelease versions so that
66
# demos are properly versioned.
77

8+
# TODO (@NickLarsenNZ): Add an option to commit each change
9+
810
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
911

1012
# Ensure we are not on the `main` branch.
@@ -19,22 +21,35 @@ if ! git diff-index --quiet HEAD --; then
1921
exit 2
2022
fi
2123

24+
# prepend a string to each line of stdout
25+
function prepend {
26+
while read -r line; do
27+
echo -e "${1}${line}"
28+
done
29+
}
30+
2231
if [[ "$CURRENT_BRANCH" == release-* ]]; then
2332
STACKABLE_RELEASE="${CURRENT_BRANCH#release-}"
2433
echo "Updating stackableRelease to $STACKABLE_RELEASE"
25-
sed -i -E "s/(stackableRelease:\s+)(\S+)/\1${STACKABLE_RELEASE}/" stacks/stacks-v2.yaml
34+
# NOTE (@NickLarsenNZ): find is not required for such a trivial case, but it is done for consitency
35+
find stacks/stacks-v2.yaml \
36+
-exec grep --color=always -l stackableRelease {} \; \
37+
-exec sed -i -E "s/(stackableRelease:\s+)(\S+)/\1${STACKABLE_RELEASE}/" {} \; \
38+
| prepend "\t"
2639

2740
# TODO (@NickLarsenNZ): Replace 0.0.0-dev refs with ${STACKABLE_RELEASE}.0
2841
# handle patches later, and what about release-candidates?
29-
SEARCH='stackable(0\.0\.0-dev|24\.7\.\d+)' # TODO (@NickLarsenNZ): After https://github.com/stackabletech/stackable-cockpit/issues/310, only search for 0.0.0-dev
42+
SEARCH='stackable(0\.0\.0-dev|24\.7\.[0-9]+)' # TODO (@NickLarsenNZ): After https://github.com/stackabletech/stackable-cockpit/issues/310, only search for 0.0.0-dev
3043
REPLACEMENT="stackable${STACKABLE_RELEASE}.0" # TODO (@NickLarsenNZ): Be a bit smarter about patch releases.
3144
echo "Updating image references. Searching for $SEARCH, replacing with $REPLACEMENT"
3245
find demos stacks -type f \
33-
-exec sed -i -E "s/${SEARCH}/${REPLACEMENT}/" {} \;
46+
-exec grep --color=always -lE "$SEARCH" {} \; \
47+
-exec sed -i -E "s/${SEARCH}/${REPLACEMENT}/" {} \; \
48+
| prepend "\t"
3449

3550
# Look for remaining references
3651
echo "Checking files with older stackable release references which will be assumed to be intentional."
37-
grep --color=always -ronE "stackable24\.3(\.[0-9]+)"
52+
grep --color=always -ronE "stackable24\.3(\.[0-9]+)" | prepend "\t"
3853
else
3954
>&2 echo "WARNING: doesn't look like a release branch. Will not update stackableRelease versions in stacks."
4055
fi
@@ -45,8 +60,9 @@ echo "Replacing githubusercontent references main->${CURRENT_BRANCH}"
4560
# This is done just in case the branch has special regex characters (like `/`).
4661
# shellcheck disable=SC2016 # We intentionally don't want to expand the variable.
4762
find demos stacks -type f \
48-
-exec grep -l githubusercontent {} \; \
49-
-exec sed -i -E 's/(stackabletech\/demos)\/main\//\1\/\${UPDATE_BRANCH_REF}\//' {} \;
63+
-exec grep --color=always -l githubusercontent {} \; \
64+
-exec sed -i -E 's/(stackabletech\/demos)\/main\//\1\/\${UPDATE_BRANCH_REF}\//' {} \; \
65+
| prepend "\t"
5066

5167
# Now, for all modified files, we can use envsubst
5268
export UPDATE_BRANCH_REF="$CURRENT_BRANCH"

0 commit comments

Comments
 (0)