Merge pull request #236 from crazy-max/setOutput

Remove workaround for setOutput
This commit is contained in:
CrazyMax 2022-10-12 08:34:51 +02:00 committed by GitHub
commit 12cce9efe0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 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';
@ -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 // 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()}`;
@ -198,11 +173,3 @@ 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]);
}
}

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

View file

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