1
+ import requests
2
+ import json
3
+ import os
4
+ import subprocess
5
+ import shlex
6
+ import shutil
7
+ import datetime
8
+
9
+ tag = os .environ .get ('RELEASE_TAG' )
10
+ benchmark_test = os .environ .get ('TEST' )
11
+ benchmark_repo = os .environ .get ('REPO' )
12
+ api_token = os .environ .get ('AUTH_TOKEN' )
13
+ jmeter_bin = '/home/vcadmin/jmeter/apache-jmeter-5.4.1/bin/jmeter'
14
+ brach_location = '~/loadtest'
15
+ rusults_dir = './results'
16
+ result_file_name = 'loadtest-result-{}-{}' .format (tag , datetime .datetime .now ().strftime ("%Y-%m-%d-%H-%M" ))
17
+ result_file_name_jtl = result_file_name + '.jtl'
18
+ git = f'git clone { benchmark_repo } '
19
+ loadtest = f'sh { jmeter_bin } -n -t { benchmark_test } -l { rusults_dir } /{ result_file_name_jtl } '
20
+ post_data = {
21
+ 'tag_name' : f'{ tag } ' ,
22
+ 'target_commitish' : 'loadtest' ,
23
+ 'name' : f'Loadtest result { tag } '
24
+ }
25
+ owner = "VirtoCommerce"
26
+ repo = "vc-deploy-dev"
27
+ query_url = f"https://api.github.com/repos/{ owner } /{ repo } /releases"
28
+ post_headers = headers = {
29
+ 'Authorization' : f'token { api_token } ' ,
30
+ 'Accept' : 'application/vnd.github.v3+json'
31
+ }
32
+
33
+ def run_command (command ):
34
+ process = subprocess .Popen (shlex .split (command ), stdout = subprocess .PIPE , text = True )
35
+ while True :
36
+ output = process .stdout .readline ()
37
+ if output == '' and process .poll () is not None :
38
+ break
39
+ if output :
40
+ print (output .strip ())
41
+ rc = process .poll ()
42
+ return rc
43
+
44
+
45
+
46
+ def github_release (file_name ):
47
+ response = requests .post (query_url , json .dumps (post_data , indent = 2 ), headers = post_headers )
48
+ print (response .json ())
49
+ release_id = (response .json ()['id' ])
50
+ if response .status_code == 201 :
51
+ print (f'Release { release_id } created' )
52
+ asset = open (f'{ file_name } ' , 'rb' )
53
+ upload_query_url = f"https://uploads.github.com/repos/{ owner } /{ repo } /releases/{ release_id } /assets?name={ file_name } "
54
+ upload_response = requests .post (upload_query_url , files = {"archive" : ("index.zip" , asset )}, headers = post_headers )
55
+ if upload_response .status_code == 201 :
56
+ print (f'File { file_name } uploaded' )
57
+ print (f'https://github.com/{ owner } /{ repo } /releases/tag/{ tag } ' )
58
+
59
+ def main ():
60
+ run_command ('rm -rf vc-benchmark' )
61
+ run_command (git )
62
+ run_command (loadtest )
63
+ shutil .make_archive (result_file_name , 'zip' , rusults_dir , result_file_name_jtl )
64
+ output_filename = result_file_name + '.zip'
65
+ github_release (output_filename )
66
+ os .remove (output_filename )
67
+
68
+ if __name__ == '__main__' :
69
+ main ()
0 commit comments