diff --git a/.github/matchers/phpunit.json b/.github/matchers/phpunit.json new file mode 100644 index 00000000..44b9db6b --- /dev/null +++ b/.github/matchers/phpunit.json @@ -0,0 +1,24 @@ +{ + "problemMatcher": [ + { + "owner": "phpunit", + "pattern": [ + { + "regexp": "^\\d+\\)\\s.*$" + }, + { + "regexp": "^(.*)$", + "message": 1 + }, + { + "regexp": "^\\s*$" + }, + { + "regexp": "^(.*):(\\d+)$", + "file": 1, + "line": 2 + } + ] + } + ] +} diff --git a/__tests__/install.test.ts b/__tests__/install.test.ts index 9842a38e..5dd5dcab 100644 --- a/__tests__/install.test.ts +++ b/__tests__/install.test.ts @@ -1,4 +1,6 @@ import * as install from '../src/install'; +import * as matchers from '../src/matchers'; +import * as path from 'path'; /** * Mock install.ts @@ -150,4 +152,34 @@ describe('Install', () => { expect(script).toContain('set coverage driver'); expect(script).toContain('sh script.sh 7.3 ' + __dirname); }); + + describe('Matchers', () => { + let originalLogMethod: any; + let outputData: any[] = []; + + beforeAll(() => { + originalLogMethod = console.log; + console['log'] = jest.fn(inputs => outputData.push(inputs)); + }); + + beforeEach(() => { + outputData = []; + }); + + afterAll(() => { + console['log'] = originalLogMethod; + }); + + it('Add matchers', async () => { + matchers.addMatchers(); + + expect(outputData).toEqual([ + `##[add-matcher]${path.join( + __dirname, + '..', + '.github/matchers/phpunit.json' + )}` + ]); + }); + }); }); diff --git a/src/install.ts b/src/install.ts index e3d93327..6b88d3d7 100644 --- a/src/install.ts +++ b/src/install.ts @@ -4,6 +4,7 @@ import * as config from './config'; import * as coverage from './coverage'; import * as extensions from './extensions'; import * as utils from './utils'; +import {addMatchers} from './matchers'; /** * Build the script @@ -68,6 +69,8 @@ export async function run(): Promise { ); break; } + + addMatchers(); } catch (error) { core.setFailed(error.message); } diff --git a/src/matchers.ts b/src/matchers.ts new file mode 100644 index 00000000..18116ccb --- /dev/null +++ b/src/matchers.ts @@ -0,0 +1,10 @@ +import * as path from 'path'; + +/** + * Add matches using the Actions Toolkit problem matchers syntax + * https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md + */ +export function addMatchers(): void { + const matchersPath = path.join(__dirname, '..', '.github/matchers'); + console.log(`##[add-matcher]${path.join(matchersPath, 'phpunit.json')}`); +}