55from parse_funcs import parse
66
77
8- ROOT_DIR = os .getenv ('GITHUB_WORKSPACE' )
8+ ROOT_DIR = os .getenv ('GITHUB_WORKSPACE' , os . path . dirname ( os . path . abspath ( __file__ )) )
99
1010SUPPORTED_LANGS = [
1111 'ruby' ,
@@ -39,7 +39,7 @@ def docker_image(lang):
3939 otherwise the language name will be returned as the image name"""
4040 return DOCKER_IMAGES .get (lang , lang )
4141
42- def run_fun (path , func ):
42+ def run_fun (func_path , func ):
4343 func_lang = func ['language' ]
4444 if func_lang not in SUPPORTED_LANGS :
4545 return ""
@@ -60,11 +60,11 @@ def run_fun(path, func):
6060 'perl' : '[ -f cpanfile ] && cpanm --installdeps . >/dev/null 2>&1' }
6161
6262 cmd = ['docker' , 'run' , '--rm' , '--workdir' , '/github/workspace' ,
63- '-v' , os . getenv ( 'GITHUB_WORKSPACE' ) + ':/github/workspace' ,
63+ '-v' , ROOT_DIR + ':/github/workspace' ,
6464 docker_image (func_lang ) + ':latest' , 'sh' , '-c' ,
65- "cd " + path + ";" +
66- run_pre_hook + ";" +
65+ "cd " + os .path .relpath (func_path , ROOT_DIR ) + ";" +
6766 deps_install .get (func_lang , ':' ) + ";" +
67+ run_pre_hook + ";" +
6868 RUN_CMDS [func_lang ] + " " + func_file_name ]
6969
7070 output = subprocess .Popen (cmd , stdout = subprocess .PIPE ).communicate ()[0 ]
@@ -98,11 +98,13 @@ def print_github_raw_url(file_path):
9898
9999
100100if __name__ == "__main__" :
101- path = ROOT_DIR
101+ # func_path is a path where the functions locate
102+ func_path = ROOT_DIR
102103 if len (sys .argv ) > 1 :
103- path = sys .argv [1 ]
104+ func_path = sys .argv [1 ]
105+ func_path = os .path .abspath (func_path )
104106
105- funcs = parse (path )
107+ funcs = parse (func_path )
106108
107109 for func in funcs :
108110 routes = func ['routes' ]
@@ -111,13 +113,13 @@ def print_github_raw_url(file_path):
111113 if len (routes ) == 1 :
112114 if routes [0 ]['action' ] != 'GET' :
113115 continue
114- result = run_fun (path , func )
116+ result = run_fun (func_path , func )
115117 print (result )
116118 if result .strip () == '' :
117119 continue
118120 write_to_route (result , routes [0 ]['route' ])
119121 else :
120- results = run_fun (path , func )
122+ results = run_fun (func_path , func )
121123 if results .strip () == '' :
122124 continue
123125 print (results )
0 commit comments