Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Add notice annotation and support more annotation fields#855
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
fe09733b3d7aa34b50f8ca5df6ef397ffadf1d9385791168931010087235d70File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -92,6 +92,8 @@ try { | ||
| // Do stuff | ||
| core.info('Output to the actions build log') | ||
| core.notice('This is a message that will also emit an annotation') | ||
| } | ||
| catch (err) { | ||
| core.error(`Error ${err}, action may still succeed though`); | ||
| @@ -115,6 +117,54 @@ const result = await core.group('Do something async', async () => { | ||
| }) | ||
| ``` | ||
| #### Annotations | ||
| This library has 3 methods that will produce [annotations](https://docs.github.com/en/rest/reference/checks#create-a-check-run). | ||
| ```js | ||
| core.error('This is a bad error. This will also fail the build.') | ||
| core.warning('Something went wrong, but it\'s not bad enough to fail the build.') | ||
| core.notice('Something happened that you might want to know about.') | ||
| ``` | ||
| These will surface to the UI in the Actions page and on Pull Requests. They look something like this: | ||
|  | ||
| These annotations can also be attached to particular lines and columns of your source files to show exactly where a problem is occuring. | ||
| These options are: | ||
| ```typescript | ||
| export interface AnnotationProperties { | ||
| /** | ||
| * A title for the annotation. | ||
| */ | ||
| title?: string | ||
luketomlinson marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * The start line for the annotation. | ||
| */ | ||
| startLine?: number | ||
| /** | ||
| * The end line for the annotation. Defaults to `startLine` when `startLine` is provided. | ||
| */ | ||
| endLine?: number | ||
| /** | ||
| * The start column for the annotation. Cannot be sent when `startLine` and `endLine` are different values. | ||
| */ | ||
| startColumn?: number | ||
| /** | ||
| * The start column for the annotation. Cannot be sent when `startLine` and `endLine` are different values. | ||
| * Defaults to `startColumn` when `startColumn` is provided. | ||
| */ | ||
| endColumn?: number | ||
| } | ||
| ``` | ||
| #### Styling output | ||
| Colored output is supported in the Action logs via standard [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code). 3/4 bit, 8 bit and 24 bit colors are all supported. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -6,7 +6,7 @@ import {toCommandValue} from './utils' | ||
| // We use any as a valid input type | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| interface CommandProperties { | ||
| export interface CommandProperties { | ||
luketomlinson marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| [key: string]: any | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import {issue, issueCommand} from './command' | ||
| import {issueCommand as issueFileCommand} from './file-command' | ||
| import {toCommandValue} from './utils' | ||
| import {toCommandProperties, toCommandValue} from './utils' | ||
| import * as os from 'os' | ||
| import * as path from 'path' | ||
| @@ -31,6 +31,38 @@ export enum ExitCode { | ||
| Failure = 1 | ||
| } | ||
| /** | ||
| * Optional properties that can be sent with annotatation commands (notice, error, and warning) | ||
| * See: https://docs.github.com/en/rest/reference/checks#create-a-check-run for more information about annotations. | ||
| */ | ||
| export interface AnnotationProperties { | ||
| /** | ||
| * A title for the annotation. | ||
| */ | ||
| title?: string | ||
| /** | ||
| * The start line for the annotation. | ||
| */ | ||
| startLine?: number | ||
| /** | ||
| * The end line for the annotation. Defaults to `startLine` when `startLine` is provided. | ||
| */ | ||
| endLine?: number | ||
| /** | ||
| * The start column for the annotation. Cannot be sent when `startLine` and `endLine` are different values. | ||
| */ | ||
| startColumn?: number | ||
| /** | ||
| * The start column for the annotation. Cannot be sent when `startLine` and `endLine` are different values. | ||
| * Defaults to `startColumn` when `startColumn` is provided. | ||
| */ | ||
| endColumn?: number | ||
| } | ||
| //----------------------------------------------------------------------- | ||
| // Variables | ||
| //----------------------------------------------------------------------- | ||
| @@ -199,17 +231,49 @@ export function debug(message: string): void { | ||
| /** | ||
| * Adds an error issue | ||
| * @param message error issue message. Errors will be converted to string via toString() | ||
| * @param properties optional properties to add to the annotation. | ||
| */ | ||
| export function error(message: string | Error): void { | ||
| issue('error', message instanceof Error ? message.toString() : message) | ||
| export function error( | ||
| message: string | Error, | ||
| properties: AnnotationProperties = {} | ||
| ): void { | ||
| issueCommand( | ||
| 'error', | ||
| toCommandProperties(properties), | ||
| message instanceof Error ? message.toString() : message | ||
| ) | ||
| } | ||
| /** | ||
| * Adds an warning issue | ||
| * Adds a warning issue | ||
| * @param message warning issue message. Errors will be converted to string via toString() | ||
| * @param properties optional properties to add to the annotation. | ||
| */ | ||
| export function warning(message: string | Error): void { | ||
| issue('warning', message instanceof Error ? message.toString() : message) | ||
| export function warning( | ||
| message: string | Error, | ||
| properties: AnnotationProperties = {} | ||
| ): void { | ||
| issueCommand( | ||
| 'warning', | ||
| toCommandProperties(properties), | ||
| message instanceof Error ? message.toString() : message | ||
| ) | ||
| } | ||
| /** | ||
| * Adds a notice issue | ||
| * @param message notice issue message. Errors will be converted to string via toString() | ||
| * @param properties optional properties to add to the annotation. | ||
| */ | ||
| export function notice( | ||
thboop marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| message: string | Error, | ||
| properties: AnnotationProperties = {} | ||
| ): void { | ||
| issueCommand( | ||
thboop marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 'notice', | ||
| toCommandProperties(properties), | ||
| message instanceof Error ? message.toString() : message | ||
| ) | ||
| } | ||
| /** | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| // We use any as a valid input type | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import {AnnotationProperties} from './core' | ||
| import {CommandProperties} from './command' | ||
| /** | ||
| * Sanitizes an input into a string so it can be passed into issueCommand safely | ||
| * @param input input to sanitize into a string | ||
| @@ -13,3 +16,25 @@ export function toCommandValue(input: any): string { | ||
| } | ||
| return JSON.stringify(input) | ||
| } | ||
| /** | ||
| * | ||
| * @param annotationProperties | ||
| * @returns The command properties to send with the actual annotation command | ||
| * See IssueCommandProperties: https://github.com/actions/runner/blob/main/src/Runner.Worker/ActionCommandManager.cs#L646 | ||
| */ | ||
| export function toCommandProperties( | ||
| annotationProperties: AnnotationProperties | ||
| ): CommandProperties { | ||
| if (!Object.keys(annotationProperties).length) { | ||
| return {} | ||
| } | ||
| return { | ||
| title: annotationProperties.title, | ||
luketomlinson marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| line: annotationProperties.startLine, | ||
| endLine: annotationProperties.endLine, | ||
| col: annotationProperties.startColumn, | ||
| endColumn: annotationProperties.endColumn | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.