Skip to content

Commit

Permalink
Merge pull request #236 from crazy-max/setOutput
Browse files Browse the repository at this point in the history
Remove workaround for setOutput
  • Loading branch information
crazy-max authored Oct 12, 2022
2 parents 210d783 + f17e188 commit 12cce9e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 50 deletions.
35 changes: 1 addition & 34 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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()}`;
Expand All @@ -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 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.

10 changes: 2 additions & 8 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
}
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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);
}
Expand Down

0 comments on commit 12cce9e

Please sign in to comment.