2020-06-29 22:29:30 -06:00
|
|
|
#!/usr/bin/env python3
|
2015-11-04 06:23:45 -07:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2015-03-15 21:29:08 -06:00
|
|
|
|
2020-06-29 22:24:03 -06:00
|
|
|
|
|
|
|
def print_stderr(stderr, args):
|
|
|
|
if not args.github_actions:
|
|
|
|
sys.stderr.write(stderr + '\n')
|
|
|
|
return
|
|
|
|
|
|
|
|
for line in stderr.split('\n'):
|
|
|
|
parts = list(map(str.strip, line.split(':')))
|
|
|
|
# e.g. luac prints "luac:" in front of messages, so find the first part
|
|
|
|
# containing the actual filename
|
|
|
|
for i in range(len(parts) - 1):
|
|
|
|
if parts[i].endswith('.' + args.ext) and parts[i + 1].isdigit():
|
|
|
|
print('::error file=%s,line=%s::%s' % (parts[i], parts[i + 1], ':'.join(parts[i + 2:])))
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
print(line)
|
|
|
|
|
|
|
|
|
2015-11-07 13:50:11 -07:00
|
|
|
def main(args):
|
2015-03-15 21:29:08 -06:00
|
|
|
root_path = os.path.abspath(args.path)
|
|
|
|
cmd = args.cmd.split(' ')
|
|
|
|
if not os.path.exists(root_path):
|
|
|
|
print('Nonexistent path: %s' % root_path)
|
|
|
|
sys.exit(2)
|
|
|
|
err = False
|
|
|
|
for cur, dirnames, filenames in os.walk(root_path):
|
|
|
|
parts = cur.replace('\\', '/').split('/')
|
|
|
|
if '.git' in parts or 'depends' in parts:
|
|
|
|
continue
|
|
|
|
for filename in filenames:
|
2015-11-07 13:50:11 -07:00
|
|
|
if not filename.endswith('.' + args.ext):
|
2015-03-15 21:29:08 -06:00
|
|
|
continue
|
|
|
|
full_path = os.path.join(cur, filename)
|
|
|
|
try:
|
2020-06-29 22:24:03 -06:00
|
|
|
p = subprocess.Popen(cmd + [full_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
_, stderr = p.communicate()
|
|
|
|
stderr = stderr.decode('utf-8', errors='ignore')
|
|
|
|
if stderr:
|
|
|
|
print_stderr(stderr, args)
|
|
|
|
if p.returncode != 0:
|
|
|
|
err = True
|
2015-03-15 21:29:08 -06:00
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
err = True
|
2015-11-04 06:23:45 -07:00
|
|
|
except IOError:
|
2015-11-05 22:58:58 -07:00
|
|
|
if not err:
|
|
|
|
print('Warning: cannot check %s script syntax' % args.ext)
|
|
|
|
err = True
|
2015-03-15 21:29:08 -06:00
|
|
|
sys.exit(int(err))
|
|
|
|
|
2015-11-04 06:23:45 -07:00
|
|
|
|
2015-03-15 21:29:08 -06:00
|
|
|
if __name__ == '__main__':
|
2015-11-04 06:23:45 -07:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--path', default='.', help='Root directory')
|
|
|
|
parser.add_argument('--ext', help='Script extension', required=True)
|
|
|
|
parser.add_argument('--cmd', help='Command', required=True)
|
2020-06-29 22:24:03 -06:00
|
|
|
parser.add_argument('--github-actions', action='store_true',
|
|
|
|
help='Enable GitHub Actions workflow command output')
|
2015-11-04 06:23:45 -07:00
|
|
|
args = parser.parse_args()
|
2015-11-07 13:50:11 -07:00
|
|
|
main(args)
|