Skip to content

Commit 202a594

Browse files
Merge pull request actions#48 from actions/matcher
More focused problem matcher regex
2 parents 1c06f0e + 0dbc7e4 commit 202a594

File tree

4 files changed

+112
-5
lines changed

4 files changed

+112
-5
lines changed

__tests__/setup-go.test.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import * as main from '../src/main';
99
import * as im from '../src/installer';
1010

1111
let goJsonData = require('./data/golang-dl.json');
12+
let matchers = require('../matchers.json');
13+
let matcherPattern = matchers.problemMatcher[0].pattern[0];
14+
let matcherRegExp = new RegExp(matcherPattern.regexp);
1215

1316
describe('setup-go', () => {
1417
let inputs = {} as any;
@@ -322,6 +325,100 @@ describe('setup-go', () => {
322325
expect(added).toBeTruthy;
323326
});
324327

328+
interface Annotation {
329+
file: string;
330+
line: number;
331+
column: number;
332+
message: string;
333+
}
334+
335+
//
336+
// problem matcher regex pattern tests
337+
338+
function testMatch(line: string): Annotation {
339+
let annotation = <Annotation>{};
340+
341+
let match = matcherRegExp.exec(line);
342+
if (match) {
343+
annotation.line = parseInt(match[matcherPattern.line], 10);
344+
annotation.column = parseInt(match[matcherPattern.column], 10);
345+
annotation.file = match[matcherPattern.file].trim();
346+
annotation.message = match[matcherPattern.message].trim();
347+
}
348+
349+
return annotation;
350+
}
351+
352+
it('matches on relative unix path', async () => {
353+
let line = './main.go:13:2: undefined: fmt.Printl';
354+
let annotation = testMatch(line);
355+
expect(annotation).toBeDefined();
356+
expect(annotation.line).toBe(13);
357+
expect(annotation.column).toBe(2);
358+
expect(annotation.file).toBe('./main.go');
359+
expect(annotation.message).toBe('undefined: fmt.Printl');
360+
});
361+
362+
it('matches on unix path up the tree', async () => {
363+
let line = '../main.go:13:2: undefined: fmt.Printl';
364+
let annotation = testMatch(line);
365+
expect(annotation).toBeDefined();
366+
expect(annotation.line).toBe(13);
367+
expect(annotation.column).toBe(2);
368+
expect(annotation.file).toBe('../main.go');
369+
expect(annotation.message).toBe('undefined: fmt.Printl');
370+
});
371+
372+
it('matches on rooted unix path', async () => {
373+
let line = '/assert.go:4:1: missing return at end of function';
374+
let annotation = testMatch(line);
375+
expect(annotation).toBeDefined();
376+
expect(annotation.line).toBe(4);
377+
expect(annotation.column).toBe(1);
378+
expect(annotation.file).toBe('/assert.go');
379+
expect(annotation.message).toBe('missing return at end of function');
380+
});
381+
382+
it('matches on unix path with spaces', async () => {
383+
let line = ' ./assert.go:5:2: missing return at end of function ';
384+
let annotation = testMatch(line);
385+
expect(annotation).toBeDefined();
386+
expect(annotation.line).toBe(5);
387+
expect(annotation.column).toBe(2);
388+
expect(annotation.file).toBe('./assert.go');
389+
expect(annotation.message).toBe('missing return at end of function');
390+
});
391+
392+
it('matches on unix path with tabs', async () => {
393+
let line = '\t./assert.go:5:2: missing return at end of function ';
394+
let annotation = testMatch(line);
395+
expect(annotation).toBeDefined();
396+
expect(annotation.line).toBe(5);
397+
expect(annotation.column).toBe(2);
398+
expect(annotation.file).toBe('./assert.go');
399+
expect(annotation.message).toBe('missing return at end of function');
400+
});
401+
402+
it('matches on relative windows path', async () => {
403+
let line = '.\\main.go:13:2: undefined: fmt.Printl';
404+
let annotation = testMatch(line);
405+
expect(annotation).toBeDefined();
406+
expect(annotation.line).toBe(13);
407+
expect(annotation.column).toBe(2);
408+
expect(annotation.file).toBe('.\\main.go');
409+
expect(annotation.message).toBe('undefined: fmt.Printl');
410+
});
411+
412+
it('matches on windows path up the tree', async () => {
413+
let line = '..\\main.go:13:2: undefined: fmt.Printl';
414+
let annotation = testMatch(line);
415+
expect(annotation).toBeDefined();
416+
expect(annotation.line).toBe(13);
417+
expect(annotation.column).toBe(2);
418+
expect(annotation.file).toBe('..\\main.go');
419+
expect(annotation.message).toBe('undefined: fmt.Printl');
420+
});
421+
325422
// 1.13.1 => 1.13.1
326423
// 1.13 => 1.13.0
327424
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1

dist/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,10 @@ function run() {
13181318
// add problem matchers
13191319
const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json');
13201320
console.log(`##[add-matcher]${matchersPath}`);
1321+
// output the version actually being used
1322+
let goPath = yield io.which('go');
1323+
let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
1324+
console.log(goVersion);
13211325
}
13221326
catch (error) {
13231327
core.setFailed(error.message);

matchers.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"owner": "go",
55
"pattern": [
66
{
7-
"regexp": "^([^:]*: )?((.:)?[^:]*):(\\d+)(:(\\d+))?: (.*)$",
8-
"file": 2,
9-
"line": 4,
10-
"column": 6,
11-
"message": 7
7+
"regexp": "^\\s*(\\.{0,2}[\\/\\\\].+\\.go):(?:(\\d+):(\\d+):)? (.*)",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"message": 4
1212
}
1313
]
1414
}

src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export async function run() {
5050
// add problem matchers
5151
const matchersPath = path.join(__dirname, '..', 'matchers.json');
5252
console.log(`##[add-matcher]${matchersPath}`);
53+
54+
// output the version actually being used
55+
let goPath = await io.which('go');
56+
let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
57+
58+
console.log(goVersion);
5359
} catch (error) {
5460
core.setFailed(error.message);
5561
}

0 commit comments

Comments
 (0)