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 setOutput #86

Merged
merged 1 commit into from
May 9, 2021
Merged
Show file tree
Hide file tree
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
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