forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump-stack-version.sh
executable file
·49 lines (43 loc) · 1.33 KB
/
bump-stack-version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
#
# Given the stack version this script will bump the version.
#
# This script is executed by the automation we are putting in place
# and it requires the git add/commit commands.
#
# Parameters:
# $1 -> the version to be bumped. Mandatory.
# $2 -> whether to create a branch where to commit the changes to.
# this is required when reusing an existing Pull Request.
# Optional. Default true.
#
set -euo pipefail
MSG="parameter missing."
VERSION=${1:?$MSG}
CREATE_BRANCH=${2:-true}
OS=$(uname -s| tr '[:upper:]' '[:lower:]')
if [ "${OS}" == "darwin" ] ; then
SED="sed -i .bck"
else
SED="sed -i"
fi
FILES="testing/environments/snapshot-oss.yml
testing/environments/snapshot.yml
"
echo "Update stack with version ${VERSION}"
for FILE in ${FILES} ; do
${SED} -E -e "s#(image: docker\.elastic\.co/.*):[0-9]+\.[0-9]+\.[0-9]+(-[a-f0-9]{8})?#\1:${VERSION}#g" $FILE
done
echo "Commit changes"
if [ "$CREATE_BRANCH" = "true" ]; then
base=$(git rev-parse --abbrev-ref HEAD | sed 's#/#-#g')
git checkout -b "update-stack-version-$(date "+%Y%m%d%H%M%S")-${base}"
else
echo "Branch creation disabled."
fi
for FILE in ${FILES} ; do
git add $FILE
done
git diff --staged --quiet || git commit -m "[Automation] Update elastic stack version to ${VERSION} for testing"
git --no-pager log -1
echo "You can now push and create a Pull Request"