mirror of
https://github.com/docker/metadata-action.git
synced 2024-12-22 10:15:30 +00:00
Fix setOutput (#67)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
34ebfd6e6b
commit
ae431178c1
|
@ -1,4 +1,5 @@
|
|||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
import * as context from '../src/context';
|
||||
|
@ -171,6 +172,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
|
||||
function getInputName(name: string): string {
|
||||
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
|
||||
|
@ -179,3 +201,11 @@ function getInputName(name: string): string {
|
|||
function setInput(name: string, value: string): void {
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
|
16
dist/index.js
generated
vendored
16
dist/index.js
generated
vendored
|
@ -39,9 +39,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.asyncForEach = exports.getInputList = exports.getInputs = exports.tmpDir = void 0;
|
||||
exports.setOutput = exports.asyncForEach = exports.getInputList = exports.getInputs = exports.tmpDir = void 0;
|
||||
const sync_1 = __importDefault(__webpack_require__(8750));
|
||||
const core = __importStar(__webpack_require__(2186));
|
||||
const command_1 = __webpack_require__(7351);
|
||||
const fs = __importStar(__webpack_require__(5747));
|
||||
const os = __importStar(__webpack_require__(2087));
|
||||
const path = __importStar(__webpack_require__(5622));
|
||||
|
@ -94,6 +95,11 @@ exports.asyncForEach = (array, callback) => __awaiter(void 0, void 0, void 0, fu
|
|||
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
|
||||
|
||||
/***/ }),
|
||||
|
@ -292,7 +298,7 @@ function run() {
|
|||
core.info(version.main || '');
|
||||
core.endGroup();
|
||||
}
|
||||
core.setOutput('version', version.main || '');
|
||||
context_1.setOutput('version', version.main || '');
|
||||
// Docker tags
|
||||
const tags = meta.getTags();
|
||||
if (tags.length == 0) {
|
||||
|
@ -305,7 +311,7 @@ function run() {
|
|||
}
|
||||
core.endGroup();
|
||||
}
|
||||
core.setOutput('tags', tags.join(inputs.sepTags));
|
||||
context_1.setOutput('tags', tags.join(inputs.sepTags));
|
||||
// Docker labels
|
||||
const labels = meta.getLabels();
|
||||
core.startGroup(`Docker labels`);
|
||||
|
@ -313,13 +319,13 @@ function run() {
|
|||
core.info(label);
|
||||
}
|
||||
core.endGroup();
|
||||
core.setOutput('labels', labels.join(inputs.sepLabels));
|
||||
context_1.setOutput('labels', labels.join(inputs.sepLabels));
|
||||
// Bake definition file
|
||||
const bakeFile = meta.getBakeFile();
|
||||
core.startGroup(`Bake definition file`);
|
||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||
core.endGroup();
|
||||
core.setOutput('bake-file', bakeFile);
|
||||
context_1.setOutput('bake-file', bakeFile);
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import csvparse from 'csv-parse/lib/sync';
|
||||
import * as core from '@actions/core';
|
||||
import {issueCommand} from '@actions/core/lib/command';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
@ -66,3 +67,8 @@ export const asyncForEach = async (array, callback) => {
|
|||
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);
|
||||
}
|
||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -1,5 +1,5 @@
|
|||
import * as fs from 'fs';
|
||||
import {getInputs, Inputs} from './context';
|
||||
import {getInputs, Inputs, setOutput} from './context';
|
||||
import * as github from './github';
|
||||
import {Meta, Version} from './meta';
|
||||
import * as core from '@actions/core';
|
||||
|
@ -36,7 +36,7 @@ async function run() {
|
|||
core.info(version.main || '');
|
||||
core.endGroup();
|
||||
}
|
||||
core.setOutput('version', version.main || '');
|
||||
setOutput('version', version.main || '');
|
||||
|
||||
// Docker tags
|
||||
const tags: Array<string> = meta.getTags();
|
||||
|
@ -49,7 +49,7 @@ async function run() {
|
|||
}
|
||||
core.endGroup();
|
||||
}
|
||||
core.setOutput('tags', tags.join(inputs.sepTags));
|
||||
setOutput('tags', tags.join(inputs.sepTags));
|
||||
|
||||
// Docker labels
|
||||
const labels: Array<string> = meta.getLabels();
|
||||
|
@ -58,14 +58,14 @@ async function run() {
|
|||
core.info(label);
|
||||
}
|
||||
core.endGroup();
|
||||
core.setOutput('labels', labels.join(inputs.sepLabels));
|
||||
setOutput('labels', labels.join(inputs.sepLabels));
|
||||
|
||||
// Bake definition file
|
||||
const bakeFile: string = meta.getBakeFile();
|
||||
core.startGroup(`Bake definition file`);
|
||||
core.info(fs.readFileSync(bakeFile, 'utf8'));
|
||||
core.endGroup();
|
||||
core.setOutput('bake-file', bakeFile);
|
||||
setOutput('bake-file', bakeFile);
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue