Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump golang version with the latest supported one #108

Merged
merged 2 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .ci/bump-go-release-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
#
# Given the Golang release 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.
#
# NOTE: sha256 is retrieved from https://pkg.go.dev/golang.org/x/website/internal/dl?utm_source=godoc
#
# Parameters:
# $1 -> the Golang release version to be bumped. Mandatory.
#
set -euo pipefail
MSG="parameter missing."
GO_RELEASE_VERSION=${1:?$MSG}
OS=$(uname -s| tr '[:upper:]' '[:lower:]')
if [ "${OS}" == "darwin" ] ; then
SED="sed -i .bck"
else
SED="sed -i"
fi

MAJOR_MINOR_VERSION=$(echo "$GO_RELEASE_VERSION" | sed -E -e "s#([0-9]+\.[0-9]+).*#\1#g")

GO_FOLDER="go${MAJOR_MINOR_VERSION}"
if [ -d "${GO_FOLDER}" ] ; then
echo "Update go version ${GO_RELEASE_VERSION}"
${SED} -E -e "s#(VERSION[[:space:]]+):= .*#\1:= ${GO_RELEASE_VERSION}#g" "${GO_FOLDER}/Makefile.common"
git add "${GO_FOLDER}/Makefile.common"
${SED} -E -e "s#(GO_VERSION[[:space:]]+)= .*#\1= '${GO_RELEASE_VERSION}'#g" Jenkinsfile
git add Jenkinsfile

find "${GO_FOLDER}" -type f -name Dockerfile.tmpl -print0 |
while IFS= read -r -d '' line; do
${SED} -E -e "s#(ARG GOLANG_VERSION)=[0-9]+\.[0-9]+\.[0-9]+#\1=${GO_RELEASE_VERSION}#g" "$line"
GOLANG_DOWNLOAD_SHA256=$(curl -s https://golang.org/dl/\?mode\=json | jq -r ".[] | select( .version | contains(\"go${GO_RELEASE_VERSION}\")) | .files[] | select (.filename | contains(\"go${GO_RELEASE_VERSION}.linux-arm64.tar.gz\")) | .sha256")
${SED} -E -e "s#(ARG GOLANG_DOWNLOAD_SHA256)=.+#\1=${GOLANG_DOWNLOAD_SHA256}#g" "$line"
git add "${line}"
done

git diff --staged --quiet || git commit -m "[Automation] Update go release version to ${GO_RELEASE_VERSION}"
git --no-pager log -1

echo "You can now push and create a Pull Request"
else
echo "A new minor version has been released. Bump cannot happen"
echo "Add Golang go${MAJOR_MINOR_VERSION} crossbuild images."
echo "See https://github.com/elastic/golang-crossbuild/pull/85"
echo "You might need to deprecate one of the existing Golang versions since"
echo "we only support the last two releases."
exit 1
fi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
.vagrant
_obj
Dockerfile
.status.*
.status.*
*.bck
12 changes: 12 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pull_request_rules:
- name: delete upstream branch after merging changes on Jenkinsfile or it's closed
conditions:
- or:
- merged
- closed
- and:
- label=automation
- head~=^update-go-version
- files~=^Jenkinsfile$
actions:
delete_head_branch: