3
0
Fork 0
mirror of https://gitea.com/actions/setup-go.git synced 2024-11-25 19:19:33 +01:00

Merge pull request #48 from actions/matcher

More focused problem matcher regex
This commit is contained in:
Bryan MacFarlane 2020-04-03 11:51:07 -04:00 committed by GitHub
commit 202a594963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 112 additions and 5 deletions

View file

@ -9,6 +9,9 @@ import * as main from '../src/main';
import * as im from '../src/installer'; import * as im from '../src/installer';
let goJsonData = require('./data/golang-dl.json'); let goJsonData = require('./data/golang-dl.json');
let matchers = require('../matchers.json');
let matcherPattern = matchers.problemMatcher[0].pattern[0];
let matcherRegExp = new RegExp(matcherPattern.regexp);
describe('setup-go', () => { describe('setup-go', () => {
let inputs = {} as any; let inputs = {} as any;
@ -322,6 +325,100 @@ describe('setup-go', () => {
expect(added).toBeTruthy; expect(added).toBeTruthy;
}); });
interface Annotation {
file: string;
line: number;
column: number;
message: string;
}
//
// problem matcher regex pattern tests
function testMatch(line: string): Annotation {
let annotation = <Annotation>{};
let match = matcherRegExp.exec(line);
if (match) {
annotation.line = parseInt(match[matcherPattern.line], 10);
annotation.column = parseInt(match[matcherPattern.column], 10);
annotation.file = match[matcherPattern.file].trim();
annotation.message = match[matcherPattern.message].trim();
}
return annotation;
}
it('matches on relative unix path', async () => {
let line = './main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2);
expect(annotation.file).toBe('./main.go');
expect(annotation.message).toBe('undefined: fmt.Printl');
});
it('matches on unix path up the tree', async () => {
let line = '../main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2);
expect(annotation.file).toBe('../main.go');
expect(annotation.message).toBe('undefined: fmt.Printl');
});
it('matches on rooted unix path', async () => {
let line = '/assert.go:4:1: missing return at end of function';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(4);
expect(annotation.column).toBe(1);
expect(annotation.file).toBe('/assert.go');
expect(annotation.message).toBe('missing return at end of function');
});
it('matches on unix path with spaces', async () => {
let line = ' ./assert.go:5:2: missing return at end of function ';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(5);
expect(annotation.column).toBe(2);
expect(annotation.file).toBe('./assert.go');
expect(annotation.message).toBe('missing return at end of function');
});
it('matches on unix path with tabs', async () => {
let line = '\t./assert.go:5:2: missing return at end of function ';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(5);
expect(annotation.column).toBe(2);
expect(annotation.file).toBe('./assert.go');
expect(annotation.message).toBe('missing return at end of function');
});
it('matches on relative windows path', async () => {
let line = '.\\main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2);
expect(annotation.file).toBe('.\\main.go');
expect(annotation.message).toBe('undefined: fmt.Printl');
});
it('matches on windows path up the tree', async () => {
let line = '..\\main.go:13:2: undefined: fmt.Printl';
let annotation = testMatch(line);
expect(annotation).toBeDefined();
expect(annotation.line).toBe(13);
expect(annotation.column).toBe(2);
expect(annotation.file).toBe('..\\main.go');
expect(annotation.message).toBe('undefined: fmt.Printl');
});
// 1.13.1 => 1.13.1 // 1.13.1 => 1.13.1
// 1.13 => 1.13.0 // 1.13 => 1.13.0
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1 // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1

4
dist/index.js vendored
View file

@ -1318,6 +1318,10 @@ function run() {
// add problem matchers // add problem matchers
const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json'); const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json');
console.log(`##[add-matcher]${matchersPath}`); console.log(`##[add-matcher]${matchersPath}`);
// output the version actually being used
let goPath = yield io.which('go');
let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString();
console.log(goVersion);
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);

View file

@ -4,11 +4,11 @@
"owner": "go", "owner": "go",
"pattern": [ "pattern": [
{ {
"regexp": "^([^:]*: )?((.:)?[^:]*):(\\d+)(:(\\d+))?: (.*)$", "regexp": "^\\s*(\\.{0,2}[\\/\\\\].+\\.go):(?:(\\d+):(\\d+):)? (.*)",
"file": 2, "file": 1,
"line": 4, "line": 2,
"column": 6, "column": 3,
"message": 7 "message": 4
} }
] ]
} }

View file

@ -50,6 +50,12 @@ export async function run() {
// add problem matchers // add problem matchers
const matchersPath = path.join(__dirname, '..', 'matchers.json'); const matchersPath = path.join(__dirname, '..', 'matchers.json');
console.log(`##[add-matcher]${matchersPath}`); console.log(`##[add-matcher]${matchersPath}`);
// output the version actually being used
let goPath = await io.which('go');
let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
console.log(goVersion);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }