From 5f658072a779a1300c99ef0f0d88ce70c8fce731 Mon Sep 17 00:00:00 2001 From: Scott Moeller Date: Thu, 11 Mar 2021 10:01:48 -0500 Subject: [PATCH] Modify TEMPLATE repo to support multi-root GCC builds Big thank-you to [xt0rted](https://github.com/xt0rted/problem-matcher) for the superb template for GH Action based Problem Matchers - really well done. This is a GCC finding problem matcher, with one additional twist: support for GH Action based annotations of fromPath to support builds of sub-components in arbitrary non-root locations. --- .github/problem-matcher.json | 10 +++-- README.md | 4 ++ __tests__/problemMatcher.test.ts | 71 ++++++++++++++++++++------------ action.yml | 4 +- package.json | 10 +++-- 5 files changed, 63 insertions(+), 36 deletions(-) diff --git a/.github/problem-matcher.json b/.github/problem-matcher.json index a50c659..194c8a8 100644 --- a/.github/problem-matcher.json +++ b/.github/problem-matcher.json @@ -1,14 +1,18 @@ { "problemMatcher": [ { - "owner": "somelinter", + "owner": "gcc-problem-matcher", "pattern": [ { - "regexp": "^([^:]*):(\\d+):?(\\d+)?\\s+([\\w-\\/]*)\\s+(.*)$", + "regexp": "^problem-match-root:(.*)$", + "fromPath": 1 + }, + { + "regexp": "^(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, - "code": 4, + "severity": 4, "message": 5 } ] diff --git a/README.md b/README.md index cd7cfee..58d1ccb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # GitHub Actions Problem Matcher +Big thank-you to [xt0rted](https://github.com/xt0rted) for the TEMPLATE. + +The pattern match regex [comes from vs-code](https://github.com/microsoft/vscode-cpptools/blob/a8285cbc0efb5b09c2d2229b0e0772dcb3b602df/Extension/package.json#L76-L94). + [![CI Workflow Status](https://github.com/xt0rted/problem-matcher/workflows/CI/badge.svg)](https://github.com/xt0rted/problem-matcher/actions?query=workflow%3ACI) A GitHub Actions template to easily add or remove a problem matcher to workflows. diff --git a/__tests__/problemMatcher.test.ts b/__tests__/problemMatcher.test.ts index 569d639..4c01e31 100644 --- a/__tests__/problemMatcher.test.ts +++ b/__tests__/problemMatcher.test.ts @@ -6,18 +6,16 @@ const problemMatcher: ProblemMatcher = problemMatcherJson[0]; describe("problemMatcher", () => { it("has the correct owner", () => { - expect(problemMatcher.owner).toEqual("somelinter"); + expect(problemMatcher.owner).toEqual("gcc-problem-matcher"); }); - it("has one pattern", () => { - expect(problemMatcher.pattern.length).toEqual(1); + it("has two patterns", () => { + expect(problemMatcher.pattern.length).toEqual(2); }); - describe("pattern", () => { + describe("root prefix pattern", () => { const reportOutput = [ - "README.md:12:81 MD013/line-length Line length [Expected: 80; Actual: 149]", - "docs/README.md:21:81 MD013/line-length Line length [Expected: 80; Actual: 119]", - "docs/README.md:14 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]", + "problem-match-root:src/-", ]; let pattern: ProblemPattern; @@ -31,32 +29,51 @@ describe("problemMatcher", () => { results = matchResults(reportOutput, regexp); }); - it("matches violations", () => { - expect(results.length).toEqual(3); + it("matches count of problem-match-root hints", () => { + expect(results.length).toEqual(1); + }); + + it("matches problem-match-root annotations", () => { + expect(results[0][pattern.fromPath]).toEqual("src/-"); }); - it("matches violation details", () => { - expect(results[0][pattern.file]).toEqual("README.md"); - expect(results[0][pattern.line]).toEqual("12"); - expect(results[0][pattern.column]).toEqual("81"); - expect(results[0][pattern.code]).toEqual("MD013/line-length"); - expect(results[0][pattern.message]).toEqual("Line length [Expected: 80; Actual: 149]"); + }); + + describe("finding pattern", () => { + const reportOutput = [ + "/magma/lte/gateway/c/oai/common/log.h:364:1: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]", + "/magma/lte/gateway/c/oai/lib/3gpp/3gpp_24.008_common_ies.c:1031:61: warning: unused parameter 'len' [-Wunused-parameter]", + ]; + + let pattern: ProblemPattern; + let results: RegExpExecArray[]; + + beforeEach(() => { + pattern = problemMatcher.pattern[1]; + + const regexp = new RegExp(pattern.regexp); + + results = matchResults(reportOutput, regexp); + }); + + it("matches violations", () => { + expect(results.length).toEqual(2); }); - it("matches violation details in sub folder", () => { - expect(results[1][pattern.file]).toEqual("docs/README.md"); - expect(results[1][pattern.line]).toEqual("21"); - expect(results[1][pattern.column]).toEqual("81"); - expect(results[1][pattern.code]).toEqual("MD013/line-length"); - expect(results[1][pattern.message]).toEqual("Line length [Expected: 80; Actual: 119]"); + it("matches gcc warnings without parameter note", () => { + expect(results[0][pattern.file]).toEqual("/magma/lte/gateway/c/oai/common/log.h"); + expect(results[0][pattern.line]).toEqual("364"); + expect(results[0][pattern.column]).toEqual("1"); + expect(results[0][pattern.severity]).toEqual("warning"); + expect(results[0][pattern.message]).toEqual("type qualifiers ignored on function return type [-Wignored-qualifiers]"); }); - it("matches violation details without column", () => { - expect(results[2][pattern.file]).toEqual("docs/README.md"); - expect(results[2][pattern.line]).toEqual("14"); - expect(results[2][pattern.column]).toBeUndefined(); - expect(results[2][pattern.code]).toEqual("MD012/no-multiple-blanks"); - expect(results[2][pattern.message]).toEqual("Multiple consecutive blank lines [Expected: 1; Actual: 2]"); + it("matches gcc warnings with parameter note", () => { + expect(results[1][pattern.file]).toEqual("/magma/lte/gateway/c/oai/lib/3gpp/3gpp_24.008_common_ies.c"); + expect(results[1][pattern.line]).toEqual("1031"); + expect(results[1][pattern.column]).toEqual("61"); + expect(results[1][pattern.severity]).toEqual("warning"); + expect(results[1][pattern.message]).toEqual("unused parameter 'len' [-Wunused-parameter]"); }); }); }); diff --git a/action.yml b/action.yml index 9d6bf93..8a17178 100644 --- a/action.yml +++ b/action.yml @@ -1,8 +1,8 @@ name: "Problem Matcher" -description: "Sets up a problem matcher that's used to create annotations for violations" +description: "Sets up a problem matcher that's used to create annotations for GCC Warnings and Errors" -author: "xt0rted" +author: "electronjoe thanks to xt0rted TEMPLATE" branding: icon: "command" diff --git a/package.json b/package.json index 1994667..0788d1b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "problem-matcher", + "name": "gcc-problem-matcher-ts", "version": "1.0.0", "private": true, - "description": "Sets up a problem matcher to create annotations for violations", + "description": "Sets up a problem matcher to create annotations for gcc warnings and errors", "main": "dist/index.js", "scripts": { "build": "tsc", @@ -13,15 +13,17 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/xt0rted/problem-matcher.git" + "url": "git+https://github.com/electronjoe/gcc-problem-matcher-ts.git" }, "keywords": [ "actions", "github", "problem-matcher", + "gcc", + "warnings", "annotations" ], - "author": "xt0rted", + "author": "electronjoe courtesy TEMPLATE by xt0rted", "license": "MIT", "dependencies": { "@actions/core": "^1.2.6"