Skip to content

Commit fd580bd

Browse files
committed
Initial commit
0 parents  commit fd580bd

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# GCC problem matcher
2+
3+
Creates annotations for warnings and errors in gcc builds.
4+
5+
6+
## Usage
7+
8+
Just add a single line before running the build step.
9+
10+
```yaml
11+
- uses: olemorud/gcc-problem-matcher@master
12+
```

action.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: GCC Problem Matcher
2+
3+
description: Get annotations for warnings and errors on builds using gcc
4+
5+
author: Ole Morud
6+
7+
branding:
8+
icon: search
9+
color: yellow
10+
11+
inputs:
12+
root:
13+
description: 'base directory for build, e.g. /workdir/build'
14+
required: false
15+
default: ''
16+
17+
runs:
18+
using: 'node16'
19+
main: 'src/index.js'

src/gcc_matcher.jsontemplate

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "gcc-problem-matcher",
5+
"pattern": [
6+
{
7+
"regexp": "^${{ BASE }}\/?(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"message": 5
13+
}
14+
]
15+
}
16+
]
17+
}

src/index.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require('path');
2+
const fs = require('node:fs');
3+
//const core = require('@actions/core');
4+
5+
// C:\Users\ => C\:\\Users\\
6+
const escapeRegExp = (s) =>
7+
s.replace(/[:.*+?^${}()|\/[\]\\]/g, "\\$&");
8+
9+
10+
// ${{ key }}, ${{var}}, ${{ aggqq43g3qg4 }}
11+
const variable = (key) =>
12+
new RegExp("\\${{\\s*?" + key + "\\s*?}}", "g");
13+
14+
15+
// default value set in /action.yml
16+
// const root = core.getInput('root', { required: false });
17+
root = '/tmp/workspace';
18+
19+
const templatePath = path.join(__dirname, "gcc_matcher.jsontemplate");
20+
21+
const parsed =
22+
fs.readFileSync(templatePath, "ascii")
23+
.replace(variable("BASE"), escapeRegExp(root));
24+
25+
const matcherPath = path.join(__dirname, "gcc_matcher.json");
26+
27+
fs.writeFileSync(matcherPath, parsed);
28+
29+
console.log('::add-matcher::' + matcherPath);
30+
31+
/* for testing */
32+
exports.escapeRegExp = escapeRegExp
33+
exports.variable = variable;

test/unittest.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const assert = require('node:assert');
2+
const test = require('node:test');
3+
const _testing = require('../src/index');
4+
5+
test('regex escaping test', () => {
6+
const escapeRegExp = _testing.escapeRegExp;
7+
8+
const st = [
9+
{str: "C:\\Users\\", ok: "C\\:\\\\Users\\\\"},
10+
{str: "/usr/bin/", ok: "\\/usr\\/bin\\/"},
11+
{str: "(\\\\d+):", ok: "\\(\\\\\\\\d\\+\\)\\:"}
12+
];
13+
14+
st.forEach( (x) => {
15+
const result = escapeRegExp(x.str);
16+
console.log(result, x.ok);
17+
assert.strictEqual(result, x.ok);
18+
});
19+
});
20+
21+
test('variable regex matching test', () => {
22+
const variable = _testing.variable;
23+
24+
const expected = [
25+
{needle: "foo", haystack: "this sentence contains variable ${{foo}}", ok: true},
26+
{needle: "bar", haystack: "finds \n ${{bar}} \n in multilines", ok: true},
27+
{needle: "baz", haystack: "${{ baz }}", ok: true},
28+
{needle: "", haystack: "${{aaa}}", ok: false},
29+
{needle: "bad", haystack: "{{bad}}", ok: false},
30+
{needle: "", haystack: "${{}}", ok: true},
31+
];
32+
33+
expected.forEach( (x) => {
34+
console.log(x);
35+
const match = x.haystack.match(variable(x.needle));
36+
assert.strictEqual( match !== null, x.ok );
37+
});
38+
});

0 commit comments

Comments
 (0)