From d0df47e3093269d50f9c2bd37864f96ef7383350 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 9 May 2021 11:15:20 +0200 Subject: [PATCH] Fix setOutput (#86) Co-authored-by: CrazyMax --- __tests__/context.test.ts | 32 ++++++++++++++++++++++++++++++++ dist/index.js | 16 +++++++++++----- src/context.ts | 6 ++++++ src/main.ts | 8 ++++---- 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 __tests__/context.test.ts diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts new file mode 100644 index 0000000..b5ce77b --- /dev/null +++ b/__tests__/context.test.ts @@ -0,0 +1,32 @@ +import * as os from 'os'; + +import * as context from '../src/context'; + +describe('setOutput', () => { + beforeEach(() => { + process.stdout.write = jest.fn(); + }); + + it('setOutput produces the correct command', () => { + context.setOutput('some output', 'some value'); + assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]); + }); + + it('setOutput handles bools', () => { + context.setOutput('some output', false); + assertWriteCalls([`::set-output name=some output::false${os.EOL}`]); + }); + + it('setOutput handles numbers', () => { + context.setOutput('some output', 1.01); + assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]); + }); +}); + +// Assert that process.stdout.write calls called only with the given arguments. +function assertWriteCalls(calls: string[]): void { + expect(process.stdout.write).toHaveBeenCalledTimes(calls.length); + for (let i = 0; i < calls.length; i++) { + expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]); + } +} diff --git a/dist/index.js b/dist/index.js index 3e98cce..01f0782 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,8 +36,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getInputs = void 0; +exports.setOutput = exports.getInputs = void 0; const core = __importStar(__webpack_require__(186)); +const command_1 = __webpack_require__(351); function getInputs() { return __awaiter(this, void 0, void 0, function* () { return { @@ -54,6 +55,11 @@ function getInputs() { }); } exports.getInputs = getInputs; +// FIXME: Temp fix https://github.com/actions/toolkit/issues/777 +function setOutput(name, value) { + command_1.issueCommand('set-output', { name }, value); +} +exports.setOutput = setOutput; //# sourceMappingURL=context.js.map /***/ }), @@ -440,10 +446,10 @@ function run() { } } core.info('🛒 Setting outputs...'); - core.setOutput('fingerprint', privateKey.fingerprint); - core.setOutput('keyid', privateKey.keyID); - core.setOutput('name', privateKey.name); - core.setOutput('email', privateKey.email); + context.setOutput('fingerprint', privateKey.fingerprint); + context.setOutput('keyid', privateKey.keyID); + context.setOutput('name', privateKey.name); + context.setOutput('email', privateKey.email); if (inputs.gitUserSigningkey) { core.info('🔐 Setting GPG signing keyID for this Git repository'); yield git.setConfig('user.signingkey', privateKey.keyID); diff --git a/src/context.ts b/src/context.ts index 2ad5d9c..8b80e1c 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import {issueCommand} from '@actions/core/lib/command'; export interface Inputs { gpgPrivateKey: string; @@ -25,3 +26,8 @@ export async function getInputs(): Promise { workdir: core.getInput('workdir') || '.' }; } + +// FIXME: Temp fix https://github.com/actions/toolkit/issues/777 +export function setOutput(name: string, value: any): void { + issueCommand('set-output', {name}, value); +} diff --git a/src/main.ts b/src/main.ts index d75a480..296b35d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -51,10 +51,10 @@ async function run(): Promise { } core.info('🛒 Setting outputs...'); - core.setOutput('fingerprint', privateKey.fingerprint); - core.setOutput('keyid', privateKey.keyID); - core.setOutput('name', privateKey.name); - core.setOutput('email', privateKey.email); + context.setOutput('fingerprint', privateKey.fingerprint); + context.setOutput('keyid', privateKey.keyID); + context.setOutput('name', privateKey.name); + context.setOutput('email', privateKey.email); if (inputs.gitUserSigningkey) { core.info('🔐 Setting GPG signing keyID for this Git repository');