Skip to content
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

Update to use :: instead of ## #110

Merged
merged 2 commits into from
Sep 9, 2019
Merged
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
38 changes: 19 additions & 19 deletions packages/core/__tests__/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,49 @@ describe('@actions/core', () => {

it('exportVariable produces the correct command and sets the env', () => {
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', () => {
core.exportVariable('special char var \r\n];', 'special val')
expect(process.env['special char var \r\n];']).toBe('special val')
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', () => {
core.exportVariable('my var2', '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', () => {
// core.exportSecret('my secret', 'secret val')
// expect(process.env['my secret']).toBe('secret val')
// assertWriteCalls([
// `##[set-env name=my secret;]secret val${os.EOL}`,
// `##[set-secret]secret val${os.EOL}`
// `::set-env name=my secret,::secret val${os.EOL}`,
// `::set-secret]secret val${os.EOL}`
// ])
// })

// it('exportSecret escapes secret names', () => {
// core.exportSecret('special char secret \r\n];', 'special secret val')
// expect(process.env['special char secret \r\n];']).toBe('special secret val')
// 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
// }`,
// `##[set-secret]special secret val${os.EOL}`
// `::set-secret]special secret val${os.EOL}`
// ])
// })

// it('exportSecret escapes secret values', () => {
// core.exportSecret('my secret2', 'secret val\r\n')
// expect(process.env['my secret2']).toBe('secret val\r\n')
// assertWriteCalls([
// `##[set-env name=my secret2;]secret val%0D%0A${os.EOL}`,
// `##[set-secret]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}`
// ])
// })

Expand All @@ -84,7 +84,7 @@ describe('@actions/core', () => {
expect(process.env['PATH']).toBe(
`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', () => {
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('@actions/core', () => {

it('setOutput produces the correct command', () => {
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', () => {
Expand All @@ -126,43 +126,43 @@ describe('@actions/core', () => {
it('setFailure sets the correct exit code and failure message', () => {
core.setFailed('Failure message')
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', () => {
core.setFailed('Failure \r\n\nmessage\r')
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', () => {
core.error('Error message')
assertWriteCalls([`##[error]Error message${os.EOL}`])
assertWriteCalls([`::error::Error message${os.EOL}`])
})

it('error escapes the error message', () => {
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', () => {
core.warning('Warning')
assertWriteCalls([`##[warning]Warning${os.EOL}`])
assertWriteCalls([`::warning::Warning${os.EOL}`])
})

it('warning escapes the message', () => {
core.warning('\r\nwarning\n')
assertWriteCalls([`##[warning]%0D%0Awarning%0A${os.EOL}`])
assertWriteCalls([`::warning::%0D%0Awarning%0A${os.EOL}`])
})

it('debug sets the correct message', () => {
core.debug('Debug')
assertWriteCalls([`##[debug]Debug${os.EOL}`])
assertWriteCalls([`::debug::Debug${os.EOL}`])
})

it('debug escapes the message', () => {
core.debug('\r\ndebug\n')
assertWriteCalls([`##[debug]%0D%0Adebug%0A${os.EOL}`])
assertWriteCalls([`::debug::%0D%0Adebug%0A${os.EOL}`])
})
})

Expand Down
2 changes: 1 addition & 1 deletion packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function issue(name: string, message: string): void {
issueCommand(name, {}, message)
}

const CMD_PREFIX = '##['
const CMD_STRING = '::'

class Command {
private readonly command: string
Expand All @@ -47,7 +47,7 @@ class Command {
}

toString(): string {
let cmdStr = CMD_PREFIX + this.command
let cmdStr = CMD_STRING + this.command

if (this.properties && Object.keys(this.properties).length > 0) {
cmdStr += ' '
Expand All @@ -57,13 +57,13 @@ class Command {
if (val) {
// safely append the val - avoid blowing up when attempting to
// 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
// call .replace() if message is not a string for some reason
Expand Down