55"""The main program to run functions."""
66
77import os
8+ import sys
89import subprocess
910
1011from gitfx import parse_funcs
1112from gitfx import lang_version
1213
1314
1415ROOT_DIR = os .getenv ('GITHUB_WORKSPACE' , os .getcwd ())
16+ WRITE_MODE = os .getenv ('GITFX_WRITE_MODE' , 'overwrite' )
1517
1618SUPPORTED_LANGS = ['ruby' ,
1719 'python' ,
@@ -87,16 +89,19 @@ def run_fun(func_path, func):
8789 # decide language version
8890 version = lang_version .get_version (func_path , func_lang ) or 'latest'
8991
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 )
100105
101106 output = subprocess .Popen (cmd , stdout = subprocess .PIPE ).communicate ()[0 ]
102107 return output .decode ("utf8" )
@@ -111,7 +116,10 @@ def write_to_route(result, func_route):
111116 os .makedirs (dst_dir )
112117
113118 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' )
115123 f .write (result )
116124 f .close ()
117125
0 commit comments