From 34223181a59a56c7bb7c395a3a60e16eaa6f2236 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Fri, 27 Mar 2020 19:56:10 -0400 Subject: [PATCH 01/11] starting --- __tests__/setup-go.test.ts | 69 ++++++++++++++++++++++++++++++++++++++ matchers.json | 10 +++--- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index d81a2aa..3734b3f 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -9,6 +9,9 @@ import * as main from '../src/main'; import * as im from '../src/installer'; 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', () => { let inputs = {} as any; @@ -322,6 +325,72 @@ describe('setup-go', () => { 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 = {}; + + 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 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 relative unix path', async () => { + let line = './a/path/assert.go:6:1: missing return at end of function'; + let annotation = testMatch(line); + expect(annotation).toBeDefined(); + expect(annotation.line).toBe(6); + expect(annotation.column).toBe(1); + expect(annotation.file).toBe('./a/path/assert.go'); + expect(annotation.message).toBe('missing return at end of function'); + }); + + 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 rooted unix path with whitespace', 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'); + }); + + + // 1.13.1 => 1.13.1 // 1.13 => 1.13.0 // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1 diff --git a/matchers.json b/matchers.json index f370917..69e8427 100644 --- a/matchers.json +++ b/matchers.json @@ -4,11 +4,11 @@ "owner": "go", "pattern": [ { - "regexp": "^([^:]*: )?((.:)?[^:]*):(\\d+)(:(\\d+))?: (.*)$", - "file": 2, - "line": 4, - "column": 6, - "message": 7 + "regexp": "((?:.{0,2}\\/|.{0,2}\\\\)(?:.+\\.go)):(?:(\\d+):(\\d+):)? (.*)", + "file": 1, + "line": 2, + "column": 3, + "message": 4 } ] } From 74c809594698e205b9f254c930617e50793e2cf5 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Fri, 27 Mar 2020 19:58:10 -0400 Subject: [PATCH 02/11] lint --- __tests__/setup-go.test.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 3734b3f..03e69dd 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -326,10 +326,10 @@ describe('setup-go', () => { }); interface Annotation { - file: string, - line: number, - column: number, - message: string + file: string; + line: number; + column: number; + message: string; } // @@ -347,7 +347,7 @@ describe('setup-go', () => { } return annotation; - } + } it('matches on rooted unix path', async () => { let line = '/assert.go:4:1: missing return at end of function'; @@ -367,7 +367,7 @@ describe('setup-go', () => { expect(annotation.column).toBe(1); expect(annotation.file).toBe('./a/path/assert.go'); expect(annotation.message).toBe('missing return at end of function'); - }); + }); it('matches on rooted unix path', async () => { let line = '/assert.go:4:1: missing return at end of function'; @@ -377,7 +377,7 @@ describe('setup-go', () => { expect(annotation.column).toBe(1); expect(annotation.file).toBe('/assert.go'); expect(annotation.message).toBe('missing return at end of function'); - }); + }); it('matches on rooted unix path with whitespace', async () => { let line = ' /assert.go:5:2: missing return at end of function '; @@ -387,9 +387,7 @@ describe('setup-go', () => { expect(annotation.column).toBe(2); expect(annotation.file).toBe('/assert.go'); expect(annotation.message).toBe('missing return at end of function'); - }); - - + }); // 1.13.1 => 1.13.1 // 1.13 => 1.13.0 From 7837b03976442632918287f7a497721158a0a23f Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Fri, 27 Mar 2020 20:14:29 -0400 Subject: [PATCH 03/11] more tests --- __tests__/setup-go.test.ts | 56 ++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 03e69dd..adb2c66 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -349,26 +349,26 @@ describe('setup-go', () => { return annotation; } - 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 relative unix path', async () => { - let line = './a/path/assert.go:6:1: missing return at end of function'; + let line = './main.go:13:2: undefined: fmt.Printl'; let annotation = testMatch(line); expect(annotation).toBeDefined(); - expect(annotation.line).toBe(6); - expect(annotation.column).toBe(1); - expect(annotation.file).toBe('./a/path/assert.go'); - expect(annotation.message).toBe('missing return at end of function'); + 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); @@ -379,16 +379,36 @@ describe('setup-go', () => { expect(annotation.message).toBe('missing return at end of function'); }); - it('matches on rooted unix path with whitespace', async () => { - let line = ' /assert.go:5:2: missing return at end of function '; + it('matches on unix path with whitespace', 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.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.13.0 // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1 From 5156bc5dd3c2247e81d9e1ec143374c2684672ae Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Fri, 27 Mar 2020 20:21:13 -0400 Subject: [PATCH 04/11] lint --- __tests__/setup-go.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index adb2c66..59ae40e 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -367,7 +367,7 @@ describe('setup-go', () => { 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'; @@ -407,7 +407,7 @@ describe('setup-go', () => { 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.13.0 From 0a62a734da04874c46fb9a6c8cef19e8cab3fd5d Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Mon, 30 Mar 2020 09:12:21 -0400 Subject: [PATCH 05/11] another test case --- __tests__/setup-go.test.ts | 10 ++++++++++ matchers.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 59ae40e..18e32e0 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -409,6 +409,16 @@ describe('setup-go', () => { expect(annotation.message).toBe('undefined: fmt.Printl'); }); + it('only matches leading dots on unix path', async () => { + let line = 'x./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'); + }); + // 1.13.1 => 1.13.1 // 1.13 => 1.13.0 // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1 diff --git a/matchers.json b/matchers.json index 69e8427..13cb6ac 100644 --- a/matchers.json +++ b/matchers.json @@ -4,7 +4,7 @@ "owner": "go", "pattern": [ { - "regexp": "((?:.{0,2}\\/|.{0,2}\\\\)(?:.+\\.go)):(?:(\\d+):(\\d+):)? (.*)", + "regexp": "((?:\\.{0,2}\\/|\\.{0,2}\\\\)(?:.+\\.go)):(?:(\\d+):(\\d+):)? (.*)", "file": 1, "line": 2, "column": 3, From 89c89c5036ba60baf8e7c851ab1001d56815f5d4 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Mon, 30 Mar 2020 10:39:29 -0400 Subject: [PATCH 06/11] cleaner regex --- matchers.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matchers.json b/matchers.json index 13cb6ac..3ba2244 100644 --- a/matchers.json +++ b/matchers.json @@ -4,7 +4,7 @@ "owner": "go", "pattern": [ { - "regexp": "((?:\\.{0,2}\\/|\\.{0,2}\\\\)(?:.+\\.go)):(?:(\\d+):(\\d+):)? (.*)", + "regexp": "(\\.{0,2}[\\/\\\\].+\\.go):(?:(\\d+):(\\d+):)? (.*)", "file": 1, "line": 2, "column": 3, From e36ce1d6cf1ad96ec3b4f675a6decf956df3dc72 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Mon, 30 Mar 2020 10:46:01 -0400 Subject: [PATCH 07/11] tabs or spaces --- __tests__/setup-go.test.ts | 22 +++++++++++----------- matchers.json | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/__tests__/setup-go.test.ts b/__tests__/setup-go.test.ts index 18e32e0..7efffbc 100644 --- a/__tests__/setup-go.test.ts +++ b/__tests__/setup-go.test.ts @@ -379,7 +379,7 @@ describe('setup-go', () => { expect(annotation.message).toBe('missing return at end of function'); }); - it('matches on unix path with whitespace', async () => { + 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(); @@ -389,6 +389,16 @@ describe('setup-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); @@ -409,16 +419,6 @@ describe('setup-go', () => { expect(annotation.message).toBe('undefined: fmt.Printl'); }); - it('only matches leading dots on unix path', async () => { - let line = 'x./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'); - }); - // 1.13.1 => 1.13.1 // 1.13 => 1.13.0 // 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1 diff --git a/matchers.json b/matchers.json index 3ba2244..675fdb7 100644 --- a/matchers.json +++ b/matchers.json @@ -4,7 +4,7 @@ "owner": "go", "pattern": [ { - "regexp": "(\\.{0,2}[\\/\\\\].+\\.go):(?:(\\d+):(\\d+):)? (.*)", + "regexp": "^\\s*(\\.{0,2}[\\/\\\\].+\\.go):(?:(\\d+):(\\d+):)? (.*)", "file": 1, "line": 2, "column": 3, From cec6ecefb4727867e1def09e5a02ae85c5133b60 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Tue, 31 Mar 2020 10:32:03 -0400 Subject: [PATCH 08/11] output version of go it resolved to --- dist/index.js | 4 ++++ src/main.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/dist/index.js b/dist/index.js index 7b347bd..8d1ce55 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1318,6 +1318,10 @@ function run() { // add problem matchers const matchersPath = path_1.default.join(__dirname, '..', 'matchers.json'); 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`); + console.log('Using go version '); } catch (error) { core.setFailed(error.message); diff --git a/src/main.ts b/src/main.ts index 9948f98..f90b834 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,6 +50,12 @@ export async function run() { // add problem matchers const matchersPath = path.join(__dirname, '..', 'matchers.json'); console.log(`##[add-matcher]${matchersPath}`); + + // output the version actually being used + let goPath = await io.which('go'); + let goVersion = cp.execSync(`${goPath} version`); + + console.log('Using go version '); } catch (error) { core.setFailed(error.message); } From f32657ccaf12f0efe91ec44e53f2fe829cdce87b Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Tue, 31 Mar 2020 10:37:33 -0400 Subject: [PATCH 09/11] output version of go it resolved to --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index f90b834..1e31578 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,7 +55,7 @@ export async function run() { let goPath = await io.which('go'); let goVersion = cp.execSync(`${goPath} version`); - console.log('Using go version '); + console.log(goVersion); } catch (error) { core.setFailed(error.message); } From 2091469f9f41b7aa3da89ed373d54201e9e4bf45 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Tue, 31 Mar 2020 10:38:13 -0400 Subject: [PATCH 10/11] lint --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 8d1ce55..3020b3e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1321,7 +1321,7 @@ function run() { // output the version actually being used let goPath = yield io.which('go'); let goVersion = child_process_1.default.execSync(`${goPath} version`); - console.log('Using go version '); + console.log(goVersion); } catch (error) { core.setFailed(error.message); From 0dbc7e4965a85bfa015c1287eefe5958cc2c4e67 Mon Sep 17 00:00:00 2001 From: Bryan MacFarlane Date: Tue, 31 Mar 2020 10:40:32 -0400 Subject: [PATCH 11/11] toString --- dist/index.js | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3020b3e..87a1a02 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1320,7 +1320,7 @@ function run() { 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`); + let goVersion = (child_process_1.default.execSync(`${goPath} version`) || '').toString(); console.log(goVersion); } catch (error) { diff --git a/src/main.ts b/src/main.ts index 1e31578..d693deb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,7 +53,7 @@ export async function run() { // output the version actually being used let goPath = await io.which('go'); - let goVersion = cp.execSync(`${goPath} version`); + let goVersion = (cp.execSync(`${goPath} version`) || '').toString(); console.log(goVersion); } catch (error) {