diff --git a/travis/lint.py b/travis/lint.py index 51117201c..e1db140c2 100755 --- a/travis/lint.py +++ b/travis/lint.py @@ -105,7 +105,7 @@ class TabLinter(Linter): linters = [cls() for cls in Linter.__subclasses__() if not cls.ignore] def main(): - is_github_actions = os.environ.get('GITHUB_ACTIONS') + is_github_actions = bool(os.environ.get('GITHUB_ACTIONS')) root_path = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else '.') if not os.path.exists(root_path): print('Nonexistent path: %s' % root_path) diff --git a/travis/script-docs.py b/travis/script-docs.py index 04728e101..b2c8063bf 100755 --- a/travis/script-docs.py +++ b/travis/script-docs.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 -from __future__ import print_function -from io import open import os from os.path import basename, dirname, join, splitext import sys SCRIPT_PATH = sys.argv[1] if len(sys.argv) > 1 else 'scripts' +IS_GITHUB_ACTIONS = bool(os.environ.get('GITHUB_ACTIONS')) def expected_cmd(path): """Get the command from the name of a script.""" @@ -20,42 +19,61 @@ def check_ls(fname, line): line = line.strip() comment = '--' if fname.endswith('.lua') else '#' if '[====[' in line or not line.startswith(comment): - print('Error: no leading comment in ' + fname) + print_error('missing leading comment (requred for `ls`)', fname) return 1 return 0 +def print_error(message, filename, line=None): + if not isinstance(line, int): + line = 1 + print('Error: %s:%i: %s' % (filename, line, message)) + if IS_GITHUB_ACTIONS: + print('::error file=%s,line=%i::%s' % (filename, line, message)) + + def check_file(fname): errors, doclines = 0, [] tok1, tok2 = ('=begin', '=end') if fname.endswith('.rb') else \ ('[====[', ']====]') + doc_start_line = None with open(fname, errors='ignore') as f: lines = f.readlines() + if not lines: + print_error('empty file', fname) + return 1 errors += check_ls(fname, lines[0]) - for l in lines: + for i, l in enumerate(lines): if doclines or l.strip().endswith(tok1): + if not doclines: + doc_start_line = i + 1 doclines.append(l.rstrip()) if l.startswith(tok2): break else: if doclines: - print('Error: docs start but not end: ' + fname) + print_error('docs start but do not end', fname, doc_start_line) else: - print('Error: no documentation in: ' + fname) + print_error('no documentation found', fname) return 1 if not doclines: - print('Error: missing or malformed documentation in: ' + fname) + print_error('missing or malformed documentation', fname) return 1 title, underline = [d for d in doclines if d and '=begin' not in d and '[====[' not in d][:2] - if underline != '=' * len(title): - print('Error: title/underline mismatch:', fname, title, underline) + title_line = doc_start_line + doclines.index(title) + expected_underline = '=' * len(title) + if underline != expected_underline: + print_error('title/underline mismatch: expected {!r}, got {!r}'.format( + expected_underline, underline), + fname, title_line + 1) errors += 1 if title != expected_cmd(fname): - print('Warning: expected script title {}, got {}'.format( - expected_cmd(fname), title)) + print_error('expected script title {!r}, got {!r}'.format( + expected_cmd(fname), title), + fname, title_line) errors += 1 return errors