Skip to content

Commit

Permalink
Fix setOutput (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max and crazy-max committed May 9, 2021
1 parent 5068739 commit d0df47e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
32 changes: 32 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -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]);
}
}
16 changes: 11 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core';
import {issueCommand} from '@actions/core/lib/command';

export interface Inputs {
gpgPrivateKey: string;
Expand All @@ -25,3 +26,8 @@ export async function getInputs(): Promise<Inputs> {
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);
}
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ async function run(): Promise<void> {
}

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');
Expand Down

0 comments on commit d0df47e

Please sign in to comment.