Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
chore: improve the automation for the stack version bump (#1351)
Browse files Browse the repository at this point in the history
* feat: automated update Beats' base version

* chore: reduce number of version occurrences in tests

* chore: decouple unit tests from the current version

* feat: update Jenkinsfile

* feat: automate .stack-version

* fix: append snapshot

* chore: simplify finding single files

There is only one file to modify

(cherry picked from commit 395bdb2)

# Conflicts:
#	.ci/bump-stack-version.sh
#	internal/_testresources/gcp/commits.json
#	internal/_testresources/gcp/snapshots.json
#	internal/utils/utils_test.go
  • Loading branch information
mdelapenya authored and mergify-bot committed Jul 22, 2021
1 parent 11f24e2 commit 5107970
Show file tree
Hide file tree
Showing 15 changed files with 7,388 additions and 1 deletion.
65 changes: 65 additions & 0 deletions .ci/bump-stack-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/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

echo "Update stack with version ${VERSION} in .stack-version"
echo "${VERSION}-SNAPSHOT" > .stack-version
git add .stack-version

echo "Update stack with version ${VERSION} in Go files"
FILE="./internal/common/defaults.go"
${SED} -E -e "s#(var BeatVersionBase = (\"))[0-9]+\.[0-9]+\.[0-9]+(-[a-f0-9]{8})?#\1${VERSION}#g" $FILE
git add $FILE

echo "Update stack with version ${VERSION} in Jenkinsfile"
FILE="./.ci/Jenkinsfile"
${SED} -E -e "s#(name: 'BEAT_VERSION', defaultValue: ')[0-9]+\.[0-9]+\.[0-9]+(-[a-f0-9]{8})?#\1${VERSION}#g" $FILE
${SED} -E -e "s#(name: 'STACK_VERSION', defaultValue: ')[0-9]+\.[0-9]+\.[0-9]+(-[a-f0-9]{8})?#\1${VERSION}#g" $FILE
git add $FILE

echo "Update stack with version ${VERSION} in docker-compose.yml"
find . -name 'docker-compose.yml' -path './cli/config/compose/profiles/*' -print0 |
while IFS= read -r -d '' FILE ; do
${SED} -E -e "s#(image: (\")?docker\.elastic\.co/.*):-[0-9]+\.[0-9]+\.[0-9]+(-[a-f0-9]{8})?#\1:-${VERSION}#g" $FILE
git add $FILE
done

echo "Update stack with version ${VERSION} in deployment.yaml"
find . -name 'deployment.yaml' -print0 |
while IFS= read -r -d '' FILE ; do
${SED} -E -e "s#(image: docker\.elastic\.co/.*):[0-9]+\.[0-9]+\.[0-9]+(-[a-f0-9]{8})?#\1:${VERSION}#g" $FILE
git add $FILE
done

echo "Commit changes"
if [ "$CREATE_BRANCH" = "true" ]; then
git checkout -b "update-stack-version-$(date "+%Y%m%d%H%M%S")"
else
echo "Branch creation disabled."
fi
git diff --staged --quiet || git commit -m "bump stack version ${VERSION}"
git --no-pager log -1

echo "You can now push and create a Pull Request"
5,709 changes: 5,709 additions & 0 deletions internal/_testresources/gcp/commits.json

Large diffs are not rendered by default.

1,463 changes: 1,463 additions & 0 deletions internal/_testresources/gcp/snapshots.json

Large diffs are not rendered by default.

Loading

0 comments on commit 5107970

Please sign in to comment.