From 2622aa9f7c8dff7384ce64e5f373fa74787f2184 Mon Sep 17 00:00:00 2001 From: 0x5c Date: Mon, 2 May 2022 00:58:34 -0400 Subject: [PATCH] common/travis/xlint.sh: print Github annotations Turns xlint, version lint, and commit lint messages into warning or error annotaions. All are printed with special highlighting in the action log and summary. Xlint and version lint annotations are shown inline in the changes tab and commit view. Annotations without line number are shown at line 1. --- common/scripts/lint-commits | 10 +++++----- common/scripts/lint2annotations.awk | 12 ++++++++++++ common/travis/xlint.sh | 5 +++-- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 common/scripts/lint2annotations.awk diff --git a/common/scripts/lint-commits b/common/scripts/lint-commits index 01c4eda17007..7207ed81d5aa 100755 --- a/common/scripts/lint-commits +++ b/common/scripts/lint-commits @@ -35,18 +35,18 @@ do /^$/ && !msg { msg = 1; next } !msg { next } # 3: long-line-is-banned-except-footnote-like-this-for-url - (NF > 2) && (length > 80) { print C ": long line: " $0; exit 1 } + (NF > 2) && (length > 80) { print "::error title=Commit Lint::" C ": long line: " $0; exit 1 } !subject { - if (length > 50) { print C ": subject is a bit long" } - if (!($0 ~ ":" || $0 ~ "^Take over maintainership " || $0 ~ "^Orphan ")) { print C ": subject does not follow CONTRIBUTING.md guildelines"; exit 1 } + if (length > 50) { print "::warning title=Commit Lint::" C ": subject is a bit long" } + if (!($0 ~ ":" || $0 ~ "^Take over maintainership " || $0 ~ "^Orphan ")) { print "::error title=Commit Lint::" C ": subject does not follow CONTRIBUTING.md guildelines"; exit 1 } # Below check is too noisy? # if (!($0 ~ "^New package:" || $0 ~ ".*: update to")) { - # print C ": not new package/update/removal?" + # print "::warning title=Commit Lint::" C ": not new package/update/removal?" # } subject = 1; next } /^$/ { body = 1; next } - !body { print C ": second line must be blank"; exit 1 } + !body { print "::error title=Commit Lint::" C ": second line must be blank"; exit 1 } ' || status=1 done exit $status diff --git a/common/scripts/lint2annotations.awk b/common/scripts/lint2annotations.awk new file mode 100644 index 000000000000..d74bcc15f961 --- /dev/null +++ b/common/scripts/lint2annotations.awk @@ -0,0 +1,12 @@ +# Converts xlint/etc format lints into GH Actions annotations +# The original line is printed alongside the annotation command +{ + split($0, a, ": ") + split(a[1], b, ":") + msg = substr($0, index($0, ": ") + 2) + if (b[2]) { + line = ",line=" b[2] + } + print $0 + printf "::error title=Template Lint,file=%s%s::%s\n", b[1], line, msg +} diff --git a/common/travis/xlint.sh b/common/travis/xlint.sh index 6b3d9e91c90a..327417c1c327 100755 --- a/common/travis/xlint.sh +++ b/common/travis/xlint.sh @@ -11,7 +11,8 @@ common/scripts/lint-commits $base $tip || EXITCODE=$? for t in $(awk '{ print "srcpkgs/" $0 "/template" }' /tmp/templates); do /bin/echo -e "\x1b[32mLinting $t...\x1b[0m" - xlint "$t" || EXITCODE=$? - common/scripts/lint-version-change "$t" $base $tip || EXITCODE=$? + xlint "$t" > /tmp/xlint_out || EXITCODE=$? + common/scripts/lint-version-change "$t" $base $tip > /tmp/vlint_out || EXITCODE=$? + awk -f common/scripts/lint2annotations.awk /tmp/xlint_out /tmp/vlint_out done exit $EXITCODE