From 42dba1991e8f1ebc6fe54b73c6253c4b513502c4 Mon Sep 17 00:00:00 2001 From: Kian Cross Date: Tue, 20 Jul 2021 12:02:12 +0100 Subject: [PATCH] Add problem matcher for Checkstyle This commit adds a problem matcher for Checkstyle to allow automatic GitHub annotations. When run through Gradle, an example line is: ``` [ant:checkstyle] [ERROR] /root/Bound.java:7:2: 'import' has incorrect indentation level 1, expected level should be 0. [Indentation] ``` Alternatively, when run standalone, an example output is: ``` [WARN] /root/test.java:2:1: The name of the outer type and the file do not match. [OuterTypeFilename] ``` The regular expression matches both cases. In the latter example, `WARN`, rather than `WARNING` is output. This is resolved by using a default severity of `warning`, which will be overridden in the case that the severity is `ERROR`. --- .github/checkstyle.json | 19 +++++++++++++++++++ src/setup-java.ts | 1 + 2 files changed, 20 insertions(+) create mode 100644 .github/checkstyle.json diff --git a/.github/checkstyle.json b/.github/checkstyle.json new file mode 100644 index 00000000..c98bac93 --- /dev/null +++ b/.github/checkstyle.json @@ -0,0 +1,19 @@ +{ + "problemMatcher": [ + { + "owner": "checkstyle", + "severity": "warning", + "pattern": [ + { + "regexp": "^.*\\[(ERROR|WARN)\\]\\s+(.*):(\\d+):(\\d+):\\s+(.*)\\s+\\[(.*)\\]$", + "severity": 1, + "file": 2, + "line": 3, + "column": 4, + "message": 5, + "code": 6 + } + ] + } + ] +} diff --git a/src/setup-java.ts b/src/setup-java.ts index 92a86197..3d1791d8 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -38,6 +38,7 @@ async function run() { const matchersPath = path.join(__dirname, '..', '..', '.github'); core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); + core.info(`##[add-matcher]${path.join(matchersPath, 'checkstyle.json')}`); await auth.configureAuthentication(); } catch (error) {