Skip to content

Commit 12cce9e

Browse files
authored
Merge pull request #236 from crazy-max/setOutput
Remove workaround for setOutput
2 parents 210d783 + f17e188 commit 12cce9e

File tree

5 files changed

+11
-50
lines changed

5 files changed

+11
-50
lines changed

__tests__/context.test.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {beforeEach, describe, expect, it, jest} from '@jest/globals';
1+
import {describe, expect, it, jest} from '@jest/globals';
22
import * as fs from 'fs';
3-
import * as os from 'os';
43
import * as path from 'path';
54

65
import * as context from '../src/context';
@@ -166,30 +165,6 @@ describe('asyncForEach', () => {
166165
});
167166
});
168167

169-
describe('setOutput', () => {
170-
beforeEach(() => {
171-
process.stdout.write = jest.fn() as typeof process.stdout.write;
172-
});
173-
174-
// eslint-disable-next-line jest/expect-expect
175-
it('setOutput produces the correct command', () => {
176-
context.setOutput('some output', 'some value');
177-
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
178-
});
179-
180-
// eslint-disable-next-line jest/expect-expect
181-
it('setOutput handles bools', () => {
182-
context.setOutput('some output', false);
183-
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
184-
});
185-
186-
// eslint-disable-next-line jest/expect-expect
187-
it('setOutput handles numbers', () => {
188-
context.setOutput('some output', 1.01);
189-
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
190-
});
191-
});
192-
193168
// See: https://github.com/actions/toolkit/blob/master/packages/core/src/core.ts#L67
194169
function getInputName(name: string): string {
195170
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
@@ -198,11 +173,3 @@ function getInputName(name: string): string {
198173
function setInput(name: string, value: string): void {
199174
process.env[getInputName(name)] = value;
200175
}
201-
202-
// Assert that process.stdout.write calls called only with the given arguments.
203-
function assertWriteCalls(calls: string[]): void {
204-
expect(process.stdout.write).toHaveBeenCalledTimes(calls.length);
205-
for (let i = 0; i < calls.length; i++) {
206-
expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]);
207-
}
208-
}

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {parse} from 'csv-parse/sync';
2-
import * as core from '@actions/core';
3-
import {issueCommand} from '@actions/core/lib/command';
41
import * as fs from 'fs';
52
import * as os from 'os';
63
import * as path from 'path';
4+
import * as core from '@actions/core';
5+
import {parse} from 'csv-parse/sync';
76

87
let _tmpDir: string;
98

@@ -73,8 +72,3 @@ export const asyncForEach = async (array, callback) => {
7372
await callback(array[index], index, array);
7473
}
7574
};
76-
77-
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
78-
export function setOutput(name: string, value: unknown): void {
79-
issueCommand('set-output', {name}, value);
80-
}

src/main.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs';
2-
import {getInputs, Inputs, setOutput} from './context';
2+
import {getInputs, Inputs} from './context';
33
import * as github from './github';
44
import {Meta, Version} from './meta';
55
import * as core from '@actions/core';
@@ -41,7 +41,7 @@ async function run() {
4141
core.info(version.main || '');
4242
core.endGroup();
4343
}
44-
setOutput('version', version.main || '');
44+
core.setOutput('version', version.main || '');
4545

4646
// Docker tags
4747
const tags: Array<string> = meta.getTags();
@@ -54,7 +54,7 @@ async function run() {
5454
}
5555
core.endGroup();
5656
}
57-
setOutput('tags', tags.join(inputs.sepTags));
57+
core.setOutput('tags', tags.join(inputs.sepTags));
5858

5959
// Docker labels
6060
const labels: Array<string> = meta.getLabels();
@@ -63,21 +63,21 @@ async function run() {
6363
core.info(label);
6464
}
6565
core.endGroup();
66-
setOutput('labels', labels.join(inputs.sepLabels));
66+
core.setOutput('labels', labels.join(inputs.sepLabels));
6767

6868
// JSON
6969
const jsonOutput = meta.getJSON();
7070
core.startGroup(`JSON output`);
7171
core.info(JSON.stringify(jsonOutput, null, 2));
7272
core.endGroup();
73-
setOutput('json', jsonOutput);
73+
core.setOutput('json', jsonOutput);
7474

7575
// Bake file definition
7676
const bakeFile: string = meta.getBakeFile();
7777
core.startGroup(`Bake file definition`);
7878
core.info(fs.readFileSync(bakeFile, 'utf8'));
7979
core.endGroup();
80-
setOutput('bake-file', bakeFile);
80+
core.setOutput('bake-file', bakeFile);
8181
} catch (error) {
8282
core.setFailed(error.message);
8383
}

0 commit comments

Comments
 (0)