From 7b10e32320d00208c744586d8e2819ccd4152ff3 Mon Sep 17 00:00:00 2001 From: Mark Suckerberg Date: Thu, 14 Sep 2023 11:26:01 -0500 Subject: [PATCH] Hopefully adds proper annotations to the regex linter (#2352) ## About The Pull Request See title ## Why It's Good For The Game More clear what's going wrong when linters fails ## Changelog :cl: /:cl: --- .github/workflows/ci_suite.yml | 2 +- tools/ci/check_regex.py | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_suite.yml b/.github/workflows/ci_suite.yml index 20378d43932b..f844f8da5747 100644 --- a/.github/workflows/ci_suite.yml +++ b/.github/workflows/ci_suite.yml @@ -59,7 +59,7 @@ jobs: python-version: "3.9" - name: Run Check Regex run: | - tools/bootstrap/python -m ci.check_regex --log-changes-only + tools/bootstrap/python -m ci.check_regex --log-changes-only --github-actions - name: Annotate Regex Matches if: always() run: | diff --git a/tools/ci/check_regex.py b/tools/ci/check_regex.py index 279d8236cbd6..f104139b7e18 100644 --- a/tools/ci/check_regex.py +++ b/tools/ci/check_regex.py @@ -31,6 +31,10 @@ modification, or removal. Good if you want to track down errors caused by commit or PR changes. + --github-actions + An output option to format the output in a way that Github Actions + can parse and show as annotations in the PR. + Copyright 2021 Martin Lyrå Permission is hereby granted, free of charge, to any person obtaining a copy @@ -99,6 +103,12 @@ dest="log_changes_only", default=False, action="store_true") +options.add_argument( + "--github-actions", + dest="github_actions", + default=False, + action="store_true" +) args = options.parse_args() @@ -790,9 +800,25 @@ def git_get_detached_head_ref(head: Head, ref_info: str) -> str: show_items.append("Current (%4i): %s" % (len(matches), matches)) if len(adds): show_items.append("+++++++ (%4i): %s" % (len(adds), adds)) + #Github actions annotations + if args.github_actions and matching != RESULT_OK: + for line_no in adds: + output_write("::error file=%s,line=%i,title=Check Regex::%s added to here, remove or update check_regex.yml" % ( + f, + line_no, + standard.message + ), to_stdout=True, to_file=False) inner_prefix = prefix if len(removes): show_items.append("------- (%4i): %s" % (len(removes), removes)) + #Github actions annotations + if args.github_actions and matching != RESULT_OK: + for line_no in removes: + output_write("::error file=%s,line=%i,title=Check Regex::%s removed from here, update check_regex.yml" % ( + f, + line_no, + standard.message + ), to_stdout=True, to_file=False) inner_prefix = prefix lines.append("%2s %s" % ("\u2500\u252C", f)) @@ -898,4 +924,4 @@ def git_get_detached_head_ref(head: Head, ref_info: str) -> str: output_file.close() output_file = None - exit(failure > 0 or fail_files > 0) \ No newline at end of file + exit(failure > 0 or fail_files > 0)