From 5c16b2f4faea56e9d5d15af1e365b5f05844cdd6 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Mon, 2 Mar 2020 07:45:27 -0500 Subject: [PATCH] Add core.isDebug() to check whether actions_step_debug is on or not. (#278) --- README.md | 6 ++++++ __tests__/core.test.ts | 13 +++++++++++++ src/core.ts | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 457f73c..5ad27ee 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,12 @@ try { core.warning('myInput was not set'); } + if (core.isDebug()) { + // curl -v https://github.com + } else { + // curl https://github.com + } + // Do stuff } catch (err) { diff --git a/__tests__/core.test.ts b/__tests__/core.test.ts index 9023542..020f4a5 100644 --- a/__tests__/core.test.ts +++ b/__tests__/core.test.ts @@ -177,6 +177,19 @@ describe('@actions/core', () => { it('getState gets wrapper action state', () => { expect(core.getState('TEST_1')).toBe('state_val') }) + + it('isDebug check debug state', () => { + const current = process.env['RUNNER_DEBUG'] + try { + delete process.env.RUNNER_DEBUG + expect(core.isDebug()).toBe(false) + + process.env['RUNNER_DEBUG'] = '1' + expect(core.isDebug()).toBe(true) + } finally { + process.env['RUNNER_DEBUG'] = current + } + }) }) // Assert that process.stdout.write calls called only with the given arguments. diff --git a/src/core.ts b/src/core.ts index dcaab53..9072f46 100644 --- a/src/core.ts +++ b/src/core.ts @@ -102,6 +102,13 @@ export function setFailed(message: string): void { // Logging Commands //----------------------------------------------------------------------- +/** + * Gets whether Actions Step Debug is on or not + */ +export function isDebug(): boolean { + return process.env['RUNNER_DEBUG'] === '1' +} + /** * Writes debug message to user log * @param message debug message