fix: remove logger from cookiecutter and rails
Signed-off-by: ElaineDeMattosSilvaB <elaine.de-mattos-silva-bezerra@deutschebahn.com>
This commit is contained in:
+3
-2
@@ -23,7 +23,7 @@ import type { ActionContext } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { join } from 'path';
|
||||
import { Logger } from 'winston';
|
||||
import { Writable } from 'stream';
|
||||
import { createFetchCookiecutterAction } from './cookiecutter';
|
||||
|
||||
const executeShellCommand = jest.fn();
|
||||
@@ -168,7 +168,7 @@ describe('fetch:cookiecutter', () => {
|
||||
join(mockTmpDir, 'template'),
|
||||
'--verbose',
|
||||
],
|
||||
logger: expect.any(Logger),
|
||||
logStream: expect.any(Writable),
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -189,6 +189,7 @@ describe('fetch:cookiecutter', () => {
|
||||
},
|
||||
workingDir: '/input',
|
||||
envVars: { HOME: '/tmp' },
|
||||
logStream: expect.any(Writable),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ import { JsonObject, JsonValue } from '@backstage/types';
|
||||
import commandExists from 'command-exists';
|
||||
import fs from 'fs-extra';
|
||||
import path, { resolve as resolvePath } from 'path';
|
||||
import { Logger } from 'winston';
|
||||
import { PassThrough, Writable } from 'stream';
|
||||
import { examples } from './cookiecutter.examples';
|
||||
|
||||
export class CookiecutterRunner {
|
||||
@@ -57,14 +57,14 @@ export class CookiecutterRunner {
|
||||
public async run({
|
||||
workspacePath,
|
||||
values,
|
||||
logger,
|
||||
logStream,
|
||||
imageName,
|
||||
templateDir,
|
||||
templateContentsDir,
|
||||
}: {
|
||||
workspacePath: string;
|
||||
values: JsonObject;
|
||||
logger: Logger;
|
||||
logStream: Writable;
|
||||
imageName?: string;
|
||||
templateDir: string;
|
||||
templateContentsDir: string;
|
||||
@@ -99,7 +99,7 @@ export class CookiecutterRunner {
|
||||
await executeShellCommand({
|
||||
command: 'cookiecutter',
|
||||
args: ['--no-input', '-o', intermediateDir, templateDir, '--verbose'],
|
||||
logger,
|
||||
logStream,
|
||||
});
|
||||
} else {
|
||||
if (this.containerRunner === undefined) {
|
||||
@@ -116,6 +116,7 @@ export class CookiecutterRunner {
|
||||
// Set the home directory inside the container as something that applications can
|
||||
// write to, otherwise they will just fail trying to write to /
|
||||
envVars: { HOME: '/tmp' },
|
||||
logStream,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -246,10 +247,15 @@ export function createFetchCookiecutterAction(options: {
|
||||
_extensions: ctx.input.extensions,
|
||||
};
|
||||
|
||||
const logStream = new PassThrough();
|
||||
logStream.on('data', chunk => {
|
||||
ctx.logger.info(chunk.toString());
|
||||
});
|
||||
|
||||
// Will execute the template in ./template and put the result in ./result
|
||||
await cookiecutter.run({
|
||||
workspacePath: workDir,
|
||||
logger: ctx.logger,
|
||||
logStream,
|
||||
values: values,
|
||||
imageName: ctx.input.imageName,
|
||||
templateDir: templateDir,
|
||||
|
||||
@@ -35,7 +35,7 @@ import { ScmIntegrations } from '@backstage/integration';
|
||||
import { fetchContents } from '@backstage/plugin-scaffolder-node';
|
||||
import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { Logger } from 'winston';
|
||||
import { Writable } from 'stream';
|
||||
import { createFetchRailsAction } from './index';
|
||||
|
||||
describe('fetch:rails', () => {
|
||||
@@ -106,7 +106,7 @@ describe('fetch:rails', () => {
|
||||
|
||||
expect(mockRailsTemplater.run).toHaveBeenCalledWith({
|
||||
workspacePath: mockContext.workspacePath,
|
||||
logger: expect.any(Logger),
|
||||
logStream: expect.any(Writable),
|
||||
values: mockContext.input.values,
|
||||
});
|
||||
});
|
||||
@@ -122,7 +122,7 @@ describe('fetch:rails', () => {
|
||||
|
||||
expect(mockRailsTemplater.run).toHaveBeenCalledWith({
|
||||
workspacePath: mockContext.workspacePath,
|
||||
logger: expect.any(Logger),
|
||||
logStream: expect.any(Writable),
|
||||
values: {
|
||||
...mockContext.input.values,
|
||||
imageName: 'foo/rails-custom-image',
|
||||
|
||||
@@ -26,6 +26,7 @@ import fs from 'fs-extra';
|
||||
|
||||
import { UrlReaderService } from '@backstage/backend-plugin-api';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { PassThrough } from 'stream';
|
||||
import { examples } from './index.examples';
|
||||
import { RailsNewRunner } from './railsNewRunner';
|
||||
|
||||
@@ -218,10 +219,15 @@ export function createFetchRailsAction(options: {
|
||||
throw new Error(`Image ${imageName} is not allowed`);
|
||||
}
|
||||
|
||||
const logStream = new PassThrough();
|
||||
logStream.on('data', chunk => {
|
||||
ctx.logger.info(chunk.toString());
|
||||
});
|
||||
|
||||
// Will execute the template in ./template and put the result in ./result
|
||||
await templateRunner.run({
|
||||
workspacePath: workDir,
|
||||
logger: ctx.logger,
|
||||
logStream,
|
||||
values: { ...ctx.input.values, imageName },
|
||||
});
|
||||
|
||||
|
||||
+20
-17
@@ -30,7 +30,7 @@ jest.mock(
|
||||
import { ContainerRunner } from '@backstage/backend-common';
|
||||
import { createMockDirectory } from '@backstage/backend-test-utils';
|
||||
import path from 'path';
|
||||
import { Logger } from 'winston';
|
||||
import { PassThrough } from 'stream';
|
||||
import { RailsNewRunner } from './railsNewRunner';
|
||||
|
||||
describe('Rails Templater', () => {
|
||||
@@ -47,7 +47,7 @@ describe('Rails Templater', () => {
|
||||
|
||||
describe('when running on docker', () => {
|
||||
it('should run the correct bindings for the volumes', async () => {
|
||||
const logger = new Logger();
|
||||
const logStream = new PassThrough();
|
||||
const values = {
|
||||
owner: 'angeliski',
|
||||
storePath: 'https://github.com/angeliski/rails-project',
|
||||
@@ -65,7 +65,7 @@ describe('Rails Templater', () => {
|
||||
await templater.run({
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logger,
|
||||
logStream,
|
||||
});
|
||||
|
||||
expect(containerRunner.runContainer).toHaveBeenCalledWith({
|
||||
@@ -78,11 +78,12 @@ describe('Rails Templater', () => {
|
||||
[path.join(mockDir.path, 'intermediate')]: '/output',
|
||||
},
|
||||
workingDir: '/input',
|
||||
logStream: logStream,
|
||||
});
|
||||
});
|
||||
|
||||
it('should use the provided imageName', async () => {
|
||||
const logger = new Logger();
|
||||
const logStream = new PassThrough();
|
||||
const values = {
|
||||
owner: 'angeliski',
|
||||
storePath: 'https://github.com/angeliski/rails-project',
|
||||
@@ -100,7 +101,7 @@ describe('Rails Templater', () => {
|
||||
await templater.run({
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logger,
|
||||
logStream,
|
||||
});
|
||||
|
||||
expect(containerRunner.runContainer).toHaveBeenCalledWith(
|
||||
@@ -111,7 +112,7 @@ describe('Rails Templater', () => {
|
||||
});
|
||||
|
||||
it('should pass through the streamer to the run docker helper', async () => {
|
||||
const logger = new Logger();
|
||||
const stream = new PassThrough();
|
||||
|
||||
const values = {
|
||||
owner: 'angeliski',
|
||||
@@ -130,7 +131,7 @@ describe('Rails Templater', () => {
|
||||
await templater.run({
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logger,
|
||||
logStream: stream,
|
||||
});
|
||||
|
||||
expect(containerRunner.runContainer).toHaveBeenCalledWith({
|
||||
@@ -143,11 +144,12 @@ describe('Rails Templater', () => {
|
||||
[path.join(mockDir.path, 'intermediate')]: '/output',
|
||||
},
|
||||
workingDir: '/input',
|
||||
logStream: stream,
|
||||
});
|
||||
});
|
||||
|
||||
it('update the template path to correct location', async () => {
|
||||
const logger = new Logger();
|
||||
const logStream = new PassThrough();
|
||||
const values = {
|
||||
owner: 'angeliski',
|
||||
storePath: 'https://github.com/angeliski/rails-project',
|
||||
@@ -166,7 +168,7 @@ describe('Rails Templater', () => {
|
||||
await templater.run({
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logger,
|
||||
logStream,
|
||||
});
|
||||
|
||||
expect(containerRunner.runContainer).toHaveBeenCalledWith({
|
||||
@@ -184,13 +186,14 @@ describe('Rails Templater', () => {
|
||||
[path.join(mockDir.path, 'intermediate')]: '/output',
|
||||
},
|
||||
workingDir: '/input',
|
||||
logStream: logStream,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when rails is available', () => {
|
||||
it('use the binary', async () => {
|
||||
const logger = new Logger();
|
||||
const stream = new PassThrough();
|
||||
|
||||
const values = {
|
||||
owner: 'angeliski',
|
||||
@@ -210,7 +213,7 @@ describe('Rails Templater', () => {
|
||||
await templater.run({
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logger,
|
||||
logStream: stream,
|
||||
});
|
||||
|
||||
expect(executeShellCommand).toHaveBeenCalledWith({
|
||||
@@ -219,12 +222,12 @@ describe('Rails Templater', () => {
|
||||
'new',
|
||||
path.join(mockDir.path, 'intermediate', 'rails-project'),
|
||||
]),
|
||||
logger,
|
||||
logStream: stream,
|
||||
});
|
||||
});
|
||||
|
||||
it('update the template path to correct location', async () => {
|
||||
const logger = new Logger();
|
||||
const stream = new PassThrough();
|
||||
|
||||
const values = {
|
||||
owner: 'angeliski',
|
||||
@@ -245,7 +248,7 @@ describe('Rails Templater', () => {
|
||||
await templater.run({
|
||||
workspacePath: mockDir.path,
|
||||
values,
|
||||
logger,
|
||||
logStream: stream,
|
||||
});
|
||||
|
||||
expect(executeShellCommand).toHaveBeenCalledWith({
|
||||
@@ -256,14 +259,14 @@ describe('Rails Templater', () => {
|
||||
'--template',
|
||||
path.join(mockDir.path, './something.rb'),
|
||||
]),
|
||||
logger,
|
||||
logStream: stream,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when nothing was generated', () => {
|
||||
it('throws an error', async () => {
|
||||
const logger = new Logger();
|
||||
const stream = new PassThrough();
|
||||
|
||||
mockDir.setContent({
|
||||
intermediate: {},
|
||||
@@ -279,7 +282,7 @@ describe('Rails Templater', () => {
|
||||
name: 'rails-project',
|
||||
imageName: 'foo/rails-custom-image',
|
||||
},
|
||||
logger,
|
||||
logStream: stream,
|
||||
}),
|
||||
).rejects.toThrow(/No data generated by rails/);
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ import { JsonObject } from '@backstage/types';
|
||||
import commandExists from 'command-exists';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { Logger } from 'winston';
|
||||
import { Writable } from 'stream';
|
||||
import {
|
||||
railsArgumentResolver,
|
||||
RailsRunOptions,
|
||||
@@ -36,11 +36,11 @@ export class RailsNewRunner {
|
||||
public async run({
|
||||
workspacePath,
|
||||
values,
|
||||
logger,
|
||||
logStream,
|
||||
}: {
|
||||
workspacePath: string;
|
||||
values: JsonObject;
|
||||
logger: Logger;
|
||||
logStream: Writable;
|
||||
}): Promise<void> {
|
||||
const intermediateDir = path.join(workspacePath, 'intermediate');
|
||||
await fs.ensureDir(intermediateDir);
|
||||
@@ -71,7 +71,7 @@ export class RailsNewRunner {
|
||||
`${intermediateDir}${path.sep}${name}`,
|
||||
...arrayExtraArguments,
|
||||
],
|
||||
logger,
|
||||
logStream,
|
||||
});
|
||||
} else {
|
||||
if (!imageName) {
|
||||
@@ -96,6 +96,7 @@ export class RailsNewRunner {
|
||||
// Set the home directory inside the container as something that applications can
|
||||
// write to, otherwise they will just fail trying to write to /
|
||||
envVars: { HOME: '/tmp' },
|
||||
logStream,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user