Skip to content

Commit

Permalink
Merge pull request #170 from crazy-max/setOutput
Browse files Browse the repository at this point in the history
Remove workaround for setOutput
  • Loading branch information
crazy-max committed Oct 12, 2022
2 parents 90a1e46 + 40fefd8 commit 83612be
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 47 deletions.
32 changes: 0 additions & 32 deletions __tests__/context.test.ts
Expand Up @@ -172,30 +172,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()}`;
Expand All @@ -204,11 +180,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 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/context.ts
Expand Up @@ -5,7 +5,6 @@ import * as tmp from 'tmp';
import * as uuid from 'uuid';
import * as buildx from './buildx';
import * as core from '@actions/core';
import {issueCommand} from '@actions/core/lib/command';

let _tmpDir: string;
export const osPlat: string = os.platform();
Expand Down Expand Up @@ -104,8 +103,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);
}
14 changes: 7 additions & 7 deletions src/main.ts
Expand Up @@ -53,7 +53,7 @@ async function run(): Promise<void> {
});
});

context.setOutput('name', inputs.name);
core.setOutput('name', inputs.name);
stateHelper.setBuilderName(inputs.name);

const credsdir = path.join(dockerConfigHome, 'buildx', 'creds', inputs.name);
Expand Down Expand Up @@ -89,12 +89,12 @@ async function run(): Promise<void> {
const builder = await buildx.inspect(inputs.name, standalone);
const firstNode = builder.nodes[0];
core.info(JSON.stringify(builder, undefined, 2));
context.setOutput('driver', builder.driver);
context.setOutput('platforms', firstNode.platforms);
context.setOutput('nodes', JSON.stringify(builder.nodes, undefined, 2));
context.setOutput('endpoint', firstNode.endpoint); // TODO: deprecated, to be removed in a later version
context.setOutput('status', firstNode.status); // TODO: deprecated, to be removed in a later version
context.setOutput('flags', firstNode['buildkitd-flags']); // TODO: deprecated, to be removed in a later version
core.setOutput('driver', builder.driver);
core.setOutput('platforms', firstNode.platforms);
core.setOutput('nodes', JSON.stringify(builder.nodes, undefined, 2));
core.setOutput('endpoint', firstNode.endpoint); // TODO: deprecated, to be removed in a later version
core.setOutput('status', firstNode.status); // TODO: deprecated, to be removed in a later version
core.setOutput('flags', firstNode['buildkitd-flags']); // TODO: deprecated, to be removed in a later version
core.endGroup();

if (!standalone && builder.driver == 'docker-container') {
Expand Down

0 comments on commit 83612be

Please sign in to comment.