Skip to content

Commit dd1141a

Browse files
committed
chore: update update_refs.sh script to optionally commit changes
1 parent af7c9a9 commit dd1141a

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

_scripts/update_refs.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ 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
8+
# Parse args:
9+
# $1 if `commit` is specified as the first argument, then changes will be staged and committed.
10+
COMMIT="${1:-false}"
11+
COMMIT="${COMMIT/commit/true}"
912

1013
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
1114

@@ -28,34 +31,51 @@ function prepend {
2831
done
2932
}
3033

34+
# stage and commit based on a message
35+
function maybe_commit {
36+
[ "$COMMIT" == "true" ] || return 0
37+
local MESSAGE="$1"
38+
PATCH=$(mktemp)
39+
git add -u
40+
git diff --staged > "$PATCH"
41+
git commit -m "$MESSAGE"
42+
echo "committed changes with message: $MESSAGE"
43+
echo "patch written to: $PATCH"
44+
}
45+
3146
if [[ "$CURRENT_BRANCH" == release-* ]]; then
3247
STACKABLE_RELEASE="${CURRENT_BRANCH#release-}"
33-
echo "Updating stackableRelease to $STACKABLE_RELEASE"
48+
MESSAGE="Update stackableRelease to $STACKABLE_RELEASE"
49+
echo "$MESSAGE"
3450
# NOTE (@NickLarsenNZ): find is not required for such a trivial case, but it is done for consitency
3551
find stacks/stacks-v2.yaml \
3652
-exec grep --color=always -l stackableRelease {} \; \
3753
-exec sed -i -E "s/(stackableRelease:\s+)(\S+)/\1${STACKABLE_RELEASE}/" {} \; \
3854
| prepend "\t"
55+
maybe_commit "chore(release): $MESSAGE"
3956

4057
# TODO (@NickLarsenNZ): Replace 0.0.0-dev refs with ${STACKABLE_RELEASE}.0
4158
# handle patches later, and what about release-candidates?
4259
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
4360
REPLACEMENT="stackable${STACKABLE_RELEASE}.0" # TODO (@NickLarsenNZ): Be a bit smarter about patch releases.
44-
echo "Updating image references. Searching for $SEARCH, replacing with $REPLACEMENT"
61+
MESSAGE="Update image references with $REPLACEMENT"
62+
echo "$MESSAGE"
4563
find demos stacks -type f \
4664
-exec grep --color=always -lE "$SEARCH" {} \; \
4765
-exec sed -i -E "s/${SEARCH}/${REPLACEMENT}/" {} \; \
4866
| prepend "\t"
67+
maybe_commit "chore(release): $MESSAGE"
4968

5069
# Look for remaining references
5170
echo "Checking files with older stackable release references which will be assumed to be intentional."
5271
grep --color=always -ronE "stackable24\.3(\.[0-9]+)" | prepend "\t"
72+
echo
5373
else
54-
>&2 echo "WARNING: doesn't look like a release branch. Will not update stackableRelease versions in stacks."
74+
>&2 echo "WARNING: doesn't look like a release branch. Will not update stackableRelease versions in stacks and image references."
5575
fi
5676

57-
echo
58-
echo "Replacing githubusercontent references main->${CURRENT_BRANCH}"
77+
MESSAGE="Replace githubusercontent references main->${CURRENT_BRANCH}"
78+
echo "$MESSAGE"
5979
# Search for githubusercontent urls and replace the branch reference with a placeholder variable
6080
# This is done just in case the branch has special regex characters (like `/`).
6181
# shellcheck disable=SC2016 # We intentionally don't want to expand the variable.
@@ -71,3 +91,4 @@ for MODIFIED_FILE in $(git diff --name-only); do
7191
envsubst '$UPDATE_BRANCH_REF' < "$MODIFIED_FILE" > "$MODIFIED_FILE.replacements"
7292
mv "$MODIFIED_FILE.replacements" "$MODIFIED_FILE"
7393
done
94+
maybe_commit "chore(release): $MESSAGE"

0 commit comments

Comments
 (0)