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

fix: debug properly #1078

Merged
merged 1 commit into from
Nov 21, 2024
Merged
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
9 changes: 7 additions & 2 deletions src/lib/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { format } from 'node:util';

import * as core from '@actions/core';
import { Command as OclifCommand } from '@oclif/core';
import debugPkg from 'debug';

import { isGHA, isTest } from './isCI.js';

Expand All @@ -15,17 +16,21 @@ export default abstract class BaseCommand<T extends typeof OclifCommand> extends
constructor(argv: string[], config: Config) {
super(argv, config);

const oclifDebug = this.debug;
// this scope is copied from the @oclif/core source
// see https://github.com/oclif/core/blob/eef2ddedf6a844b28d8968ef5afd38c92f5875db/src/command.ts#L140
const scope = this.id ? `${this.config.bin}:${this.id}` : this.config.bin;

// rather than using the @oclif/core debug function, we use the debug package
// so we have full control over the scope.
const debug = debugPkg(scope);
// this is a lightweight reimplementation of the @oclif/core debug function
// with some debug logging functionality for github actions
this.debug = (formatter: unknown, ...args: unknown[]) => {
if (isGHA() && !isTest()) {
core.debug(`${scope}: ${format(formatter, ...args)}`);
}

return oclifDebug(formatter, ...args);
return debug(formatter, ...args);
};
}

Expand Down
Loading