-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ado-improvements-1): Pipeline specific formatting (#1051)
- Loading branch information
Showing
21 changed files
with
355 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
...c/output-hooks/stdout-transformer.spec.ts → ...tput-hooks/ado-stdout-transformer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { stdoutTransformer } from './stdout-transformer'; | ||
import { adoStdoutTransformer } from './ado-stdout-transformer'; | ||
|
||
describe(stdoutTransformer, () => { | ||
describe(adoStdoutTransformer, () => { | ||
it.each` | ||
input | expectedOutput | ||
${'abc'} | ${'##[debug]abc'} | ||
${'[Trace][info] ==='} | ${'##[debug][Trace][info] ==='} | ||
${'\u001B[32mINFO\u001b[39m'} | ${'##[debug]\u001B[32mINFO\u001b[39m'} | ||
${'Processing page'} | ${'##[debug]Processing page'} | ||
${'Discovered 12 links on'} | ${'##[debug]Discovered 12 links on'} | ||
`(`Debug tag added to raw input - input value '$input' returned as '$expectedOutput'`, ({ input, expectedOutput }) => { | ||
const output = stdoutTransformer(input); | ||
const output = adoStdoutTransformer(input); | ||
expect(output).toBe(expectedOutput); | ||
}); | ||
|
||
it.each` | ||
input | expectedOutput | ||
${'\u001B[32mINFO\u001b[39m '} | ${'##[debug]'} | ||
${'\u001B[32mINFO\u001b[39m abc'} | ${'##[debug]abc'} | ||
${'##[verbose]abc'} | ${'##[debug]abc'} | ||
`(`Debug tag added to modified input - input value '$input' returned as '$expectedOutput'`, ({ input, expectedOutput }) => { | ||
const output = stdoutTransformer(input); | ||
const output = adoStdoutTransformer(input); | ||
expect(output).toBe(expectedOutput); | ||
}); | ||
|
||
it.each` | ||
input | ||
${'##[error]abc'} | ||
${'##vso[task.debug]abc'} | ||
${'Processing page abc'} | ||
${'Discovered 2 links on page abc'} | ||
${'Discovered 2345 links on page abc'} | ||
${'Found 3 accessibility issues on page abc'} | ||
${'Found 3456 accessibility issues on page abc'} | ||
`(`Debug tag not added - input value '$input' returned as '$input'`, ({ input }) => { | ||
const output = stdoutTransformer(input); | ||
const output = adoStdoutTransformer(input); | ||
expect(output).toBe(input); | ||
}); | ||
|
||
it.each` | ||
input | expectedOutput | ||
${'##[warn]abc'} | ${'##[warning]abc'} | ||
${'##[info]abc'} | ${'abc'} | ||
input | expectedOutput | ||
${'[group]abc'} | ${'##[group]abc'} | ||
${'[endgroup]abc'} | ${'##[endgroup]abc'} | ||
${'[debug]abc'} | ${'##[debug]abc'} | ||
${'[warning]abc'} | ${'##[warning]abc'} | ||
${'[info]abc'} | ${'abc'} | ||
`(`LogLevel tags mapped input as '$input', returned as '$expectedOutput'`, ({ input, expectedOutput }) => { | ||
const output = stdoutTransformer(input); | ||
const output = adoStdoutTransformer(input); | ||
expect(output).toBe(expectedOutput); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/gh-action/src/output-hooks/gh-stdout-transformer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { ghStdoutTransformer } from './gh-stdout-transformer'; | ||
|
||
describe(ghStdoutTransformer, () => { | ||
it.each` | ||
input | expectedOutput | ||
${'abc'} | ${'::debug::abc'} | ||
${'\u001B[32mINFO\u001b[39m'} | ${'::debug::\u001B[32mINFO\u001b[39m'} | ||
${'Processing page'} | ${'::debug::Processing page'} | ||
${'Discovered 12 links on'} | ${'::debug::Discovered 12 links on'} | ||
`(`Debug tag added to raw input - input value '$input' returned as '$expectedOutput'`, ({ input, expectedOutput }) => { | ||
const output = ghStdoutTransformer(input); | ||
expect(output).toBe(expectedOutput); | ||
}); | ||
|
||
it.each` | ||
input | expectedOutput | ||
${'\u001B[32mINFO\u001b[39m '} | ${'::debug::'} | ||
${'\u001B[32mINFO\u001b[39m abc'} | ${'::debug::abc'} | ||
`(`Debug tag added to modified input - input value '$input' returned as '$expectedOutput'`, ({ input, expectedOutput }) => { | ||
const output = ghStdoutTransformer(input); | ||
expect(output).toBe(expectedOutput); | ||
}); | ||
|
||
it.each` | ||
input | ||
${'Processing page abc'} | ||
${'Discovered 2 links on page abc'} | ||
${'Discovered 2345 links on page abc'} | ||
${'Found 3 accessibility issues on page abc'} | ||
${'Found 3456 accessibility issues on page abc'} | ||
`(`Debug tag not added - input value '$input' returned as '$input'`, ({ input }) => { | ||
const output = ghStdoutTransformer(input); | ||
expect(output).toBe(input); | ||
}); | ||
|
||
it.each` | ||
input | expectedOutput | ||
${'[group]abc'} | ${'::group::abc'} | ||
${'[endgroup]abc'} | ${'::endgroup::abc'} | ||
${'[debug]abc'} | ${'::debug::abc'} | ||
${'[warning]abc'} | ${'::warning::abc'} | ||
${'[info]abc'} | ${'abc'} | ||
`(`LogLevel tags mapped input as '$input', returned as '$expectedOutput'`, ({ input, expectedOutput }) => { | ||
const output = ghStdoutTransformer(input); | ||
expect(output).toBe(expectedOutput); | ||
}); | ||
}); |
110 changes: 110 additions & 0 deletions
110
packages/gh-action/src/output-hooks/gh-stdout-transformer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
const debugPrefix = '::debug::'; | ||
|
||
type RegexTransformation = { | ||
regex: RegExp; | ||
method: (rawData: string, regex?: RegExp) => string; | ||
}; | ||
|
||
const regexTransformations: RegexTransformation[] = [ | ||
{ | ||
regex: new RegExp('^Processing page .*'), | ||
method: useUnmodifiedString, | ||
}, | ||
{ | ||
regex: new RegExp('^Discovered \\d* links on page '), | ||
method: useUnmodifiedString, | ||
}, | ||
{ | ||
regex: new RegExp('^Found \\d* accessibility issues on page '), | ||
method: useUnmodifiedString, | ||
}, | ||
{ | ||
regex: new RegExp('^\\[error\\]'), | ||
method: replaceFirstMatchWithErrorPrefix, | ||
}, | ||
{ | ||
regex: new RegExp('^\\[info\\]'), | ||
method: removeFirstMatch, | ||
}, | ||
{ | ||
regex: new RegExp('^\\[warning\\]'), | ||
method: replaceFirstMatchWithWarningPrefix, | ||
}, | ||
{ | ||
regex: new RegExp('^\\[verbose\\]'), | ||
method: replaceFirstMatchWithDebugPrefix, | ||
}, | ||
{ | ||
regex: new RegExp('^\\[debug\\]'), | ||
method: replaceFirstMatchWithDebugPrefix, | ||
}, | ||
{ | ||
regex: new RegExp('^\\[group\\]'), | ||
method: replaceFirstMatchWithGroupPrefix, | ||
}, | ||
{ | ||
regex: new RegExp('^\\[endgroup\\]'), | ||
method: replaceFirstMatchWithEndgroupPrefix, | ||
}, | ||
{ | ||
// eslint-disable-next-line no-control-regex | ||
regex: new RegExp('^\u001B\\[32mINFO\u001b\\[39m '), // Includes escape characters used for color formatting) | ||
method: replaceFirstMatchWithDebugPrefix, | ||
}, | ||
]; | ||
|
||
export const ghStdoutTransformer = (rawData: string): string | null => { | ||
for (const startSubstitution of regexTransformations) { | ||
const newData = regexTransformation(rawData, startSubstitution.regex, startSubstitution.method); | ||
|
||
if (newData) { | ||
return newData; | ||
} | ||
} | ||
|
||
return prependDebugPrefix(rawData); | ||
}; | ||
|
||
const regexTransformation = (input: string, regex: RegExp, modifier: (input: string, regex?: RegExp) => string): string | null => { | ||
const matches = input.match(regex); | ||
if (matches) { | ||
return modifier(input, regex); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
function useUnmodifiedString(input: string): string { | ||
return input; | ||
} | ||
|
||
function removeFirstMatch(input: string, regex: RegExp): string { | ||
return `${input.replace(regex, '$`')}`; | ||
} | ||
|
||
function replaceFirstMatchWithDebugPrefix(input: string, regex: RegExp): string { | ||
return `${debugPrefix}${input.replace(regex, '$`')}`; | ||
} | ||
|
||
function replaceFirstMatchWithWarningPrefix(input: string, regex: RegExp): string { | ||
return `::warning::${input.replace(regex, '$`')}`; | ||
} | ||
|
||
function replaceFirstMatchWithErrorPrefix(input: string, regex: RegExp): string { | ||
return `::error::${input.replace(regex, '$`')}`; | ||
} | ||
|
||
function replaceFirstMatchWithGroupPrefix(input: string, regex: RegExp): string { | ||
return `::group::${input.replace(regex, '$`')}`; | ||
} | ||
|
||
function replaceFirstMatchWithEndgroupPrefix(input: string, regex: RegExp): string { | ||
return `::endgroup::${input.replace(regex, '$`')}`; | ||
} | ||
|
||
function prependDebugPrefix(input: string): string { | ||
return `${debugPrefix}${input}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.