Skip to content

Commit d3e2bdb

Browse files
authored
updatecli: use .go-version (#335)
1 parent bad301b commit d3e2bdb

File tree

6 files changed

+42
-17
lines changed

6 files changed

+42
-17
lines changed

.buildkite/pipeline.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
env:
44
SETUP_GVM_VERSION: "v0.5.1"
5-
GOLANG_VERSION: "1.21.3"
65
IMAGE_UBUNTU_X86_64: "family/core-ubuntu-2204"
76
IMAGE_UBUNTU_ARM_64: "core-ubuntu-2004-aarch64"
87
DOCKER_REGISTRY: "docker.elastic.co"

.buildkite/scripts/common.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,31 @@
33
set -euo pipefail
44

55
REPO="golang-crossbuild"
6-
WORKSPACE="$(pwd)/bin"
6+
WORKSPACE="$(pwd)"
7+
BIN="${WORKSPACE}/bin"
78
HW_TYPE="$(uname -m)"
89
PLATFORM_TYPE="$(uname)"
910
TMP_FOLDER="tmp.${REPO}"
1011
GOOGLE_CREDENTIALS_FILENAME="google-cloud-credentials.json"
1112

13+
if [[ -z "${GOLANG_VERSION-""}" ]]; then
14+
export GOLANG_VERSION=$(cat "${WORKSPACE}/.go-version")
15+
fi
16+
1217
add_bin_path() {
1318
echo "Adding PATH to the environment variables..."
14-
create_workspace
15-
export PATH="${PATH}:${WORKSPACE}"
19+
create_bin
20+
export PATH="${PATH}:${BIN}"
1621
}
1722

1823
with_go() {
1924
local go_version="${1}"
2025
echo "Setting up the Go environment..."
21-
create_workspace
26+
create_bin
2227
check_platform_architecture
23-
retry 5 curl -sL -o ${WORKSPACE}/gvm "https://github.com/andrewkroh/gvm/releases/download/${SETUP_GVM_VERSION}/gvm-${PLATFORM_TYPE}-${arch_type}"
24-
export PATH="${PATH}:${WORKSPACE}"
25-
chmod +x ${WORKSPACE}/gvm
28+
retry 5 curl -sL -o ${BIN}/gvm "https://github.com/andrewkroh/gvm/releases/download/${SETUP_GVM_VERSION}/gvm-${PLATFORM_TYPE}-${arch_type}"
29+
export PATH="${PATH}:${BIN}"
30+
chmod +x ${BIN}/gvm
2631
eval "$(gvm "$go_version")"
2732
go version
2833
which go
@@ -37,15 +42,15 @@ with_mage() {
3742
"github.com/jstemmer/go-junit-report"
3843
"gotest.tools/gotestsum"
3944
)
40-
create_workspace
45+
create_bin
4146
for pkg in "${install_packages[@]}"; do
4247
go install "${pkg}@latest"
4348
done
4449
}
4550

46-
create_workspace() {
47-
if [[ ! -d "${WORKSPACE}" ]]; then
48-
mkdir -p ${WORKSPACE}
51+
create_bin() {
52+
if [[ ! -d "${BIN}" ]]; then
53+
mkdir -p ${BIN}
4954
fi
5055
}
5156

@@ -87,7 +92,7 @@ retry() {
8792
}
8893

8994
google_cloud_auth() {
90-
local gsUtilLocation=$(mktemp -d -p ${WORKSPACE} -t "${TMP_FOLDER}.XXXXXXXXX")
95+
local gsUtilLocation=$(mktemp -d -p ${BIN} -t "${TMP_FOLDER}.XXXXXXXXX")
9196
local secretFileLocation=${gsUtilLocation}/${GOOGLE_CREDENTIALS_FILENAME}
9297
echo "${PRIVATE_CI_GCS_CREDENTIALS_SECRET}" > ${secretFileLocation}
9398
gcloud auth activate-service-account --key-file ${secretFileLocation} 2> /dev/null
@@ -118,7 +123,7 @@ google_cloud_logout_active_account() {
118123

119124
cleanup() {
120125
echo "Deleting temporary files..."
121-
rm -rf ${WORKSPACE}/${TMP_FOLDER}.*
126+
rm -rf ${BIN}/${TMP_FOLDER}.*
122127
echo "Done."
123128
}
124129

.ci/bump-go-release-version.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ GOLANG_DOWNLOAD_SHA256_ARM=$(curl -s -L https://golang.org/dl/\?mode\=json | jq
2424
GOLANG_DOWNLOAD_SHA256_AMD=$(curl -s -L https://golang.org/dl/\?mode\=json | jq -r ".[] | select( .version | contains(\"go${GO_RELEASE_VERSION}\")) | .files[] | select (.filename | contains(\"go${GO_RELEASE_VERSION}.linux-amd64.tar.gz\")) | .sha256")
2525

2626
echo "Update go version ${GO_RELEASE_VERSION}"
27-
${SED} -E -e "s#(VERSION[[:space:]]+):= .*#\1:= ${GO_RELEASE_VERSION}#g" "go/Makefile.common"
28-
${SED} -E -e "s#(GO_VERSION[[:space:]]+)= .*#\1= '${GO_RELEASE_VERSION}'#g" Jenkinsfile
2927

3028
find "go" -type f -name Dockerfile.tmpl -print0 |
3129
while IFS= read -r -d '' line; do

.ci/bump-golang.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,30 @@ conditions:
7474
failwhen: true
7575

7676
targets:
77+
update-go-version:
78+
name: "Update .go-version"
79+
sourceid: latestGoVersion
80+
scmid: githubConfig
81+
kind: file
82+
spec:
83+
content: '{{ source "latestGoVersion" }}'
84+
file: .go-version
85+
matchpattern: '\d+.\d+.\d+'
86+
update-go-makefile.common:
87+
name: "Update go/Makefile.common"
88+
sourceid: latestGoVersion
89+
scmid: githubConfig
90+
kind: file
91+
spec:
92+
content: '{{ source "latestGoVersion" }}'
93+
file: go/Makefile.common
94+
matchpattern: '\d+.\d+.\d+'
7795
update-go-versions:
7896
name: 'Update go version {{ source "latestGoVersion" }}'
7997
kind: shell
8098
sourceid: latestGoVersion
8199
scmid: githubConfig
82100
spec:
83101
command: .ci/bump-go-release-version.sh
102+
environments:
103+
- name: PATH

.go-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.21.4

Jenkinsfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pipeline {
2929
DOCKER_REGISTRY_SECRET = 'secret/observability-team/ci/docker-registry/prod'
3030
DOCKER_REGISTRY = 'docker.elastic.co'
3131
STAGING_IMAGE = "${env.DOCKER_REGISTRY}/observability-ci"
32-
GO_VERSION = '1.21.4'
3332
BUILDX = "1"
3433
}
3534
options {
@@ -52,6 +51,9 @@ pipeline {
5251
deleteDir()
5352
gitCheckout(basedir: BASE_DIR)
5453
stash name: 'source', useDefaultExcludes: false
54+
dir("${BASE_DIR}"){
55+
setEnvVar('GO_VERSION', readFile(".go-version").trim())
56+
}
5557
}
5658
}
5759
stage('Package'){

0 commit comments

Comments
 (0)