added scaffolder-common package with beta3 entity definitions

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: blam <ben@blam.sh>
Co-authored-by: Johan Haals <johan.haals@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-10-05 13:28:33 +02:00
parent 9faf634497
commit 445d222a48
7 changed files with 457 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('@backstage/cli/config/eslint.backend')],
};
+3
View File
@@ -0,0 +1,3 @@
# @backstage/plugin-scaffolder-common
Common types and functionalities for the scaffolder, to be shared between scaffolder and scaffolder-backend.
+44
View File
@@ -0,0 +1,44 @@
{
"name": "@backstage/plugin-scaffolder-common",
"description": "Common functionalities for the scaffolder, to be shared between scaffolder and scaffolder-backend plugin",
"version": "0.1.0",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
"types": "dist/index.d.ts"
},
"homepage": "https://backstage.io",
"repository": {
"type": "git",
"url": "https://github.com/backstage/backstage",
"directory": "plugin/scaffolder-common"
},
"keywords": [
"techdocs",
"scaffolder"
],
"files": [
"dist"
],
"scripts": {
"build": "backstage-cli build",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"prepack": "backstage-cli prepack",
"postpack": "backstage-cli postpack",
"clean": "backstage-cli clean"
},
"bugs": {
"url": "https://github.com/backstage/backstage/issues"
},
"dependencies": {
"@backstage/catalog-model": "^0.9.3",
"@backstage/config": "^0.1.10"
},
"devDependencies": {
"@backstage/cli": "^0.7.13"
}
}
@@ -0,0 +1,186 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "TemplateV1beta3",
"description": "A Template describes a scaffolding task for use with the Scaffolder. It describes the required parameters as well as a series of steps that will be taken to execute the scaffolding task.",
"examples": [
{
"apiVersion": "templates.backstage.io/v1beta3",
"kind": "Template",
"metadata": {
"name": "react-ssr-template",
"title": "React SSR Template",
"description": "Next.js application skeleton for creating isomorphic web applications.",
"tags": ["recommended", "react"]
},
"spec": {
"owner": "artist-relations-team",
"parameters": {
"required": ["name", "description", "repoUrl"],
"properties": {
"name": {
"title": "Name",
"type": "string",
"description": "Unique name of the component"
},
"description": {
"title": "Description",
"type": "string",
"description": "Description of the component"
},
"repoUrl": {
"title": "Pick a repository",
"type": "string",
"ui:field": "RepoUrlPicker"
}
}
},
"steps": [
{
"id": "fetch",
"name": "Fetch",
"action": "fetch:plain",
"parameters": {
"url": "./template"
}
},
{
"id": "publish",
"name": "Publish to GitHub",
"action": "publish:github",
"parameters": {
"repoUrl": "${{ parameters.repoUrl }}"
},
"if": "${{ parameters.repoUrl }}"
}
],
"output": {
"catalogInfoUrl": "${{ steps.publish.output.catalogInfoUrl }}"
}
}
}
],
"allOf": [
{
"$ref": "Entity"
},
{
"type": "object",
"required": ["spec"],
"properties": {
"apiVersion": {
"enum": ["templates.backstage.io/v1beta3"]
},
"kind": {
"enum": ["Template"]
},
"spec": {
"type": "object",
"required": ["type", "steps"],
"properties": {
"type": {
"type": "string",
"description": "The type of component created by the template. The software catalog accepts any type value, but an organization should take great care to establish a proper taxonomy for these. Tools including Backstage itself may read this field and behave differently depending on its value. For example, a website type component may present tooling in the Backstage interface that is specific to just websites.",
"examples": ["service", "website", "library"],
"minLength": 1
},
"parameters": {
"oneOf": [
{
"type": "object",
"description": "The JSONSchema describing the inputs for the template."
},
{
"type": "array",
"description": "A list of separate forms to collect parameters.",
"items": {
"type": "object",
"description": "The JSONSchema describing the inputs for the template."
}
}
]
},
"steps": {
"type": "array",
"description": "A list of steps to execute.",
"items": {
"type": "object",
"description": "A description of the step to execute.",
"required": ["action"],
"properties": {
"id": {
"type": "string",
"description": "The ID of the step, which can be used to refer to its outputs."
},
"name": {
"type": "string",
"description": "The name of the step, which will be displayed in the UI during the scaffolding process."
},
"action": {
"type": "string",
"description": "The name of the action to execute."
},
"input": {
"type": "object",
"description": "A templated object describing the inputs to the action."
},
"if": {
"type": ["string", "boolean"],
"description": "A templated condition that skips the step when evaluated to false. If the condition is true or not defined, the step is executed. The condition is true, if the input is not `false`, `undefined`, `null`, `\"\"`, `0`, or `[]`."
}
}
}
},
"output": {
"type": "object",
"description": "A templated object describing the outputs of the scaffolding task.",
"properties": {
"links": {
"type": "array",
"description": "A list of external hyperlinks, typically pointing to resources created or updated by the template",
"items": {
"type": "object",
"required": [],
"properties": {
"url": {
"type": "string",
"description": "A url in a standard uri format.",
"examples": ["https://github.com/my-org/my-new-repo"],
"minLength": 1
},
"entityRef": {
"type": "string",
"description": "An entity reference to an entity in the catalog.",
"examples": ["Component:default/my-app"],
"minLength": 1
},
"title": {
"type": "string",
"description": "A user friendly display name for the link.",
"examples": ["View new repo"],
"minLength": 1
},
"icon": {
"type": "string",
"description": "A key representing a visual icon to be displayed in the UI.",
"examples": ["dashboard"],
"minLength": 1
}
}
}
}
},
"additionalProperties": {
"type": "string"
}
},
"owner": {
"type": "string",
"description": "The user (or group) owner of the template",
"minLength": 1
}
}
}
}
}
]
}
@@ -0,0 +1,157 @@
/*
* 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 { entityKindSchemaValidator } from '@backstage/catalog-model';
import type { TemplateEntityV1beta3 } from './TemplateEntityV1beta3';
import schema from './Template.v1beta3.schema.json';
const validator = entityKindSchemaValidator(schema);
describe('templateEntityV1beta3Validator', () => {
let entity: TemplateEntityV1beta3;
beforeEach(() => {
entity = {
apiVersion: 'templates.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 () => {
expect(validator(entity)).toBe(entity);
});
it('ignores unknown apiVersion', async () => {
(entity as any).apiVersion = 'backstage.io/v1beta0';
expect(validator(entity)).toBe(false);
});
it('ignores unknown kind', async () => {
(entity as any).kind = 'Wizard';
expect(validator(entity)).toBe(false);
});
it('rejects missing type', async () => {
delete (entity as any).spec.type;
expect(() => validator(entity)).toThrow(/type/);
});
it('accepts any other type', async () => {
(entity as any).spec.type = 'hallo';
expect(validator(entity)).toBe(entity);
});
it('accepts missing parameters', async () => {
delete (entity as any).spec.parameters;
expect(validator(entity)).toBe(entity);
});
it('accepts missing outputs', async () => {
delete (entity as any).spec.outputs;
expect(validator(entity)).toBe(entity);
});
it('rejects empty type', async () => {
(entity as any).spec.type = '';
expect(() => validator(entity)).toThrow(/type/);
});
it('rejects missing steps', async () => {
delete (entity as any).spec.steps;
expect(() => validator(entity)).toThrow(/steps/);
});
it('accepts step with missing id', async () => {
delete (entity as any).spec.steps[0].id;
expect(validator(entity)).toBe(entity);
});
it('accepts step with missing name', async () => {
delete (entity as any).spec.steps[0].name;
expect(validator(entity)).toBe(entity);
});
it('rejects step with missing action', async () => {
delete (entity as any).spec.steps[0].action;
expect(() => validator(entity)).toThrow(/action/);
});
it('accepts missing owner', async () => {
delete (entity as any).spec.owner;
expect(validator(entity)).toBe(entity);
});
it('rejects empty owner', async () => {
(entity as any).spec.owner = '';
expect(() => validator(entity)).toThrow(/owner/);
});
it('rejects wrong type owner', async () => {
(entity as any).spec.owner = 5;
expect(() => validator(entity)).toThrow(/owner/);
});
it('accepts missing if', async () => {
delete (entity as any).spec.steps[0].if;
expect(validator(entity)).toBe(entity);
});
it('accepts boolean in if', async () => {
(entity as any).spec.steps[0].if = true;
expect(validator(entity)).toBe(entity);
});
it('accepts empty if', async () => {
(entity as any).spec.steps[0].if = '';
expect(validator(entity)).toBe(entity);
});
it('rejects wrong type if', async () => {
(entity as any).spec.steps[0].if = 5;
expect(() => validator(entity)).toThrow(/if/);
});
});
@@ -0,0 +1,37 @@
/*
* 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 { Entity } from '@backstage/catalog-model';
/** @public */
export interface TemplateEntityV1beta3 extends Entity {
apiVersion: 'templates.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;
};
}
+27
View File
@@ -0,0 +1,27 @@
/*
* 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.
*/
/**
* Common functionalities for the scaffolder, to be shared between scaffolder and scaffolder-backend plugin
*
* @packageDocumentation
*/
// The `{ default as ...}` re-export does not seem to work for json in tests
import templateEntityV1beta3Schema from './Template.v1beta3.schema.json';
export type { TemplateEntityV1beta3 } from './TemplateEntityV1beta3';
export { templateEntityV1beta3Schema };