From 17d7f5bc57dfb5d57db11927694de2d6dfcb9f25 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 11 Oct 2021 14:51:43 +0200 Subject: [PATCH] feat: removing the older stuff and updating to work with the new common packages Signed-off-by: blam --- .../src/kinds/TemplateEntityV1beta3.test.ts | 156 ------------------ .../src/kinds/TemplateEntityV1beta3.ts | 43 ----- .../tasks/DefaultWorkflowRunner.test.ts | 26 +-- .../scaffolder/tasks/DefaultWorkflowRunner.ts | 2 +- .../src/scaffolder/tasks/TaskWorker.test.ts | 4 +- .../src/scaffolder/tasks/TaskWorker.ts | 2 +- 6 files changed, 17 insertions(+), 216 deletions(-) delete mode 100644 packages/catalog-model/src/kinds/TemplateEntityV1beta3.test.ts delete mode 100644 packages/catalog-model/src/kinds/TemplateEntityV1beta3.ts diff --git a/packages/catalog-model/src/kinds/TemplateEntityV1beta3.test.ts b/packages/catalog-model/src/kinds/TemplateEntityV1beta3.test.ts deleted file mode 100644 index cc275435e8..0000000000 --- a/packages/catalog-model/src/kinds/TemplateEntityV1beta3.test.ts +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - TemplateEntityV1beta3, - templateEntityV1beta3Validator as validator, -} from './TemplateEntityV1beta3'; - -describe('templateEntityV1beta3Validator', () => { - let entity: TemplateEntityV1beta3; - - beforeEach(() => { - entity = { - apiVersion: 'backstage.io/v1beta3', - kind: 'Template', - metadata: { - name: 'test', - }, - spec: { - type: 'website', - parameters: { - required: ['storePath', 'owner'], - properties: { - owner: { - type: 'string', - title: 'Owner', - description: 'Who is going to own this component', - }, - }, - }, - steps: [ - { - id: 'fetch', - name: 'Fetch', - action: 'fetch:plan', - input: { - url: './template', - }, - if: '${{ parameters.owner }}', - }, - ], - output: { - fetchUrl: '${{ steps.fetch.output.targetUrl }}', - }, - owner: 'team-b@example.com', - }, - }; - }); - - it('happy path: accepts valid data', async () => { - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('ignores unknown apiVersion', async () => { - (entity as any).apiVersion = 'backstage.io/v1beta0'; - await expect(validator.check(entity)).resolves.toBe(false); - }); - - it('ignores unknown kind', async () => { - (entity as any).kind = 'Wizard'; - await expect(validator.check(entity)).resolves.toBe(false); - }); - - it('rejects missing type', async () => { - delete (entity as any).spec.type; - await expect(validator.check(entity)).rejects.toThrow(/type/); - }); - - it('accepts any other type', async () => { - (entity as any).spec.type = 'hallo'; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts missing parameters', async () => { - delete (entity as any).spec.parameters; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts missing outputs', async () => { - delete (entity as any).spec.outputs; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects empty type', async () => { - (entity as any).spec.type = ''; - await expect(validator.check(entity)).rejects.toThrow(/type/); - }); - - it('rejects missing steps', async () => { - delete (entity as any).spec.steps; - await expect(validator.check(entity)).rejects.toThrow(/steps/); - }); - - it('accepts step with missing id', async () => { - delete (entity as any).spec.steps[0].id; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts step with missing name', async () => { - delete (entity as any).spec.steps[0].name; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects step with missing action', async () => { - delete (entity as any).spec.steps[0].action; - await expect(validator.check(entity)).rejects.toThrow(/action/); - }); - - it('accepts missing owner', async () => { - delete (entity as any).spec.owner; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects empty owner', async () => { - (entity as any).spec.owner = ''; - await expect(validator.check(entity)).rejects.toThrow(/owner/); - }); - - it('rejects wrong type owner', async () => { - (entity as any).spec.owner = 5; - await expect(validator.check(entity)).rejects.toThrow(/owner/); - }); - - it('accepts missing if', async () => { - delete (entity as any).spec.steps[0].if; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts boolean in if', async () => { - (entity as any).spec.steps[0].if = true; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('accepts empty if', async () => { - (entity as any).spec.steps[0].if = ''; - await expect(validator.check(entity)).resolves.toBe(true); - }); - - it('rejects wrong type if', async () => { - (entity as any).spec.steps[0].if = 5; - await expect(validator.check(entity)).rejects.toThrow(/if/); - }); -}); diff --git a/packages/catalog-model/src/kinds/TemplateEntityV1beta3.ts b/packages/catalog-model/src/kinds/TemplateEntityV1beta3.ts deleted file mode 100644 index 2da9a0b6b8..0000000000 --- a/packages/catalog-model/src/kinds/TemplateEntityV1beta3.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { JsonObject } from '@backstage/config'; -import type { Entity } from '../entity/Entity'; -import schema from '../schema/kinds/Template.v1beta3.schema.json'; -import { ajvCompiledJsonSchemaValidator } from './util'; - -/** @public */ -export interface TemplateEntityV1beta3 extends Entity { - apiVersion: 'backstage.io/v1beta3'; - kind: 'Template'; - spec: { - type: string; - parameters?: JsonObject | JsonObject[]; - steps: Array<{ - id?: string; - name?: string; - action: string; - input?: JsonObject; - if?: string | boolean; - }>; - output?: { [name: string]: string }; - owner?: string; - }; -} - -/** @public */ -export const templateEntityV1beta3Validator = - ajvCompiledJsonSchemaValidator(schema); diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.test.ts index 542cbb4b2f..3ecdd6dcd8 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.test.ts @@ -91,7 +91,7 @@ describe('DefaultWorkflowRunner', () => { it('should throw an error if the action does not exist', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', parameters: {}, output: {}, steps: [{ id: 'test', name: 'name', action: 'does-not-exist' }], @@ -105,7 +105,7 @@ describe('DefaultWorkflowRunner', () => { describe('validation', () => { it('should throw an error if the action has a schema and the input does not match', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', parameters: {}, output: {}, steps: [{ id: 'test', name: 'name', action: 'jest-validated-action' }], @@ -118,7 +118,7 @@ describe('DefaultWorkflowRunner', () => { it('should run the action when the validation passes', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', parameters: {}, output: {}, steps: [ @@ -140,7 +140,7 @@ describe('DefaultWorkflowRunner', () => { describe('conditionals', () => { it('should execute steps conditionally', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', name: 'test', action: 'output-action' }, { @@ -163,7 +163,7 @@ describe('DefaultWorkflowRunner', () => { it('should skips steps conditionally', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', name: 'test', action: 'output-action' }, { @@ -186,7 +186,7 @@ describe('DefaultWorkflowRunner', () => { it('should skips steps using the negating equals operator', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', name: 'test', action: 'output-action' }, { @@ -211,7 +211,7 @@ describe('DefaultWorkflowRunner', () => { describe('templating', () => { it('should template the input to an action', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', @@ -237,7 +237,7 @@ describe('DefaultWorkflowRunner', () => { it('should keep the original types for the input and not parse things that arent meant to be parsed', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', @@ -265,7 +265,7 @@ describe('DefaultWorkflowRunner', () => { it('should template complex values into the action', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', @@ -291,7 +291,7 @@ describe('DefaultWorkflowRunner', () => { it('supports really complex structures', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', @@ -320,7 +320,7 @@ describe('DefaultWorkflowRunner', () => { it('supports numbers as first class too', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', @@ -349,7 +349,7 @@ describe('DefaultWorkflowRunner', () => { it('should template the output from simple actions', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', @@ -373,7 +373,7 @@ describe('DefaultWorkflowRunner', () => { describe('filters', () => { it('provides the parseRepoUrl filter', async () => { const task = createMockTaskWithSpec({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [ { id: 'test', diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.ts index 354092ee06..4a94b9bf73 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/DefaultWorkflowRunner.ts @@ -49,7 +49,7 @@ type TemplateContext = { }; const isValidTaskSpec = (taskSpec: TaskSpec): taskSpec is TaskSpecV1beta3 => { - return taskSpec.apiVersion === 'backstage.io/v1beta3'; + return taskSpec.apiVersion === 'scaffolder.backstage.io/v1beta3'; }; const createStepLogger = ({ task, step }: { task: Task; step: TaskStep }) => { diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts index 035398d448..87a0229b5d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.test.ts @@ -92,7 +92,7 @@ describe('TaskWorker', () => { }); await broker.dispatch({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [{ id: 'test', name: 'test', action: 'not-found-action' }], output: { result: '{{ steps.test.output.testOutput }}', @@ -121,7 +121,7 @@ describe('TaskWorker', () => { }); const { taskId } = await broker.dispatch({ - apiVersion: 'backstage.io/v1beta3', + apiVersion: 'scaffolder.backstage.io/v1beta3', steps: [{ id: 'test', name: 'test', action: 'not-found-action' }], output: { result: '{{ steps.test.output.testOutput }}', diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts index 5b69ecc6df..7122c2fc3e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/TaskWorker.ts @@ -38,7 +38,7 @@ export class TaskWorker { async runOneTask(task: Task) { try { const { output } = - task.spec.apiVersion === 'backstage.io/v1beta3' + task.spec.apiVersion === 'scaffolder.backstage.io/v1beta3' ? await this.options.runners.workflowRunner.execute(task) : await this.options.runners.legacyWorkflowRunner.execute(task);