Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 352aff7976 |
@@ -5,12 +5,6 @@ import {DownloadOptions, getDownloadOptions} from '../src/options'
|
|||||||
|
|
||||||
jest.mock('../src/internal/downloadUtils')
|
jest.mock('../src/internal/downloadUtils')
|
||||||
|
|
||||||
test('getCacheVersion does not mutate arguments', async () => {
|
|
||||||
const paths = ['node_modules']
|
|
||||||
getCacheVersion(paths, undefined, true)
|
|
||||||
expect(paths).toEqual(['node_modules'])
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getCacheVersion with one path returns version', async () => {
|
test('getCacheVersion with one path returns version', async () => {
|
||||||
const paths = ['node_modules']
|
const paths = ['node_modules']
|
||||||
const result = getCacheVersion(paths, undefined, true)
|
const result = getCacheVersion(paths, undefined, true)
|
||||||
|
|||||||
@@ -49,22 +49,6 @@ const testEnvVars = {
|
|||||||
const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
|
const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
|
||||||
const DELIMITER = `ghadelimiter_${UUID}`
|
const DELIMITER = `ghadelimiter_${UUID}`
|
||||||
|
|
||||||
function extractErrorMetadata(error: Error): {
|
|
||||||
file: string | undefined
|
|
||||||
line: string | undefined
|
|
||||||
column: string | undefined
|
|
||||||
} {
|
|
||||||
const stackLines = error.stack?.split(os.EOL) || []
|
|
||||||
const firstTraceLine = stackLines[1]
|
|
||||||
const match = firstTraceLine.match(/at (?:.*) \((.*):(\d+):(\d+)\)/) || []
|
|
||||||
const [, file, line, column] = match
|
|
||||||
return {
|
|
||||||
file,
|
|
||||||
line,
|
|
||||||
column
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('@actions/core', () => {
|
describe('@actions/core', () => {
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
const filePath = path.join(__dirname, `test`)
|
const filePath = path.join(__dirname, `test`)
|
||||||
@@ -395,14 +379,9 @@ describe('@actions/core', () => {
|
|||||||
|
|
||||||
it('setFailed handles Error', () => {
|
it('setFailed handles Error', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
const error = new Error(message)
|
core.setFailed(new Error(message))
|
||||||
|
|
||||||
core.setFailed(error)
|
|
||||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||||
const {file, line, column} = extractErrorMetadata(error)
|
assertWriteCalls([`::error::Error: ${message}${os.EOL}`])
|
||||||
assertWriteCalls([
|
|
||||||
`::error title=Error,file=${file},line=${line},col=${column}::Error: ${message}${os.EOL}`
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('error sets the correct error message', () => {
|
it('error sets the correct error message', () => {
|
||||||
@@ -417,21 +396,11 @@ describe('@actions/core', () => {
|
|||||||
|
|
||||||
it('error handles an error object', () => {
|
it('error handles an error object', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
const error = new Error(message)
|
core.error(new Error(message))
|
||||||
core.error(error)
|
|
||||||
const {file, line, column} = extractErrorMetadata(error)
|
|
||||||
assertWriteCalls([
|
|
||||||
`::error title=Error,file=${file},line=${line},col=${column}::Error: ${message}${os.EOL}`
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('error handles an error object and an empty properties', () => {
|
|
||||||
const message = 'this is my error message'
|
|
||||||
core.error(new Error(message), {})
|
|
||||||
assertWriteCalls([`::error::Error: ${message}${os.EOL}`])
|
assertWriteCalls([`::error::Error: ${message}${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('error handles custom properties correctly', () => {
|
it('error handles parameters correctly', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
core.error(new Error(message), {
|
core.error(new Error(message), {
|
||||||
title: 'A title',
|
title: 'A title',
|
||||||
@@ -458,21 +427,11 @@ describe('@actions/core', () => {
|
|||||||
|
|
||||||
it('warning handles an error object', () => {
|
it('warning handles an error object', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
const error = new Error(message)
|
core.warning(new Error(message))
|
||||||
core.warning(error)
|
|
||||||
const {file, line, column} = extractErrorMetadata(error)
|
|
||||||
assertWriteCalls([
|
|
||||||
`::warning title=Error,file=${file},line=${line},col=${column}::Error: ${message}${os.EOL}`
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('warning handles an error object and an empty properties', () => {
|
|
||||||
const message = 'this is my error message'
|
|
||||||
core.warning(new Error(message), {})
|
|
||||||
assertWriteCalls([`::warning::Error: ${message}${os.EOL}`])
|
assertWriteCalls([`::warning::Error: ${message}${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('warning handles custom properties correctly', () => {
|
it('warning handles parameters correctly', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
core.warning(new Error(message), {
|
core.warning(new Error(message), {
|
||||||
title: 'A title',
|
title: 'A title',
|
||||||
@@ -499,21 +458,11 @@ describe('@actions/core', () => {
|
|||||||
|
|
||||||
it('notice handles an error object', () => {
|
it('notice handles an error object', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
const error = new Error(message)
|
core.notice(new Error(message))
|
||||||
core.notice(error)
|
|
||||||
const {file, line, column} = extractErrorMetadata(error)
|
|
||||||
assertWriteCalls([
|
|
||||||
`::notice title=Error,file=${file},line=${line},col=${column}::Error: ${message}${os.EOL}`
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it('notice handles an error object and an empty properties', () => {
|
|
||||||
const message = 'this is my error message'
|
|
||||||
core.notice(new Error(message), {})
|
|
||||||
assertWriteCalls([`::notice::Error: ${message}${os.EOL}`])
|
assertWriteCalls([`::notice::Error: ${message}${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('notice handles custom properties correctly', () => {
|
it('notice handles parameters correctly', () => {
|
||||||
const message = 'this is my error message'
|
const message = 'this is my error message'
|
||||||
core.notice(new Error(message), {
|
core.notice(new Error(message), {
|
||||||
title: 'A title',
|
title: 'A title',
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
import {toAnnotationProperties} from '../src/utils'
|
|
||||||
|
|
||||||
describe('@actions/core/src/utils', () => {
|
|
||||||
describe('.toAnnotationProperties', () => {
|
|
||||||
it('extracts title only from Error instance without a parseable stack', () => {
|
|
||||||
const error = new TypeError('Test error')
|
|
||||||
error.stack = ''
|
|
||||||
expect(toAnnotationProperties(error)).toEqual({
|
|
||||||
title: 'TypeError',
|
|
||||||
file: undefined,
|
|
||||||
startLine: undefined,
|
|
||||||
startColumn: undefined
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('extracts AnnotationProperties from Error instance', () => {
|
|
||||||
const error = new ReferenceError('Test error')
|
|
||||||
expect(toAnnotationProperties(error)).toEqual({
|
|
||||||
title: 'ReferenceError',
|
|
||||||
file: expect.stringMatching(/utils\.test\.ts$/),
|
|
||||||
startLine: expect.any(Number),
|
|
||||||
startColumn: expect.any(Number)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Generated
-27
@@ -11,7 +11,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
"error-stack-parser": "^2.1.4",
|
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -52,19 +51,6 @@
|
|||||||
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
|
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/error-stack-parser": {
|
|
||||||
"version": "2.1.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.1.4.tgz",
|
|
||||||
"integrity": "sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"stackframe": "^1.3.4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/stackframe": {
|
|
||||||
"version": "1.3.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz",
|
|
||||||
"integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw=="
|
|
||||||
},
|
|
||||||
"node_modules/tunnel": {
|
"node_modules/tunnel": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||||
@@ -116,19 +102,6 @@
|
|||||||
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
|
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"error-stack-parser": {
|
|
||||||
"version": "2.1.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.1.4.tgz",
|
|
||||||
"integrity": "sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==",
|
|
||||||
"requires": {
|
|
||||||
"stackframe": "^1.3.4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"stackframe": {
|
|
||||||
"version": "1.3.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz",
|
|
||||||
"integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw=="
|
|
||||||
},
|
|
||||||
"tunnel": {
|
"tunnel": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
"error-stack-parser": "^2.1.4",
|
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import {issue, issueCommand} from './command'
|
import {issue, issueCommand} from './command'
|
||||||
import {issueFileCommand, prepareKeyValueMessage} from './file-command'
|
import {issueFileCommand, prepareKeyValueMessage} from './file-command'
|
||||||
import {
|
import {toCommandProperties, toCommandValue} from './utils'
|
||||||
toAnnotationProperties,
|
|
||||||
toCommandProperties,
|
|
||||||
toCommandValue
|
|
||||||
} from './utils'
|
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
@@ -245,21 +242,6 @@ export function debug(message: string): void {
|
|||||||
issueCommand('debug', {}, message)
|
issueCommand('debug', {}, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultAnnotationPropertes(
|
|
||||||
message: string | Error,
|
|
||||||
properties: AnnotationProperties | undefined = undefined
|
|
||||||
): AnnotationProperties {
|
|
||||||
// If no properties are provided, try to extract them from the Error instance
|
|
||||||
if (properties === undefined) {
|
|
||||||
if (message instanceof Error) {
|
|
||||||
properties = toAnnotationProperties(message)
|
|
||||||
} else {
|
|
||||||
properties = {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return properties
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error issue
|
* Adds an error issue
|
||||||
* @param message error issue message. Errors will be converted to string via toString()
|
* @param message error issue message. Errors will be converted to string via toString()
|
||||||
@@ -267,10 +249,8 @@ function defaultAnnotationPropertes(
|
|||||||
*/
|
*/
|
||||||
export function error(
|
export function error(
|
||||||
message: string | Error,
|
message: string | Error,
|
||||||
properties: AnnotationProperties | undefined = undefined
|
properties: AnnotationProperties = {}
|
||||||
): void {
|
): void {
|
||||||
properties = defaultAnnotationPropertes(message, properties)
|
|
||||||
|
|
||||||
issueCommand(
|
issueCommand(
|
||||||
'error',
|
'error',
|
||||||
toCommandProperties(properties),
|
toCommandProperties(properties),
|
||||||
@@ -285,10 +265,8 @@ export function error(
|
|||||||
*/
|
*/
|
||||||
export function warning(
|
export function warning(
|
||||||
message: string | Error,
|
message: string | Error,
|
||||||
properties: AnnotationProperties | undefined = undefined
|
properties: AnnotationProperties = {}
|
||||||
): void {
|
): void {
|
||||||
properties = defaultAnnotationPropertes(message, properties)
|
|
||||||
|
|
||||||
issueCommand(
|
issueCommand(
|
||||||
'warning',
|
'warning',
|
||||||
toCommandProperties(properties),
|
toCommandProperties(properties),
|
||||||
@@ -303,10 +281,8 @@ export function warning(
|
|||||||
*/
|
*/
|
||||||
export function notice(
|
export function notice(
|
||||||
message: string | Error,
|
message: string | Error,
|
||||||
properties: AnnotationProperties | undefined = undefined
|
properties: AnnotationProperties = {}
|
||||||
): void {
|
): void {
|
||||||
properties = defaultAnnotationPropertes(message, properties)
|
|
||||||
|
|
||||||
issueCommand(
|
issueCommand(
|
||||||
'notice',
|
'notice',
|
||||||
toCommandProperties(properties),
|
toCommandProperties(properties),
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import {AnnotationProperties} from './core'
|
import {AnnotationProperties} from './core'
|
||||||
import {CommandProperties} from './command'
|
import {CommandProperties} from './command'
|
||||||
import ErrorStackParser from 'error-stack-parser'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
||||||
@@ -40,21 +39,3 @@ export function toCommandProperties(
|
|||||||
endColumn: annotationProperties.endColumn
|
endColumn: annotationProperties.endColumn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toAnnotationProperties(error: Error): AnnotationProperties {
|
|
||||||
let firstFrame
|
|
||||||
|
|
||||||
try {
|
|
||||||
const stack = ErrorStackParser.parse(error)
|
|
||||||
firstFrame = stack?.[0]
|
|
||||||
} catch (parseError) {
|
|
||||||
// If we can't parse the stack, we'll just skip it
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
title: error.name,
|
|
||||||
file: firstFrame?.fileName,
|
|
||||||
startLine: firstFrame?.lineNumber,
|
|
||||||
startColumn: firstFrame?.columnNumber
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user