Skip to content

Commit

Permalink
Modify TEMPLATE repo to support multi-root GCC builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
electronjoe authored and Scott Harrison Moeller committed Mar 11, 2021
1 parent 91e0aae commit 5f65807
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 36 deletions.
10 changes: 7 additions & 3 deletions .github/problem-matcher.json
Original file line number Diff line number Diff line change
@@ -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
}
]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
71 changes: 44 additions & 27 deletions __tests__/problemMatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]");
});
});
});
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down

0 comments on commit 5f65807

Please sign in to comment.