Skip to content

Commit db74366

Browse files
committed
fix(utils): prevent nested github actions log groups when run within nx target
1 parent b95e56c commit db74366

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/utils/src/lib/logger.int.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('Logger', () => {
5151
vi.stubEnv('CI', 'false');
5252
vi.stubEnv('GITHUB_ACTIONS', 'false');
5353
vi.stubEnv('GITLAB_CI', 'false');
54+
vi.stubEnv('NX_TASK_TARGET_TARGET', '');
5455
});
5556

5657
afterAll(() => {
@@ -247,6 +248,28 @@ ${ansis.cyan('└')} ${ansis.green(`Total line coverage is ${ansis.bold('82%')}`
247248
└ ESLint reported 4 errors and 11 warnings (1.23 s)
248249
::endgroup::
249250
251+
`);
252+
});
253+
254+
it('should NOT use native GitHub Actions log groups if run within Nx target', async () => {
255+
vi.stubEnv('CI', 'true');
256+
vi.stubEnv('GITHUB_ACTIONS', 'true');
257+
vi.stubEnv('NX_TASK_TARGET_TARGET', 'code-pushup');
258+
performanceNowSpy.mockReturnValueOnce(0).mockReturnValueOnce(1234); // group duration: 1.23 s
259+
const logger = new Logger();
260+
261+
await logger.group('Running plugin "ESLint"', async () => {
262+
logger.info('$ npx eslint . --format=json');
263+
logger.warn('Skipping unknown rule "deprecation/deprecation"');
264+
return 'ESLint reported 4 errors and 11 warnings';
265+
});
266+
267+
expect(ansis.strip(stdout)).toBe(`
268+
❯ Running plugin "ESLint"
269+
│ $ npx eslint . --format=json
270+
│ Skipping unknown rule "deprecation/deprecation"
271+
└ ESLint reported 4 errors and 11 warnings (1.23 s)
272+
250273
`);
251274
});
252275

packages/utils/src/lib/logger.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,16 @@ export class Logger {
350350
start: (title: string) => string;
351351
end: () => string;
352352
} {
353-
switch (this.#ciPlatform) {
353+
// Nx typically renders native log groups for each target in GitHub Actions
354+
// + GitHub Actions doesn't support nested log groups: https://github.com/actions/toolkit/issues/1001
355+
// => skip native GitHub Actions log groups if run within Nx target
356+
const platform =
357+
this.#ciPlatform === 'GitHub Actions' &&
358+
process.env['NX_TASK_TARGET_TARGET'] // https://nx.dev/docs/reference/environment-variables
359+
? undefined
360+
: this.#ciPlatform;
361+
362+
switch (platform) {
354363
case 'GitHub Actions':
355364
// https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-commands#grouping-log-lines
356365
return {

0 commit comments

Comments
 (0)