mirror of https://github.com/actions/toolkit
parent
b529540e0c
commit
a6e7249776
|
@ -33,29 +33,29 @@ describe('@actions/core', () => {
|
||||||
|
|
||||||
it('exportVariable produces the correct command and sets the env', () => {
|
it('exportVariable produces the correct command and sets the env', () => {
|
||||||
core.exportVariable('my var', 'var val')
|
core.exportVariable('my var', 'var val')
|
||||||
assertWriteCalls([`##[set-env name=my var;]var val${os.EOL}`])
|
assertWriteCalls([`::set-env name=my var,::var val${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('exportVariable escapes variable names', () => {
|
it('exportVariable escapes variable names', () => {
|
||||||
core.exportVariable('special char var \r\n];', 'special val')
|
core.exportVariable('special char var \r\n];', 'special val')
|
||||||
expect(process.env['special char var \r\n];']).toBe('special val')
|
expect(process.env['special char var \r\n];']).toBe('special val')
|
||||||
assertWriteCalls([
|
assertWriteCalls([
|
||||||
`##[set-env name=special char var %0D%0A%5D%3B;]special val${os.EOL}`
|
`::set-env name=special char var %0D%0A%5D%3B,::special val${os.EOL}`
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('exportVariable escapes variable values', () => {
|
it('exportVariable escapes variable values', () => {
|
||||||
core.exportVariable('my var2', 'var val\r\n')
|
core.exportVariable('my var2', 'var val\r\n')
|
||||||
expect(process.env['my var2']).toBe('var val\r\n')
|
expect(process.env['my var2']).toBe('var val\r\n')
|
||||||
assertWriteCalls([`##[set-env name=my var2;]var val%0D%0A${os.EOL}`])
|
assertWriteCalls([`::set-env name=my var2,::var val%0D%0A${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
// it('exportSecret produces the correct commands and sets the env', () => {
|
// it('exportSecret produces the correct commands and sets the env', () => {
|
||||||
// core.exportSecret('my secret', 'secret val')
|
// core.exportSecret('my secret', 'secret val')
|
||||||
// expect(process.env['my secret']).toBe('secret val')
|
// expect(process.env['my secret']).toBe('secret val')
|
||||||
// assertWriteCalls([
|
// assertWriteCalls([
|
||||||
// `##[set-env name=my secret;]secret val${os.EOL}`,
|
// `::set-env name=my secret,::secret val${os.EOL}`,
|
||||||
// `##[set-secret]secret val${os.EOL}`
|
// `::set-secret]secret val${os.EOL}`
|
||||||
// ])
|
// ])
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
@ -63,10 +63,10 @@ describe('@actions/core', () => {
|
||||||
// core.exportSecret('special char secret \r\n];', 'special secret val')
|
// core.exportSecret('special char secret \r\n];', 'special secret val')
|
||||||
// expect(process.env['special char secret \r\n];']).toBe('special secret val')
|
// expect(process.env['special char secret \r\n];']).toBe('special secret val')
|
||||||
// assertWriteCalls([
|
// assertWriteCalls([
|
||||||
// `##[set-env name=special char secret %0D%0A%5D%3B;]special secret val${
|
// `::set-env name=special char secret %0D%0A%5D%3B,::special secret val${
|
||||||
// os.EOL
|
// os.EOL
|
||||||
// }`,
|
// }`,
|
||||||
// `##[set-secret]special secret val${os.EOL}`
|
// `::set-secret]special secret val${os.EOL}`
|
||||||
// ])
|
// ])
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
@ -74,8 +74,8 @@ describe('@actions/core', () => {
|
||||||
// core.exportSecret('my secret2', 'secret val\r\n')
|
// core.exportSecret('my secret2', 'secret val\r\n')
|
||||||
// expect(process.env['my secret2']).toBe('secret val\r\n')
|
// expect(process.env['my secret2']).toBe('secret val\r\n')
|
||||||
// assertWriteCalls([
|
// assertWriteCalls([
|
||||||
// `##[set-env name=my secret2;]secret val%0D%0A${os.EOL}`,
|
// `::set-env name=my secret2,::secret val%0D%0A${os.EOL}`,
|
||||||
// `##[set-secret]secret val%0D%0A${os.EOL}`
|
// `::set-secret]secret val%0D%0A${os.EOL}`
|
||||||
// ])
|
// ])
|
||||||
// })
|
// })
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ describe('@actions/core', () => {
|
||||||
expect(process.env['PATH']).toBe(
|
expect(process.env['PATH']).toBe(
|
||||||
`myPath${path.delimiter}path1${path.delimiter}path2`
|
`myPath${path.delimiter}path1${path.delimiter}path2`
|
||||||
)
|
)
|
||||||
assertWriteCalls([`##[add-path]myPath${os.EOL}`])
|
assertWriteCalls([`::add-path::myPath${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('getInput gets non-required input', () => {
|
it('getInput gets non-required input', () => {
|
||||||
|
@ -115,7 +115,7 @@ describe('@actions/core', () => {
|
||||||
|
|
||||||
it('setOutput produces the correct command', () => {
|
it('setOutput produces the correct command', () => {
|
||||||
core.setOutput('some output', 'some value')
|
core.setOutput('some output', 'some value')
|
||||||
assertWriteCalls([`##[set-output name=some output;]some value${os.EOL}`])
|
assertWriteCalls([`::set-output name=some output,::some value${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('setNeutral sets the correct exit code', () => {
|
it('setNeutral sets the correct exit code', () => {
|
||||||
|
@ -126,33 +126,33 @@ describe('@actions/core', () => {
|
||||||
it('setFailure sets the correct exit code and failure message', () => {
|
it('setFailure sets the correct exit code and failure message', () => {
|
||||||
core.setFailed('Failure message')
|
core.setFailed('Failure message')
|
||||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||||
assertWriteCalls([`##[error]Failure message${os.EOL}`])
|
assertWriteCalls([`::error::Failure message${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('setFailure escapes the failure message', () => {
|
it('setFailure escapes the failure message', () => {
|
||||||
core.setFailed('Failure \r\n\nmessage\r')
|
core.setFailed('Failure \r\n\nmessage\r')
|
||||||
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
expect(process.exitCode).toBe(core.ExitCode.Failure)
|
||||||
assertWriteCalls([`##[error]Failure %0D%0A%0Amessage%0D${os.EOL}`])
|
assertWriteCalls([`::error::Failure %0D%0A%0Amessage%0D${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('error sets the correct error message', () => {
|
it('error sets the correct error message', () => {
|
||||||
core.error('Error message')
|
core.error('Error message')
|
||||||
assertWriteCalls([`##[error]Error message${os.EOL}`])
|
assertWriteCalls([`::error::Error message${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('error escapes the error message', () => {
|
it('error escapes the error message', () => {
|
||||||
core.error('Error message\r\n\n')
|
core.error('Error message\r\n\n')
|
||||||
assertWriteCalls([`##[error]Error message%0D%0A%0A${os.EOL}`])
|
assertWriteCalls([`::error::Error message%0D%0A%0A${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('warning sets the correct message', () => {
|
it('warning sets the correct message', () => {
|
||||||
core.warning('Warning')
|
core.warning('Warning')
|
||||||
assertWriteCalls([`##[warning]Warning${os.EOL}`])
|
assertWriteCalls([`::warning::Warning${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('warning escapes the message', () => {
|
it('warning escapes the message', () => {
|
||||||
core.warning('\r\nwarning\n')
|
core.warning('\r\nwarning\n')
|
||||||
assertWriteCalls([`##[warning]%0D%0Awarning%0A${os.EOL}`])
|
assertWriteCalls([`::warning::%0D%0Awarning%0A${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('startGroup starts a new group', () => {
|
it('startGroup starts a new group', () => {
|
||||||
|
@ -180,12 +180,12 @@ describe('@actions/core', () => {
|
||||||
|
|
||||||
it('debug sets the correct message', () => {
|
it('debug sets the correct message', () => {
|
||||||
core.debug('Debug')
|
core.debug('Debug')
|
||||||
assertWriteCalls([`##[debug]Debug${os.EOL}`])
|
assertWriteCalls([`::debug::Debug${os.EOL}`])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('debug escapes the message', () => {
|
it('debug escapes the message', () => {
|
||||||
core.debug('\r\ndebug\n')
|
core.debug('\r\ndebug\n')
|
||||||
assertWriteCalls([`##[debug]%0D%0Adebug%0A${os.EOL}`])
|
assertWriteCalls([`::debug::%0D%0Adebug%0A${os.EOL}`])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@actions/core",
|
"name": "@actions/core",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -29,7 +29,7 @@ export function issue(name: string, message: string = ''): void {
|
||||||
issueCommand(name, {}, message)
|
issueCommand(name, {}, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
const CMD_PREFIX = '##['
|
const CMD_STRING = '::'
|
||||||
|
|
||||||
class Command {
|
class Command {
|
||||||
private readonly command: string
|
private readonly command: string
|
||||||
|
@ -47,7 +47,7 @@ class Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
let cmdStr = CMD_PREFIX + this.command
|
let cmdStr = CMD_STRING + this.command
|
||||||
|
|
||||||
if (this.properties && Object.keys(this.properties).length > 0) {
|
if (this.properties && Object.keys(this.properties).length > 0) {
|
||||||
cmdStr += ' '
|
cmdStr += ' '
|
||||||
|
@ -57,13 +57,13 @@ class Command {
|
||||||
if (val) {
|
if (val) {
|
||||||
// safely append the val - avoid blowing up when attempting to
|
// safely append the val - avoid blowing up when attempting to
|
||||||
// call .replace() if message is not a string for some reason
|
// call .replace() if message is not a string for some reason
|
||||||
cmdStr += `${key}=${escape(`${val || ''}`)};`
|
cmdStr += `${key}=${escape(`${val || ''}`)},`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdStr += ']'
|
cmdStr += CMD_STRING
|
||||||
|
|
||||||
// safely append the message - avoid blowing up when attempting to
|
// safely append the message - avoid blowing up when attempting to
|
||||||
// call .replace() if message is not a string for some reason
|
// call .replace() if message is not a string for some reason
|
||||||
|
|
Loading…
Reference in New Issue