Skip to content

feat(core): add wrappers functions to manage problem matchers #2001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions packages/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 23 additions & 1 deletion packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,27 @@ export async function group<T>(name: string, fn: () => Promise<T>): Promise<T> {
}

//-----------------------------------------------------------------------
// 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.
*
Expand All @@ -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<string> {
return await OidcClient.getIDToken(aud)
}
Expand Down