Skip to content

Move agent version to .agent-version file #6622

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .buildkite/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fi
if [[ -z "${SETUP_GVM_VERSION-""}" ]]; then
SETUP_GVM_VERSION="v0.5.2" # https://github.com/andrewkroh/gvm/issues/44#issuecomment-1013231151
fi
BEAT_VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' "${WORKSPACE}/version/version.go")
BEAT_VERSION=$(cat version/.agent-version)
export BEAT_VERSION

getOSOptions() {
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/scripts/common2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [[ -z "${WORKSPACE-""}" ]]; then
export WORKSPACE
fi

BEAT_VERSION=$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' "${WORKSPACE}/version/version.go")
BEAT_VERSION=$(cat version/.agent-version)
export BEAT_VERSION

getOSOptions() {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fragment-in-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
./bin/elastic-agent-changelog-tool pr-has-fragment --repo ${{ github.event.repository.name }} ${{github.event.number}}
- name: get elasti-agent version
run: |
gv=$(awk '$0 ~ /[0-9]+\.[0-9]+\.[0-9]+/ {print $4}' version/version.go)
gv=$(cat version/.agent-version)
echo "agent-version=$gv" >> $GITHUB_OUTPUT
id: agent-version
- name: check fragment-syntax
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := /bin/bash

ALL=elastic-agent-standalone elastic-agent-managed
WORKSPACE=$(shell git rev-parse --show-toplevel)
BEAT_VERSION=$(shell grep -oE '[0-9]+\.[0-9]+\.[0-9]+(\-[a-zA-Z]+[0-9]+)?' "${WORKSPACE}/version/version.go")
BEAT_VERSION=$(shell cat "${WORKSPACE}/version/.agent-version")
BRANCH_VERSION=$(shell cut -d. -f1-2 <<< '${BEAT_VERSION}')

#variables needed for ci-create-kubernetes-templates-pull-request
Expand Down
30 changes: 7 additions & 23 deletions dev-tools/set_version
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@ def get_rootfolder():
# Libbeat detected
return os.path.dirname(script_directory)

def replace_in_file(filename, varname, version):
new_lines = []
with open(filename, 'r') as f:
for line in f:
if line.startswith("const " + varname):
new_lines.append('const {} = "{}"\n'.format(varname, version))
else:
new_lines.append(line)

def replace_in_file(filename, version):
with open(filename, 'w') as f:
for line in new_lines:
f.write(line)
f.write(version)

print ("Set version {} in file {}".format(version, filename))

def main():
Expand All @@ -43,18 +35,10 @@ def main():
parser.add_argument("version",
help="The new version")
args = parser.parse_args()
version = args.version

is_libbeat = vendored_elastic_agent not in os.path.realpath(__file__)
if is_libbeat:
goversion_filepath = os.path.join(get_rootfolder(), "version", "version.go")
go_var = goversion_var_elastic_agent
else:
goversion_filepath = os.path.join(get_rootfolder(), "version.go")
go_var = goversion_var

# Create version.go and version.yml files
replace_in_file(goversion_filepath, go_var, version)
version = args.version
goversion_filepath = os.path.join(get_rootfolder(), "version", ".agent-version")
# Update version/.agent-version file
replace_in_file(goversion_filepath, version)

if __name__ == "__main__":
main()
Expand Down
2 changes: 1 addition & 1 deletion testing/environments/cloud/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif
ifeq (${SNAPSHOT}, 0)
SNAPSHOT_SUFFIX:=""
endif
VERSION:=$(shell grep "const defaultBeatVersion =" ${REPO_ROOT}/version/version.go | cut -d\" -f2)${SNAPSHOT_SUFFIX}
VERSION:=$(shell cat ${REPO_ROOT}/version/.agent-version)${SNAPSHOT_SUFFIX}

export DOCKER_BUILDKIT=1

Expand Down
3 changes: 1 addition & 2 deletions testing/environments/cloud/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ terraform {
provider "ec" {}

locals {
match = regex("const defaultBeatVersion = \"(.*)\"", file("${path.module}/../../../version/version.go"))[0]
stack_version = format("%s-SNAPSHOT", local.match)
stack_version = format("%s-SNAPSHOT", file("${path.module}/../../../version/.agent-version"))
}

module "ec_deployment" {
Expand Down
1 change: 1 addition & 0 deletions version/.agent-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9.0.0
7 changes: 5 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

package version

const defaultBeatVersion = "9.0.0"
const Agent = defaultBeatVersion
import _ "embed"

//go:embed .agent-version
var defaultBeatVersion string
var Agent = defaultBeatVersion