diff --git a/src/main/java/com/github/imas/rdflint/LintProblemFormatter.java b/src/main/java/com/github/imas/rdflint/LintProblemFormatter.java index 42612f9..5cd8818 100644 --- a/src/main/java/com/github/imas/rdflint/LintProblemFormatter.java +++ b/src/main/java/com/github/imas/rdflint/LintProblemFormatter.java @@ -1,5 +1,6 @@ package com.github.imas.rdflint; +import com.github.imas.rdflint.LintProblem.ErrorLevel; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.OutputStream; import java.io.PrintWriter; @@ -78,6 +79,42 @@ public static void out(OutputStream out, LintProblemSet problems) { pw.flush(); } + /** + * dump formatted problems. + */ + @SuppressFBWarnings(value = "DM_DEFAULT_ENCODING") + public static void annotationGitHubAction(OutputStream out, LintProblemSet problems) { + PrintWriter pw = new PrintWriter(out); + problems.getProblemSet().forEach((f, l) -> { + l.forEach(m -> { + Object[] args = LintProblemFormatter.buildArguments(m); + String msg = LintProblemFormatter.dumpMessage(m.getKey(), null, args); + long lineNoBegin = 1; + long lineNoEnd = 1; + if (m.getLocation() != null && m.getLocation().getBeginLine() >= 0) { + lineNoBegin = m.getLocation().getBeginLine(); + if (m.getLocation().getEndLine() >= 0) { + lineNoEnd = m.getLocation().getEndLine(); + } else { + lineNoEnd = lineNoBegin; + } + } + pw.println(String.format( + "::%s file=%s,line=%d,endLine=%d,title=%s#L%d::%s", + m.getLevel() == ErrorLevel.INFO ? "warning" : "error", + f, + lineNoBegin, + lineNoEnd, + f, + lineNoBegin, + msg + )); + }); + pw.println(); + }); + pw.flush(); + } + /** * dump yaml-formatted problems. */ diff --git a/src/main/java/com/github/imas/rdflint/RdfLint.java b/src/main/java/com/github/imas/rdflint/RdfLint.java index fa214b7..f6e886e 100644 --- a/src/main/java/com/github/imas/rdflint/RdfLint.java +++ b/src/main/java/com/github/imas/rdflint/RdfLint.java @@ -109,6 +109,9 @@ public static void main(String[] args) throws ParseException, IOException { if (problems.hasProblem()) { Path problemsPath = Paths.get(params.getOutputDir() + "/rdflint-problems.yml"); LintProblemFormatter.out(System.out, problems); + if ("true".equals(System.getenv("GITHUB_ACTIONS"))) { + LintProblemFormatter.annotationGitHubAction(System.out, problems); + } LintProblemFormatter.yaml(Files.newOutputStream(problemsPath), problems); final String minErrorLevel = cmd.getOptionValue("minErrorLevel", "WARN"); final LintProblem.ErrorLevel errorLevel = LintProblem.ErrorLevel.valueOf(minErrorLevel);