5
5
"""The main program to run functions."""
6
6
7
7
import os
8
+ import sys
8
9
import subprocess
9
10
10
11
from gitfx import parse_funcs
11
12
from gitfx import lang_version
12
13
13
14
14
15
ROOT_DIR = os .getenv ('GITHUB_WORKSPACE' , os .getcwd ())
16
+ WRITE_MODE = os .getenv ('GITFX_WRITE_MODE' , 'overwrite' )
15
17
16
18
SUPPORTED_LANGS = ['ruby' ,
17
19
'python' ,
@@ -87,16 +89,19 @@ def run_fun(func_path, func):
87
89
# decide language version
88
90
version = lang_version .get_version (func_path , func_lang ) or 'latest'
89
91
90
- if func_lang == 'bash' :
91
- cmd = ["bash" , os .path .join (func_path , func_file_name )]
92
- else :
93
- cmd = ['docker' , 'run' , '--rm' , '--workdir' , '/github/workspace' ,
94
- '-v' , ROOT_DIR + ':/github/workspace' ,
95
- docker_image (func_lang ) + ':' + version , 'sh' , '-c' ,
96
- "cd " + os .path .relpath (func_path , ROOT_DIR ) + " && " + # noqa
97
- deps_install_cmd (func_lang , func_path ) + " && " + # noqa
98
- run_before_script + " && " + # noqa
99
- RUN_CMDS [func_lang ] + " " + func_file_name ]
92
+ try :
93
+ if func_lang == 'bash' :
94
+ cmd = ["bash" , os .path .join (func_path , func_file_name )]
95
+ else :
96
+ cmd = ['docker' , 'run' , '--rm' , '--workdir' , '/github/workspace' ,
97
+ '-v' , ROOT_DIR + ':/github/workspace' ,
98
+ docker_image (func_lang ) + ':' + version , 'sh' , '-c' ,
99
+ "cd " + os .path .relpath (func_path , ROOT_DIR ) + " && " + # noqa
100
+ deps_install_cmd (func_lang , func_path ) + " && " + # noqa
101
+ run_before_script + " && " + # noqa
102
+ RUN_CMDS [func_lang ] + " " + func_file_name ]
103
+ except :
104
+ sys .exit (1 )
100
105
101
106
output = subprocess .Popen (cmd , stdout = subprocess .PIPE ).communicate ()[0 ]
102
107
return output .decode ("utf8" )
@@ -111,7 +116,10 @@ def write_to_route(result, func_route):
111
116
os .makedirs (dst_dir )
112
117
113
118
file_path = os .path .join (ROOT_DIR , func_route )
114
- f = open (file_path , 'w' )
119
+ if os .path .isfile (file_path ) and WRITE_MODE == 'append' :
120
+ f = open (file_path , 'a' )
121
+ else :
122
+ f = open (file_path , 'w' )
115
123
f .write (result )
116
124
f .close ()
117
125
0 commit comments