scaffolder-backend: implemented beta1 task spec translation
Co-authored-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TemplateEntityV1alpha1 } from '@backstage/catalog-model';
|
||||
import { TemplateEntity } from '@backstage/catalog-model';
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { ConflictError, NotFoundError } from '@backstage/backend-common';
|
||||
|
||||
@@ -32,7 +32,7 @@ export class CatalogEntityClient {
|
||||
async findTemplate(
|
||||
templateName: string,
|
||||
options?: { token?: string },
|
||||
): Promise<TemplateEntityV1alpha1> {
|
||||
): Promise<TemplateEntity> {
|
||||
const { items: templates } = (await this.catalogClient.getEntities(
|
||||
{
|
||||
filter: {
|
||||
@@ -41,7 +41,7 @@ export class CatalogEntityClient {
|
||||
},
|
||||
},
|
||||
options,
|
||||
)) as { items: TemplateEntityV1alpha1[] };
|
||||
)) as { items: TemplateEntity[] };
|
||||
|
||||
if (templates.length !== 1) {
|
||||
if (templates.length > 1) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import { PassThrough } from 'stream';
|
||||
import { Logger } from 'winston';
|
||||
import * as winston from 'winston';
|
||||
import { JsonValue } from '@backstage/config';
|
||||
import { JsonValue, JsonObject } from '@backstage/config';
|
||||
import { TaskBroker, Task } from './types';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
@@ -57,10 +57,11 @@ export class TaskWorker {
|
||||
);
|
||||
|
||||
const templateCtx: {
|
||||
parameters: JsonObject;
|
||||
steps: {
|
||||
[stepName: string]: { output: { [outputName: string]: JsonValue } };
|
||||
};
|
||||
} = { steps: {} };
|
||||
} = { parameters: task.spec.values, steps: {} };
|
||||
|
||||
for (const step of task.spec.steps) {
|
||||
const metadata = { stepId: step.id };
|
||||
|
||||
@@ -86,6 +86,7 @@ export function templateEntityToSpec(
|
||||
});
|
||||
|
||||
return {
|
||||
values: {},
|
||||
steps,
|
||||
output: {
|
||||
remoteUrl: '{{ steps.publish.output.remoteUrl }}',
|
||||
|
||||
@@ -43,6 +43,7 @@ export type DbTaskEventRow = {
|
||||
};
|
||||
|
||||
export type TaskSpec = {
|
||||
values: JsonObject;
|
||||
steps: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
@@ -45,6 +45,7 @@ import {
|
||||
import { registerLegacyActions } from '../scaffolder/stages/legacy';
|
||||
import { getWorkingDirectory } from './helpers';
|
||||
import {
|
||||
InputError,
|
||||
NotFoundError,
|
||||
PluginDatabaseManager,
|
||||
} from '@backstage/backend-common';
|
||||
@@ -250,7 +251,25 @@ export async function createRouter(
|
||||
res.status(400).json({ errors: validationResult.errors });
|
||||
return;
|
||||
}
|
||||
const taskSpec = templateEntityToSpec(template, values);
|
||||
|
||||
let taskSpec;
|
||||
if (template.apiVersion === 'backstage.io/v1alpha1') {
|
||||
taskSpec = templateEntityToSpec(template, values);
|
||||
} else if (template.apiVersion === 'backstage.io/v1beta1') {
|
||||
// TODO: add v1beta1 type
|
||||
// const betaTemplate = template as TemplateEntityV1beta1
|
||||
const betaTemplate = template as any;
|
||||
taskSpec = {
|
||||
values,
|
||||
steps: betaTemplate.spec.steps,
|
||||
output: betaTemplate.spec.output,
|
||||
};
|
||||
} else {
|
||||
throw new InputError(
|
||||
`Unknown apiVersion field in schema entity, ${template.apiVersion}`,
|
||||
);
|
||||
}
|
||||
|
||||
const result = await taskBroker.dispatch(taskSpec);
|
||||
|
||||
res.status(201).json({ id: result.taskId });
|
||||
|
||||
Reference in New Issue
Block a user