Remove workaround for setOutput

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2022-10-12 07:07:13 +02:00
parent 210d783f42
commit f17e188860
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
5 changed files with 11 additions and 50 deletions

View File

@ -1,6 +1,5 @@
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
import {describe, expect, it, jest} from '@jest/globals';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as context from '../src/context';
@ -166,30 +165,6 @@ describe('asyncForEach', () => {
});
});
describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn() as typeof process.stdout.write;
});
// eslint-disable-next-line jest/expect-expect
it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
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()}`;
@ -198,11 +173,3 @@ 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]);
}
}

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -1,9 +1,8 @@
import {parse} from 'csv-parse/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';
import * as core from '@actions/core';
import {parse} from 'csv-parse/sync';
let _tmpDir: string;
@ -73,8 +72,3 @@ 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: unknown): void {
issueCommand('set-output', {name}, value);
}

View File

@ -1,5 +1,5 @@
import * as fs from 'fs';
import {getInputs, Inputs, setOutput} from './context';
import {getInputs, Inputs} from './context';
import * as github from './github';
import {Meta, Version} from './meta';
import * as core from '@actions/core';
@ -41,7 +41,7 @@ async function run() {
core.info(version.main || '');
core.endGroup();
}
setOutput('version', version.main || '');
core.setOutput('version', version.main || '');
// Docker tags
const tags: Array<string> = meta.getTags();
@ -54,7 +54,7 @@ async function run() {
}
core.endGroup();
}
setOutput('tags', tags.join(inputs.sepTags));
core.setOutput('tags', tags.join(inputs.sepTags));
// Docker labels
const labels: Array<string> = meta.getLabels();
@ -63,21 +63,21 @@ async function run() {
core.info(label);
}
core.endGroup();
setOutput('labels', labels.join(inputs.sepLabels));
core.setOutput('labels', labels.join(inputs.sepLabels));
// JSON
const jsonOutput = meta.getJSON();
core.startGroup(`JSON output`);
core.info(JSON.stringify(jsonOutput, null, 2));
core.endGroup();
setOutput('json', jsonOutput);
core.setOutput('json', jsonOutput);
// Bake file definition
const bakeFile: string = meta.getBakeFile();
core.startGroup(`Bake file definition`);
core.info(fs.readFileSync(bakeFile, 'utf8'));
core.endGroup();
setOutput('bake-file', bakeFile);
core.setOutput('bake-file', bakeFile);
} catch (error) {
core.setFailed(error.message);
}