Fix setOutput (#86)

Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-05-09 11:15:20 +02:00 committed by GitHub
parent 5068739ab7
commit d0df47e309
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 9 deletions

32
__tests__/context.test.ts Normal file
View file

@ -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
dist/index.js generated vendored
View file

@ -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);

View file

@ -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<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);
}

View file

@ -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');