forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_version
executable file
·71 lines (54 loc) · 2.27 KB
/
set_version
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import argparse
import os
import re
import sys
from subprocess import check_call
vendored_libbeat = os.path.normpath("vendor/github.com/elastic/beats")
goversion_template = '''package main
const appVersion = "{version}"
'''
goversion_template_libbeat = '''// Code generated by dev-tools/set_version
package version
const defaultBeatVersion = "{version}"
'''
yamlversion_template = '''version: "{version}"
'''
def get_rootfolder():
vendored_libbeat = os.path.normpath("vendor/github.com/elastic/beats")
script_directory = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
index = script_directory.find(vendored_libbeat)
if index > 0:
# Community beat detected, version files are stored at the root folder of the project
return os.path.abspath(script_directory[:index])
# Libbeat detected
return os.path.dirname(script_directory)
def create_from_template(filename, template, version):
with open(filename, "w") as f:
f.write(template.format(version=version))
print ("Set version {} in file {}".format(version, filename))
def main():
parser = argparse.ArgumentParser(
description="Used to set the current version. Doesn't commit changes.")
parser.add_argument("version",
help="The new version")
args = parser.parse_args()
version = args.version
is_libbeat = vendored_libbeat not in os.path.realpath(__file__)
if is_libbeat:
goversion_filepath = os.path.join(get_rootfolder(), "libbeat", "version", "version.go")
ymlversion_filepath = os.path.join(get_rootfolder(), "dev-tools", "packer", "version.yml")
go_template = goversion_template_libbeat
else:
goversion_filepath = os.path.join(get_rootfolder(), "version.go")
ymlversion_filepath = os.path.join(get_rootfolder(), "version.yml")
go_template = goversion_template
# Create version.go and version.yml files
create_from_template(goversion_filepath, go_template, version)
create_from_template(ymlversion_filepath, yamlversion_template, version)
# Updates all version files with the new templates
os.chdir(get_rootfolder())
print("Update build files")
check_call("make update", shell=True)
if __name__ == "__main__":
main()