File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ CURRENT_BRANCH=$( git rev-parse --abbrev-ref HEAD)
5+
6+ # Ensure we are not on the `main` branch.
7+ if [[ " $CURRENT_BRANCH " == " main" ]]; then
8+ >&2 echo " Will not replace github references for the main branch. Exiting."
9+ exit 1
10+ fi
11+
12+ # Ensure the index is clean
13+ if ! git diff-index --quiet HEAD --; then
14+ >&2 echo " Dirty git index. Check working tree or staged changes. Exiting."
15+ exit 2
16+ fi
17+
18+ # Warn if the branch isn't a `release-*` branch (these changes shouldn't be in a branch that gets merged to main)
19+ if [[ " $CURRENT_BRANCH " != release-* ]]; then
20+ >&2 echo " WARNING: doesn't look like a release branch. Continuing anyway."
21+ fi
22+
23+ # Search for githubusercontent urls and replace the branch reference with a placeholder variable
24+ # This is done just in case the branch has special regex characters (like `/`).
25+ # shellcheck disable=SC2016 # We intentionally don't want to expand the variable.
26+ find demos stacks -type f \
27+ -exec grep -l githubusercontent {} \; \
28+ -exec sed -i -E ' s/(stackabletech\/demos)\/main\//\1\/\${UPDATE_BRANCH_REF}\//' {} \;
29+
30+ # Now, for all modified files, we can use envsubst
31+ export UPDATE_BRANCH_REF=" $CURRENT_BRANCH "
32+ for MODIFIED_FILE in $( git diff --name-only) ; do
33+ # shellcheck disable=SC2016 # We intentionally don't want to expand the variable.
34+ envsubst ' $UPDATE_BRANCH_REF' < " $MODIFIED_FILE " > " $MODIFIED_FILE .replacements"
35+ mv " $MODIFIED_FILE .replacements" " $MODIFIED_FILE "
36+ done
You can’t perform that action at this time.
0 commit comments