Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
luketomlinson committed Jul 2, 2021
1 parent b3d7aa3 commit 4b50f8c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
Binary file added docs/assets/annotations.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/problem-matchers.md
Expand Up @@ -6,7 +6,7 @@ Problem Matchers are a way to scan the output of actions for a specified regex p

Currently, GitHub Actions limit the annotation count in a workflow run.

- 10 warning annotations and 10 error annotations per step
- 10 warning annotations, 10 error annotations, and 10 notice annotations per step
- 50 annotations per job (sum of annotations from all the steps)
- 50 annotations per run (separate from the job annotations, these annotations aren’t created by users)

Expand Down
49 changes: 49 additions & 0 deletions packages/core/README.md
Expand Up @@ -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`);
Expand All @@ -115,6 +117,53 @@ 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:

![Annotations Image](../../docs/assets/annotations.png)

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

/**
* 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.
Expand Down
48 changes: 35 additions & 13 deletions packages/core/__tests__/core.test.ts
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import * as core from '../src/core'
import { toCommandProperties } from '../src/utils'
import {toCommandProperties} from '../src/utils'

/* eslint-disable @typescript-eslint/unbound-method */

Expand Down Expand Up @@ -142,17 +142,17 @@ describe('@actions/core', () => {
})

it('getInput gets required input', () => {
expect(core.getInput('my input', { required: true })).toBe('val')
expect(core.getInput('my input', {required: true})).toBe('val')
})

it('getInput throws on missing required input', () => {
expect(() => core.getInput('missing', { required: true })).toThrow(
expect(() => core.getInput('missing', {required: true})).toThrow(
'Input required and not supplied: missing'
)
})

it('getInput does not throw on missing non-required input', () => {
expect(core.getInput('missing', { required: false })).toBe('')
expect(core.getInput('missing', {required: false})).toBe('')
})

it('getInput is case insensitive', () => {
Expand Down Expand Up @@ -183,13 +183,13 @@ describe('@actions/core', () => {

it('getInput trims whitespace when option is explicitly true', () => {
expect(
core.getInput('with trailing whitespace', { trimWhitespace: true })
core.getInput('with trailing whitespace', {trimWhitespace: true})
).toBe('some val')
})

it('getInput does not trim whitespace when option is false', () => {
expect(
core.getInput('with trailing whitespace', { trimWhitespace: false })
core.getInput('with trailing whitespace', {trimWhitespace: false})
).toBe(' some val ')
})

Expand All @@ -198,7 +198,7 @@ describe('@actions/core', () => {
})

it('getInput gets required input', () => {
expect(core.getBooleanInput('boolean input', { required: true })).toBe(true)
expect(core.getBooleanInput('boolean input', {required: true})).toBe(true)
})

it('getBooleanInput handles boolean input', () => {
Expand All @@ -213,7 +213,7 @@ describe('@actions/core', () => {
it('getBooleanInput handles wrong boolean input', () => {
expect(() => core.getBooleanInput('wrong boolean input')).toThrow(
'Input does not meet YAML 1.2 "Core Schema" specification: wrong boolean input\n' +
`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``
`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``
)
})

Expand Down Expand Up @@ -272,8 +272,16 @@ describe('@actions/core', () => {

it('error handles parameters correctly', () => {
const message = 'this is my error message'
core.error(new Error(message), { title: 'A title', startColumn: 1, endColumn: 2, startLine: 5, endLine: 5 })
assertWriteCalls([`::error title=A title,line=5,end_line=5,col=1,end_column=2::Error: ${message}${os.EOL}`])
core.error(new Error(message), {
title: 'A title',
startColumn: 1,
endColumn: 2,
startLine: 5,
endLine: 5
})
assertWriteCalls([
`::error title=A title,line=5,end_line=5,col=1,end_column=2::Error: ${message}${os.EOL}`
])
})

it('warning sets the correct message', () => {
Expand All @@ -294,12 +302,26 @@ describe('@actions/core', () => {

it('warning handles parameters correctly', () => {
const message = 'this is my error message'
core.warning(new Error(message), { title: 'A title', startColumn: 1, endColumn: 2, startLine: 5, endLine: 5 })
assertWriteCalls([`::warning title=A title,line=5,end_line=5,col=1,end_column=2::Error: ${message}${os.EOL}`])
core.warning(new Error(message), {
title: 'A title',
startColumn: 1,
endColumn: 2,
startLine: 5,
endLine: 5
})
assertWriteCalls([
`::warning title=A title,line=5,end_line=5,col=1,end_column=2::Error: ${message}${os.EOL}`
])
})

it('annotations map field names correctly', () => {
const commandProperties = toCommandProperties({ title: 'A title', startColumn: 1, endColumn: 2, startLine: 5, endLine: 5 })
const commandProperties = toCommandProperties({
title: 'A title',
startColumn: 1,
endColumn: 2,
startLine: 5,
endLine: 5
})
expect(commandProperties.title).toBe('A title')
expect(commandProperties.col).toBe(1)
expect(commandProperties.end_column).toBe(2)
Expand Down

0 comments on commit 4b50f8c

Please sign in to comment.