-
Notifications
You must be signed in to change notification settings - Fork 15
feat(ci): style top-level logs #1156
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import ansis from 'ansis'; | ||
| import { | ||
| CODE_PUSHUP_UNICODE_LOGO, | ||
| logger, | ||
| transformLines, | ||
| } from '@code-pushup/utils'; | ||
|
|
||
| const LOG_PREFIX = ansis.bold.blue(CODE_PUSHUP_UNICODE_LOGO); | ||
|
|
||
| /** | ||
| * Logs error message with top-level CI log styles (lines prefixed with logo, ends in empty line). | ||
| * @param message Log message | ||
| */ | ||
| export function logError(message: string): void { | ||
| log('error', message); | ||
| } | ||
|
|
||
| /** | ||
| * Logs warning message with top-level CI log styles (lines prefixed with logo, ends in empty line). | ||
| * @param message Log message | ||
| */ | ||
| export function logWarning(message: string): void { | ||
| log('warn', message); | ||
| } | ||
|
|
||
| /** | ||
| * Logs info message with top-level CI log styles (lines prefixed with logo, ends in empty line). | ||
| * @param message Log message | ||
| */ | ||
| export function logInfo(message: string): void { | ||
| log('info', message); | ||
| } | ||
|
|
||
| /** | ||
| * Logs debug message with top-level CI log styles (lines prefixed with logo, ends in empty line). | ||
| * @param message Log message | ||
| */ | ||
| export function logDebug(message: string): void { | ||
| log('debug', message); | ||
| } | ||
|
|
||
| /** | ||
| * Prefixes CI logs with logo and ensures each CI log is followed by an empty line. | ||
| * This is to make top-level CI logs more visually distinct from printed process logs. | ||
| * @param level Log level | ||
| * @param message Log message | ||
| */ | ||
| export function log( | ||
| level: 'error' | 'warn' | 'info' | 'debug', | ||
| message: string, | ||
| ): void { | ||
| const prefixedLines = transformLines( | ||
| message.trim(), | ||
| line => `${LOG_PREFIX} ${line}`, | ||
| ); | ||
| const styledMessage = `${prefixedLines}\n`; | ||
|
|
||
| logger[level](styledMessage); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import ansis from 'ansis'; | ||
| import { logger } from '@code-pushup/utils'; | ||
| import { log } from './log.js'; | ||
|
|
||
| describe('log', () => { | ||
|
Check failure on line 5 in packages/ci/src/lib/log.unit.test.ts
|
||
| it('should add logo prefix and ending line-break to message', () => { | ||
|
Check failure on line 6 in packages/ci/src/lib/log.unit.test.ts
|
||
| log('info', 'Running Code PushUp in standalone mode'); | ||
| expect(logger.info).toHaveBeenCalledWith( | ||
| `${ansis.bold.blue('<✓>')} Running Code PushUp in standalone mode\n`, | ||
| ); | ||
| }); | ||
|
|
||
| it('should add logo prefix to each line', () => { | ||
|
Check failure on line 13 in packages/ci/src/lib/log.unit.test.ts
|
||
| log('debug', 'Found 3 Nx projects:\n- api\n- backoffice\n- frontoffice'); | ||
| expect(logger.debug).toHaveBeenCalledWith( | ||
| ` | ||
| ${ansis.bold.blue('<✓>')} Found 3 Nx projects: | ||
| ${ansis.bold.blue('<✓>')} - api | ||
| ${ansis.bold.blue('<✓>')} - backoffice | ||
| ${ansis.bold.blue('<✓>')} - frontoffice | ||
| `.trimStart(), | ||
| ); | ||
| }); | ||
|
|
||
| it('should not add final line-break if already present', () => { | ||
|
Check failure on line 25 in packages/ci/src/lib/log.unit.test.ts
|
||
| log('warn', 'Comment body is too long, truncating to 1000 characters\n'); | ||
| expect(logger.warn).toHaveBeenCalledWith( | ||
| `${ansis.bold.blue('<✓>')} Comment body is too long, truncating to 1000 characters\n`, | ||
| ); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.