|
|
@@ -27,6 +27,7 @@ class Build:
|
|
|
def __init__(self) -> None:
|
|
|
self.date_build: str = str(datetime.datetime.now())
|
|
|
"""Дата сборки"""
|
|
|
+ self.date_build = self.date_build.replace(" ", "_")
|
|
|
|
|
|
cmd: list[str] = ['git', 'describe', '--tags', '--abbrev=0']
|
|
|
output: bytes = subprocess.Popen(
|
|
|
@@ -39,7 +40,7 @@ class Build:
|
|
|
cmd = ['go', 'version']
|
|
|
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
|
|
|
go_version: str = output.decode("utf-8")
|
|
|
- go_version = go_version[11:]
|
|
|
+ go_version = go_version[11:][:-1].replace(" ", "_")
|
|
|
out: str = f"date={self.date_build}\t\t" +\
|
|
|
f"tag={self.tag}\t\t" +\
|
|
|
f"go_version={go_version}"
|
|
|
@@ -50,6 +51,7 @@ class Build:
|
|
|
|
|
|
def run(self) -> None:
|
|
|
"""Запуск сборки"""
|
|
|
+ print("cleaning")
|
|
|
try:
|
|
|
shutil.rmtree('./bin')
|
|
|
except OSError:
|
|
|
@@ -70,13 +72,71 @@ class Build:
|
|
|
os.mkdir("bin/web/tmpl")
|
|
|
except FileExistsError:
|
|
|
pass
|
|
|
+ print("copying")
|
|
|
os.system('cp -r ../app_serv/web ./bin')
|
|
|
os.chdir("../app_serv")
|
|
|
- # os.system("go build -o app_work")
|
|
|
+ print("format")
|
|
|
+ os.system("go fmt ./...")
|
|
|
+ print("build")
|
|
|
+ cmd: str = """go build -ldflags "-w -s -X """ +\
|
|
|
+ f"""main.GoVersion={self.go_version} -X """ +\
|
|
|
+ """main.Version=$TAG -X """ +\
|
|
|
+ """main.Date=$BUILD_DATE" -o """ +\
|
|
|
+ '../app_work/bin/server.exe ./cmd/server/main.go'
|
|
|
+ print(cmd)
|
|
|
+ os.system(cmd)
|
|
|
+ os.chdir("../app_work")
|
|
|
+ print('stripping')
|
|
|
+ os.system('strip -s ./bin/server.exe')
|
|
|
+ print('packing exe')
|
|
|
+ os.system('upx -f ./bin/server.exe')
|
|
|
+ exeSize: int = os.path.getsize("./bin/server.exe")
|
|
|
+ print(f'size exe={exeSize/1000**2:.2f} MB')
|
|
|
|
|
|
- cmd: list[str] = ['go', 'fmt', './...']
|
|
|
- subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
|
|
|
- # go_version: str = output.decode("utf-8")
|
|
|
+
|
|
|
+class Dev:
|
|
|
+ """Класс разработки
|
|
|
+ """
|
|
|
+
|
|
|
+ def __init__(self) -> None:
|
|
|
+ pass
|
|
|
+
|
|
|
+ def run(self) -> None:
|
|
|
+ print("cleaning")
|
|
|
+ try:
|
|
|
+ shutil.rmtree('./bin')
|
|
|
+ except OSError:
|
|
|
+ pass
|
|
|
+ try:
|
|
|
+ os.mkdir("bin")
|
|
|
+ except FileExistsError:
|
|
|
+ pass
|
|
|
+ try:
|
|
|
+ os.mkdir("bin/web")
|
|
|
+ except FileExistsError:
|
|
|
+ pass
|
|
|
+ try:
|
|
|
+ os.mkdir("bin/web/static")
|
|
|
+ except FileExistsError:
|
|
|
+ pass
|
|
|
+ try:
|
|
|
+ os.mkdir("bin/web/tmpl")
|
|
|
+ except FileExistsError:
|
|
|
+ pass
|
|
|
+ print("copying")
|
|
|
+ os.system('cp -r ../app_serv/web ./bin')
|
|
|
+ os.chdir("../app_serv")
|
|
|
+ print("format")
|
|
|
+ os.system("go fmt ./...")
|
|
|
+ print("build")
|
|
|
+ cmd: str = """go build -race """ +\
|
|
|
+ '-o ../app_work/bin/server.exe ./cmd/server/main.go'
|
|
|
+ print(cmd)
|
|
|
+ os.system(cmd)
|
|
|
+ os.chdir("../app_work/bin")
|
|
|
+ os.unsetenv('STAGE')
|
|
|
+ os.putenv('STAGE', 'local')
|
|
|
+ os.system('./server.exe')
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
@@ -92,6 +152,9 @@ if __name__ == '__main__':
|
|
|
case"build": # Сборка всей программы
|
|
|
b: Build = Build()
|
|
|
b.run()
|
|
|
+ case "dev": # Разработка
|
|
|
+ d: Dev = Dev()
|
|
|
+ d.run()
|
|
|
case "":
|
|
|
help()
|
|
|
case _: pass
|