diff --git a/packages/core/README.md b/packages/core/README.md index ac8ced92bb..6128b0c23b 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -263,6 +263,29 @@ var pid = core.getState("pidToKill"); process.kill(pid); ``` +#### Problem matchers + +You can use this library to register problem matchers for your action. +Problem matchers are used to scan the output of actions for a specified regex pattern and surface that information prominently in the UI. + +#### Register a problem matcher + +```js +const core = require('@actions/core'); + +// Add matcher file "my-matcher.json" +core.addMatcher('my-matcher.json'); +``` + +#### Remove a problem matcher + +```js +const core = require('@actions/core'); + +// Remove the problem matcher with the owner "my-matcher-owner" +core.removeMatcher('my-matcher-owner'); +``` + #### OIDC Token You can use these methods to interact with the GitHub OIDC provider and get a JWT ID token which would help to get access token from third party cloud providers. diff --git a/packages/core/__tests__/core.test.ts b/packages/core/__tests__/core.test.ts index 2928788d7f..3f45464f74 100644 --- a/packages/core/__tests__/core.test.ts +++ b/packages/core/__tests__/core.test.ts @@ -634,6 +634,16 @@ describe('@actions/core', () => { core.setCommandEcho(false) assertWriteCalls([`::echo::off${os.EOL}`]) }) + + it('addMatcher adds a problem matcher', () => { + core.addMatcher('my-matcher.json') + assertWriteCalls([`::add-matcher::my-matcher.json${os.EOL}`]) + }) + + it('removeMatcher removes a problem matcher', () => { + core.removeMatcher('my-matcher-owner') + assertWriteCalls([`::remove-matcher owner=my-matcher-owner::${os.EOL}`]) + }) }) // Assert that process.stdout.write calls called only with the given arguments. diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index e9091ba206..84149ea215 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -364,9 +364,27 @@ export async function group(name: string, fn: () => Promise): Promise { } //----------------------------------------------------------------------- -// Wrapper action state +// Problem Matchers Commands //----------------------------------------------------------------------- +/** + * Adds a matcher to the process + * + * @param path path to the matcher json file + */ +export function addMatcher(path: string): void { + issueCommand('add-matcher', {}, path) +} + +/** + * Removes a matcher from the process + * + * @param owner owner of the matcher + */ +export function removeMatcher(owner: string): void { + issueCommand('remove-matcher', {owner}, null) +} + /** * Saves state for current action, the state can only be retrieved by this action's post job execution. * @@ -393,6 +411,10 @@ export function getState(name: string): string { return process.env[`STATE_${name}`] || '' } +//----------------------------------------------------------------------- +// Wrapper action state +//----------------------------------------------------------------------- + export async function getIDToken(aud?: string): Promise { return await OidcClient.getIDToken(aud) }