Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[steps] Do not print warning about non-defined outputs in step #501

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions packages/steps/src/BuildStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,31 +432,20 @@ export class BuildStep extends BuildStepOutputAccessor {
private async collectAndValidateOutputsAsync(outputsDir: string): Promise<void> {
const files = await fs.readdir(outputsDir);

const nonDefinedOutputIds: string[] = [];
for (const outputId of files) {
if (!(outputId in this.outputById)) {
nonDefinedOutputIds.push(outputId);
const newOutput = new BuildStepOutput(this.ctx.global, {
id: outputId,
stepDisplayName: this.displayName,
required: false,
});
const file = path.join(outputsDir, outputId);
const rawContents = await fs.readFile(file, 'utf-8');
const value = rawContents.trim();
newOutput.set(value);
this.outputById[outputId] = newOutput;
} else {
const file = path.join(outputsDir, outputId);
const rawContents = await fs.readFile(file, 'utf-8');
const value = rawContents.trim();
this.outputById[outputId].set(value);
}
}

if (nonDefinedOutputIds.length > 0) {
const idsString = nonDefinedOutputIds.map((i) => `"${i}"`).join(', ');
this.ctx.logger.warn(`Some outputs are not defined in step config: ${idsString}`);
const file = path.join(outputsDir, outputId);
const rawContents = await fs.readFile(file, 'utf-8');
const value = rawContents.trim();
this.outputById[outputId].set(value);
}

const nonSetRequiredOutputIds: string[] = [];
Expand Down
24 changes: 0 additions & 24 deletions packages/steps/src/__tests__/BuildStep-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,30 +480,6 @@ describe(BuildStep, () => {
expect(abc?.value).toBe('d o m i n i k');
});

it('prints a warning if some of the outputs set with set-output are not defined in step config', async () => {
const logger = createMockLogger();
const warnLines: string[] = [];
jest.mocked(logger.warn as any).mockImplementation((line: string) => {
warnLines.push(line);
});
jest.mocked(logger.child).mockReturnValue(logger);

(baseStepCtx as any).baseLogger = logger;

const id = 'test1';
const command = 'set-output abc 123';
const displayName = BuildStep.getDisplayName({ id, command });

const step = new BuildStep(baseStepCtx, {
id,
command,
displayName,
});
await step.executeAsync();
const found = warnLines.find((l) => l.match(/Some outputs are not defined in step config/));
expect(found).not.toBeUndefined();
});

it('throws an error if some required outputs have not been set with set-output in script', async () => {
const id = 'test1';
const command = 'echo 123';
Expand Down
Loading