chore: move to templateInfo in the scaffolder-backend

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-02-16 14:50:16 +01:00
parent 32f1cc6d46
commit b344cd674a
8 changed files with 18 additions and 12 deletions
@@ -59,7 +59,7 @@ export function createFetchPlainAction(options: {
await fetchContents({
reader,
integrations,
baseUrl: ctx.baseUrl,
baseUrl: ctx.templateInfo?.baseUrl,
fetchUrl: ctx.input.url,
outputPath,
});
@@ -75,7 +75,7 @@ describe('fetch:template', () => {
const logger = getVoidLogger();
const mockContext = (inputPatch: Partial<FetchTemplateInput> = {}) => ({
baseUrl: 'base-url',
templateInfo: { baseUrl: 'base-url', name: 'test' },
input: {
url: './skeleton',
targetPath: './target',
@@ -135,7 +135,7 @@ export function createFetchTemplateAction(options: {
await fetchContents({
reader,
integrations,
baseUrl: ctx.baseUrl,
baseUrl: ctx.templateInfo?.baseUrl,
fetchUrl: ctx.input.url,
outputPath: templateDir,
});
@@ -19,10 +19,12 @@ import { Writable } from 'stream';
import { JsonValue, JsonObject } from '@backstage/types';
import { Schema } from 'jsonschema';
import { TaskSecrets, TemplateMetadata } from '../tasks/types';
import { TemplateInfo } from '@backstage/plugin-scaffolder-common';
export type ActionContext<Input extends JsonObject> = {
/**
* Base URL for the location of the task spec, typically the url of the source entity file.
* @deprecated please use templateInfo.baseUrl instead
*/
baseUrl?: string;
@@ -38,7 +40,11 @@ export type ActionContext<Input extends JsonObject> = {
*/
createTemporaryDirectory(): Promise<string>;
/**
* @deprecated please use templateInfo instead
*/
metadata?: TemplateMetadata;
templateInfo?: TemplateInfo;
};
export type TemplateAction<Input extends JsonObject> = {
@@ -107,7 +107,7 @@ describe('LegacyWorkflowRunner', () => {
],
output: {},
values: {},
metadata: { name: templateName },
templateInfo: { name: templateName },
});
await runner.execute(task);
@@ -225,13 +225,8 @@ export class HandlebarsWorkflowRunner implements WorkflowRunner {
input: JSON.stringify(input, null, 2),
});
if (!task.spec.metadata) {
console.warn(
'DEPRECATION NOTICE: metadata is undefined. metadata will be required in the future.',
);
}
await action.handler({
// deprecated in favor of templateInfo.baseUrl
baseUrl: task.spec.baseUrl,
logger: taskLogger,
logStream: stream,
@@ -248,7 +243,9 @@ export class HandlebarsWorkflowRunner implements WorkflowRunner {
output(name: string, value: JsonValue) {
stepOutputs[name] = value;
},
metadata: task.spec.metadata,
// deprecated in favor of templateInfo
metadata: task.spec.templateInfo,
templateInfo: task.spec.templateInfo,
});
// Remove all temporary directories that were created when executing the action
@@ -176,7 +176,7 @@ describe('DefaultWorkflowRunner', () => {
input: { foo: 1 },
},
],
metadata: { name: templateName },
templateInfo: { name: templateName },
});
await runner.execute(task);
@@ -259,6 +259,7 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
const stepOutput: { [outputName: string]: JsonValue } = {};
await action.handler({
// deprecated in favourof templateInfo.baseUrl
baseUrl: task.spec.baseUrl,
input,
secrets: task.secrets ?? {},
@@ -275,7 +276,9 @@ export class NunjucksWorkflowRunner implements WorkflowRunner {
output(name: string, value: JsonValue) {
stepOutput[name] = value;
},
// deprecated in favour of templateInfo
metadata: task.spec.metadata,
templateInfo: task.spec.templateInfo,
});
// Remove all temporary directories that were created when executing the action