Skip to content

Commit 8258a25

Browse files
committed
Add pre_hook feature to run script
1 parent 8ef14b3 commit 8258a25

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

.github/workflows/test_run_funcs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
4040
ruby.json
4141
ruby_second.json
42+
43+
test_pre_hook
4244
)
4345
4446
status=0

run_funcs.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
'golang',
1616
'elixir',
1717
'haskell',
18-
'php']
18+
'php',
19+
]
1920

2021
RUN_CMDS = {
2122
'ruby': 'ruby',
@@ -25,8 +26,8 @@
2526
'golang': 'go run',
2627
'elixir': 'elixir',
2728
'haskell': 'runhaskell',
28-
'php': 'php'}
29-
29+
'php': 'php',
30+
}
3031

3132
def run_fun(path, func):
3233
func_lang = func['language']
@@ -36,16 +37,22 @@ def run_fun(path, func):
3637
if func_file_name.strip() == '':
3738
return ""
3839

40+
pre_hook_file = func_file_name + '.sh'
41+
run_pre_hook = '[ -f {0} ] && sh {0} >/dev/null 2>&1'.format(pre_hook_file)
42+
3943
deps_install = {
40-
'ruby': '[ -e Gemfile ] && bundle install >/dev/null 2>&1',
41-
'python': '[ -e requirements.txt ] && pip install -r requirements.txt >/dev/null 2>&1',
42-
'node': '[ -e package.json ] && npm install --only=prod >/dev/null 2>&1',
43-
'perl': '[ -e cpanfile ] && cpanm --installdeps . >/dev/null 2>&1'}
44+
'ruby': '[ -f Gemfile ] && bundle install >/dev/null 2>&1',
45+
'python': '[ -f requirements.txt ] && pip install -r requirements.txt >/dev/null 2>&1',
46+
'node': '[ -f package.json ] && npm install --only=prod >/dev/null 2>&1',
47+
'perl': '[ -f cpanfile ] && cpanm --installdeps . >/dev/null 2>&1'}
4448

4549
cmd = ['docker', 'run', '--rm', '--workdir', '/github/workspace',
4650
'-v', os.getenv('GITHUB_WORKSPACE') + ':/github/workspace',
4751
func_lang + ':latest', 'sh', '-c',
48-
"cd " + path + ";" + deps_install.get(func_lang, ':') + ";" + RUN_CMDS[func_lang] + " " + func_file_name]
52+
"cd " + path + ";" +
53+
run_pre_hook + ";" +
54+
deps_install.get(func_lang, ':') + ";" +
55+
RUN_CMDS[func_lang] + " " + func_file_name]
4956

5057
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
5158
return output.decode("utf8")

test/func_samples/test_pre_hook.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
with open('/tmp/test_pre_hook.txt', 'r') as fh:
3+
# GET /test/result/test_pre_hook
4+
print(fh.read().splitlines()[0])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "hello, prehook" > /tmp/test_pre_hook.txt

0 commit comments

Comments
 (0)