Merge pull request #350 from crazy-max/fix-setoutput

Fix setOutput
This commit is contained in:
CrazyMax 2021-04-27 16:34:06 +02:00 committed by GitHub
commit 17822e4df4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 3 deletions

View file

@ -1,4 +1,5 @@
import * as fs from 'fs'; import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path'; import * as path from 'path';
import * as context from '../src/context'; import * as context from '../src/context';
@ -554,6 +555,27 @@ describe('asyncForEach', () => {
}); });
}); });
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}`]);
});
});
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67 // See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
function getInputName(name: string): string { function getInputName(name: string): string {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
@ -562,3 +584,11 @@ function getInputName(name: string): string {
function setInput(name: string, value: string): void { function setInput(name: string, value: string): void {
process.env[getInputName(name)] = value; process.env[getInputName(name)] = value;
} }
// 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]);
}
}

10
dist/index.js generated vendored
View file

@ -2419,7 +2419,7 @@ function run() {
if (imageID) { if (imageID) {
core.startGroup(`Extracting digest`); core.startGroup(`Extracting digest`);
core.info(`${imageID}`); core.info(`${imageID}`);
core.setOutput('digest', imageID); context.setOutput('digest', imageID);
core.endGroup(); core.endGroup();
} }
} }
@ -13004,7 +13004,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.asyncForEach = exports.getInputList = exports.getArgs = exports.getInputs = exports.tmpNameSync = exports.tmpDir = exports.defaultContext = void 0; exports.setOutput = exports.asyncForEach = exports.getInputList = exports.getArgs = exports.getInputs = exports.tmpNameSync = exports.tmpDir = exports.defaultContext = void 0;
const sync_1 = __importDefault(__webpack_require__(750)); const sync_1 = __importDefault(__webpack_require__(750));
const fs = __importStar(__webpack_require__(747)); const fs = __importStar(__webpack_require__(747));
const os = __importStar(__webpack_require__(87)); const os = __importStar(__webpack_require__(87));
@ -13012,6 +13012,7 @@ const path = __importStar(__webpack_require__(622));
const semver = __importStar(__webpack_require__(383)); const semver = __importStar(__webpack_require__(383));
const tmp = __importStar(__webpack_require__(517)); const tmp = __importStar(__webpack_require__(517));
const core = __importStar(__webpack_require__(186)); const core = __importStar(__webpack_require__(186));
const command_1 = __webpack_require__(351);
const github = __importStar(__webpack_require__(438)); const github = __importStar(__webpack_require__(438));
const buildx = __importStar(__webpack_require__(295)); const buildx = __importStar(__webpack_require__(295));
let _defaultContext, _tmpDir; let _defaultContext, _tmpDir;
@ -13189,6 +13190,11 @@ exports.asyncForEach = (array, callback) => __awaiter(void 0, void 0, void 0, fu
yield callback(array[index], index, array); yield callback(array[index], index, array);
} }
}); });
// 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 //# sourceMappingURL=context.js.map
/***/ }), /***/ }),

View file

@ -6,6 +6,7 @@ import * as semver from 'semver';
import * as tmp from 'tmp'; import * as tmp from 'tmp';
import * as core from '@actions/core'; import * as core from '@actions/core';
import {issueCommand} from '@actions/core/lib/command';
import * as github from '@actions/github'; import * as github from '@actions/github';
import * as buildx from './buildx'; import * as buildx from './buildx';
@ -205,3 +206,8 @@ export const asyncForEach = async (array, callback) => {
await callback(array[index], index, array); await callback(array[index], index, array);
} }
}; };
// 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

@ -36,7 +36,7 @@ async function run(): Promise<void> {
if (imageID) { if (imageID) {
core.startGroup(`Extracting digest`); core.startGroup(`Extracting digest`);
core.info(`${imageID}`); core.info(`${imageID}`);
core.setOutput('digest', imageID); context.setOutput('digest', imageID);
core.endGroup(); core.endGroup();
} }
} catch (error) { } catch (error) {