Skip to content

Commit

Permalink
move TemplateEntityV1beta2 from @backstage/catalog-model to `@bac…
Browse files Browse the repository at this point in the history
…kstage/plugin-scaffolder-common`

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
  • Loading branch information
freben committed Feb 16, 2022
1 parent d7868b4 commit e72d371
Show file tree
Hide file tree
Showing 27 changed files with 155 additions and 79 deletions.
8 changes: 8 additions & 0 deletions .changeset/beige-cherries-knock.md
@@ -0,0 +1,8 @@
---
'@backstage/plugin-scaffolder-common': patch
---

Added `TemplateEntityV1beta2` which was moved here from
`@backstage/plugin-scaffolder-common`. It has also been marked as deprecated in
the process - please consider [migrating to `v1beta3`
templates](https://backstage.io/docs/features/software-templates/migrating-from-v1beta2-to-v1beta3).
9 changes: 9 additions & 0 deletions .changeset/modern-mayflies-join.md
@@ -0,0 +1,9 @@
---
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-catalog-react': patch
'@backstage/plugin-scaffolder': patch
'@backstage/plugin-scaffolder-backend': patch
---

Use `TemplateEntityV1beta2` from `@backstage/plugin-scaffolder-common` instead
of `@backstage/catalog-model`.
8 changes: 8 additions & 0 deletions .changeset/smart-rivers-reflect.md
@@ -0,0 +1,8 @@
---
'@backstage/catalog-model': minor
---

**BREAKING**: Removed `TemplateEntityV1beta2` from the model and moved it to
`@backstage/plugin-scaffolder-common` where `TemplateEntityV1beta3` already
lived. It has also been marked as deprecated in the process - please consider
[migrating to `v1beta3` templates](https://backstage.io/docs/features/software-templates/migrating-from-v1beta2-to-v1beta3).
27 changes: 0 additions & 27 deletions packages/catalog-model/api-report.md
Expand Up @@ -558,33 +558,6 @@ export { SystemEntityV1alpha1 };
// @public
export const systemEntityV1alpha1Validator: KindValidator;

// @public
export interface TemplateEntityV1beta2 extends Entity {
// (undocumented)
apiVersion: 'backstage.io/v1beta2';
// (undocumented)
kind: 'Template';
// (undocumented)
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 templateEntityV1beta2Validator: KindValidator;

// @public
interface UserEntityV1alpha1 extends Entity {
// (undocumented)
Expand Down
2 changes: 0 additions & 2 deletions packages/catalog-model/src/kinds/index.ts
Expand Up @@ -50,8 +50,6 @@ export type {
SystemEntityV1alpha1 as SystemEntity,
SystemEntityV1alpha1,
} from './SystemEntityV1alpha1';
export { templateEntityV1beta2Validator } from './TemplateEntityV1beta2';
export type { TemplateEntityV1beta2 } from './TemplateEntityV1beta2';
export type { KindValidator } from './types';
export { userEntityV1alpha1Validator } from './UserEntityV1alpha1';
export type {
Expand Down
1 change: 1 addition & 0 deletions plugins/catalog-backend/package.json
Expand Up @@ -39,6 +39,7 @@
"@backstage/plugin-catalog-common": "^0.1.2",
"@backstage/plugin-permission-common": "^0.4.0",
"@backstage/plugin-permission-node": "^0.4.3",
"@backstage/plugin-scaffolder-common": "^0.1.3",
"@backstage/search-common": "^0.2.2",
"@backstage/types": "^0.1.1",
"@octokit/graphql": "^4.5.8",
Expand Down
Expand Up @@ -21,9 +21,9 @@ import {
GroupEntity,
ResourceEntity,
SystemEntity,
TemplateEntityV1beta2,
UserEntity,
} from '@backstage/catalog-model';
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
import { BuiltinKindsEntityProcessor } from './BuiltinKindsEntityProcessor';

describe('BuiltinKindsEntityProcessor', () => {
Expand Down
Expand Up @@ -46,11 +46,13 @@ import {
resourceEntityV1alpha1Validator,
SystemEntity,
systemEntityV1alpha1Validator,
TemplateEntityV1beta2,
templateEntityV1beta2Validator,
UserEntity,
userEntityV1alpha1Validator,
} from '@backstage/catalog-model';
import {
TemplateEntityV1beta2,
templateEntityV1beta2Validator,
} from '@backstage/plugin-scaffolder-common';
import * as result from './results';
import { CatalogProcessor, CatalogProcessorEmit } from './types';

Expand Down
1 change: 1 addition & 0 deletions plugins/catalog-react/package.json
Expand Up @@ -59,6 +59,7 @@
"@backstage/cli": "^0.13.2",
"@backstage/core-app-api": "^0.5.2",
"@backstage/plugin-catalog-common": "^0.1.2",
"@backstage/plugin-scaffolder-common": "^0.1.3",
"@backstage/test-utils": "^0.2.4",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^11.2.5",
Expand Down
3 changes: 2 additions & 1 deletion plugins/catalog-react/src/filters.test.ts
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import { Entity, TemplateEntityV1beta2 } from '@backstage/catalog-model';
import { Entity } from '@backstage/catalog-model';
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
import { EntityTextFilter } from './filters';

const entities: Entity[] = [
Expand Down
2 changes: 1 addition & 1 deletion plugins/scaffolder-backend/api-report.md
Expand Up @@ -29,7 +29,7 @@ import { SpawnOptionsWithoutStdio } from 'child_process';
import { TaskSpec } from '@backstage/plugin-scaffolder-common';
import { TaskSpecV1beta2 } from '@backstage/plugin-scaffolder-common';
import { TaskSpecV1beta3 } from '@backstage/plugin-scaffolder-common';
import { TemplateEntityV1beta2 } from '@backstage/catalog-model';
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
import { TemplateMetadata } from '@backstage/plugin-scaffolder-common';
import { UrlReader } from '@backstage/backend-common';
import { Writable } from 'stream';
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { TemplateEntityV1beta2 } from '@backstage/catalog-model';
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
import { CatalogApi } from '@backstage/catalog-client';
import { ConflictError, NotFoundError } from '@backstage/errors';

Expand Down
1 change: 1 addition & 0 deletions plugins/scaffolder-backend/src/scaffolder/index.ts
Expand Up @@ -13,5 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './actions';
export * from './tasks';
2 changes: 1 addition & 1 deletion plugins/scaffolder-backend/src/service/router.test.ts
Expand Up @@ -36,7 +36,7 @@ import {
UrlReaders,
} from '@backstage/backend-common';
import { CatalogApi } from '@backstage/catalog-client';
import { TemplateEntityV1beta2 } from '@backstage/catalog-model';
import { TemplateEntityV1beta2 } from '@backstage/plugin-scaffolder-common';
import { ConfigReader } from '@backstage/config';
import express from 'express';
import request from 'supertest';
Expand Down
7 changes: 5 additions & 2 deletions plugins/scaffolder-backend/src/service/router.ts
Expand Up @@ -20,11 +20,14 @@ import {
UrlReader,
} from '@backstage/backend-common';
import { CatalogApi } from '@backstage/catalog-client';
import { Entity, TemplateEntityV1beta2 } from '@backstage/catalog-model';
import { Entity } from '@backstage/catalog-model';
import { Config } from '@backstage/config';
import { InputError, NotFoundError } from '@backstage/errors';
import { ScmIntegrations } from '@backstage/integration';
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
import {
TemplateEntityV1beta2,
TemplateEntityV1beta3,
} from '@backstage/plugin-scaffolder-common';
import express from 'express';
import Router from 'express-promise-router';
import { validate } from 'jsonschema';
Expand Down
37 changes: 34 additions & 3 deletions plugins/scaffolder-common/api-report.md
Expand Up @@ -7,11 +7,12 @@ import { Entity } from '@backstage/catalog-model';
import { JsonObject } from '@backstage/types';
import { JSONSchema } from '@backstage/catalog-model';
import { JsonValue } from '@backstage/types';
import { KindValidator } from '@backstage/catalog-model';

// @public
export type TaskSpec = TaskSpecV1beta2 | TaskSpecV1beta3;

// @public
// @public @deprecated
export interface TaskSpecV1beta2 {
// (undocumented)
apiVersion: 'backstage.io/v1beta2';
Expand Down Expand Up @@ -61,7 +62,37 @@ export interface TaskStep {
name: string;
}

// @public (undocumented)
// @public @deprecated
export interface TemplateEntityV1beta2 extends Entity {
// (undocumented)
apiVersion: 'backstage.io/v1beta2';
// (undocumented)
kind: 'Template';
// (undocumented)
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 @deprecated
export const templateEntityV1beta2Schema: JSONSchema;

// @public @deprecated
export const templateEntityV1beta2Validator: KindValidator;

// @public
export interface TemplateEntityV1beta3 extends Entity {
// (undocumented)
apiVersion: 'scaffolder.backstage.io/v1beta3';
Expand All @@ -85,7 +116,7 @@ export interface TemplateEntityV1beta3 extends Entity {
};
}

// @public (undocumented)
// @public
export const templateEntityV1beta3Schema: JSONSchema;

// @public
Expand Down
15 changes: 10 additions & 5 deletions plugins/scaffolder-common/src/TaskSpec.ts
Expand Up @@ -17,7 +17,8 @@
import { JsonValue, JsonObject } from '@backstage/types';

/**
* TemplateMetadata
* Metadata about the Template that was the originator of a scaffolder task, as
* stored in the database.
*
* @public
*/
Expand All @@ -26,7 +27,7 @@ export type TemplateMetadata = {
};

/**
* TaskStep
* An individual step of a scaffolder task, as stored in the database.
*
* @public
*/
Expand All @@ -39,9 +40,12 @@ export interface TaskStep {
}

/**
* TaskSpecV1beta2
* A scaffolder task as stored in the database, generated from a v1beta2
* apiVersion Template.
*
* @public
* @deprecated Please convert your templates to TaskSpecV1beta3 on apiVersion
* scaffolder.backstage.io/v1beta3
*/
export interface TaskSpecV1beta2 {
apiVersion: 'backstage.io/v1beta2';
Expand All @@ -53,7 +57,8 @@ export interface TaskSpecV1beta2 {
}

/**
* TaskSpecV1beta3
* A scaffolder task as stored in the database, generated from a v1beta3
* apiVersion Template.
*
* @public
*/
Expand All @@ -67,7 +72,7 @@ export interface TaskSpecV1beta3 {
}

/**
* TaskSpec
* A scaffolder task as stored in the database, generated from a Template.
*
* @public
*/
Expand Down
Expand Up @@ -14,15 +14,22 @@
* limitations under the License.
*/

import {
Entity,
entityKindSchemaValidator,
JSONSchema,
KindValidator,
} from '@backstage/catalog-model';
import { JsonObject } from '@backstage/types';
import type { Entity } from '../entity/Entity';
import schema from '../schema/kinds/Template.v1beta2.schema.json';
import { ajvCompiledJsonSchemaValidator } from './util';
import schema from './Template.v1beta2.schema.json';

/**
* Backstage catalog Template kind Entity. Templates are used by the Scaffolder plugin to create new Components.
* Backstage catalog Template kind Entity. Templates are used by the Scaffolder
* plugin to create new entities, such as Components.
*
* @public
* @deprecated Please convert your templates to TemplateEntityV1beta3 on
* apiVersion scaffolder.backstage.io/v1beta3
*/
export interface TemplateEntityV1beta2 extends Entity {
apiVersion: 'backstage.io/v1beta2';
Expand All @@ -42,10 +49,30 @@ export interface TemplateEntityV1beta2 extends Entity {
};
}

const validator = entityKindSchemaValidator(schema);

/**
* JSON schema of the Template kind, apiVersion backstage.io/v1beta2.
*
* @public
* @deprecated Please convert your templates to apiVersion
* scaffolder.backstage.io/v1beta3
*/
export const templateEntityV1beta2Schema: JSONSchema = schema as Omit<
JSONSchema,
'examples'
>;

/**
* {@link KindValidator} for {@link TemplateEntityV1beta2}.
* Entity data validator for {@link TemplateEntityV1beta2}.
*
* @public
* @deprecated Please convert your templates to TemplateEntityV1beta3 on
* apiVersion scaffolder.backstage.io/v1beta3
*/
export const templateEntityV1beta2Validator =
ajvCompiledJsonSchemaValidator(schema);
export const templateEntityV1beta2Validator: KindValidator = {
// TODO(freben): Emulate the old KindValidator until we fix that type
async check(data: Entity) {
return validator(data) === data;
},
};
20 changes: 18 additions & 2 deletions plugins/scaffolder-common/src/TemplateEntityV1beta3.ts
Expand Up @@ -14,10 +14,16 @@
* limitations under the License.
*/

import { Entity, JSONSchema } from '@backstage/catalog-model';
import { JsonObject } from '@backstage/types';
import { Entity } from '@backstage/catalog-model';
import v1beta3Schema from './Template.v1beta3.schema.json';

/** @public */
/**
* Backstage catalog Template kind Entity. Templates are used by the Scaffolder
* plugin to create new entities, such as Components.
*
* @public
*/
export interface TemplateEntityV1beta3 extends Entity {
apiVersion: 'scaffolder.backstage.io/v1beta3';
kind: 'Template';
Expand All @@ -35,3 +41,13 @@ export interface TemplateEntityV1beta3 extends Entity {
owner?: string;
};
}

/**
* JSON schema of the Template kind, apiVersion scaffolder.backstage.io/v1beta3.
*
* @public
*/
export const templateEntityV1beta3Schema: JSONSchema = v1beta3Schema as Omit<
JSONSchema,
'examples'
>;

0 comments on commit e72d371

Please sign in to comment.