Skip to content

Commit

Permalink
feat(scaffolder-backend-module-annotator)!: migrate to the new backen…
Browse files Browse the repository at this point in the history
…d and remove deprecations (janus-idp#2269)

* remove legacy plugin installer

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* delete alpha and update dependencies

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* update dist-dynamic

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* update readme

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* remove backend-common dependency

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* regen yarn lock

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* Revert "regen yarn lock"

This reverts commit 15d9de7.

* change @backstage/backend-test-utils version

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* remove catalog-model dependency

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

* update README

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>

---------

Signed-off-by: Dominika Zemanovicova <dzemanov@redhat.com>
  • Loading branch information
dzemanov authored Oct 2, 2024
1 parent 33655e4 commit 53e5175
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 190 deletions.
114 changes: 3 additions & 111 deletions plugins/scaffolder-annotator-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,128 +20,20 @@ To begin, install the module package into the backend workspace of your backstag
yarn workspace backend add @janus-idp/backstage-scaffolder-backend-module-annotator
```

### Registering the annotator action plugin with the new backend system
### Registering the annotator action plugin with the backend system

To install the module into the [new backend system](https://backstage.io/docs/backend-system/), add the following into the `packages/backend/src/index.ts` file:
To install the module into the [backend system](https://backstage.io/docs/backend-system/), add the following into the `packages/backend/src/index.ts` file:

```ts title="packages/backend/src/index.ts
const backend = createBackend();

// highlight-add-start
backend.add(
import('@janus-idp/backstage-scaffolder-backend-module-annotator/alpha'),
);
backend.add(import('@janus-idp/backstage-scaffolder-backend-module-annotator'));
// highlight-add-end

backend.start();
```

### Registering the annotator action plugin with the legacy backend system

1. Register the custom actions in the `packages/backend/src/plugins/scaffolder.ts` file:

- Install the `@backstage/integration` package using the following command:

```console
yarn workspace backend add @backstage/integration
```

- Add the `createTimestampAction`, `createScaffoldedFromAction` and `createAnnotatorAction` with the other built-in actions:

```ts title="packages/backend/src/plugins/scaffolder.ts"

import { CatalogClient } from '@backstage/catalog-client';
/* highlight-add-start */
import { ScmIntegrations } from '@backstage/integration';
import {
createBuiltinActions,
createRouter,
} from '@backstage/plugin-scaffolder-backend';
import { createTimestampAction, createScaffoldedFromAction, createAnnotatorAction } from '@janus-idp/backstage-scaffolder-backend-module-annotator';
/* highlight-add-end */
...

export default async function createPlugin(
const catalogClient = new CatalogClient({
discoveryApi: env.discovery,
});

/* highlight-add-start */
const integrations = ScmIntegrations.fromConfig(env.config);

const builtInActions = createBuiltinActions({
integrations: integrations as any,
catalogClient,
config: env.config,
reader: env.reader,
});
const actions = [...builtInActions, createTimestampAction(), createScaffoldedFromAction(), createAnnotatorAction()];
/* highlight-add-end */


return await createRouter({
/* highlight-add-next-line */
actions,
logger: env.logger,
...
});
```

2. To annotate the `catalog-info.yaml` skeleton with the current timestamp, add the `catalog:timestamping` custom action in your template's YAML file after the `Fetch Skeleton + Template` step. Refer to the [example templates](./examples/) for examples on how it's used in a template.

```yaml title="template.yaml"
steps:
- id: template
name: Fetch Skeleton + Template
action: fetch:template
...

# highlight-add-start
- id: timestamp
name: Add Timestamp to catalog-info.yaml
action: catalog:timestamping
# highlight-add-end
```

3. To annotate the `catalog-info.yaml` skeleton with the template's `entityRef`, add the `catalog:scaffolded-from` custom action in your YAML file after the `Fetch Skeleton + Template` step. Refer to the [example templates](./examples/) for examples on how it is used in a template.

```yaml "title=template.yaml"
steps:
- id: template
name: Fetch Skeleton + Template
action: fetch:template
...
# highlight-add-start
- id: append-templateRef
name: Append the entityRef of this template to the entityRef
action: catalog:scaffolded-from
# highlight-add-end

```

4. To use the `catalog:annotate` action to annotate your entity object. Refer to the [example templates](./examples/) for examples on how it is used in a template.

```yaml "title=template.yaml"
steps:
- id: template
name: Fetch Skeleton + Template
action: fetch:template
...
# highlight-add-start
- id: add-fields-to-catalog-info
name: Add a few fields into `catalog-info.yaml` using the generic action
action: catalog:annotate
input:
labels:
custom: ${{ parameters.label }}
other: "test-label"
annotations:
custom.io/annotation: ${{ parameters.label }}
custom.io/other: "value"
# highlight-add-end

```

## Creating custom actions for your templates using the annotator module

### Create the custom action
Expand Down
10 changes: 1 addition & 9 deletions plugins/scaffolder-annotator-action/dist-dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"require": "./dist/index.cjs.js",
"default": "./dist/index.cjs.js"
},
"./alpha": {
"require": "./dist/alpha.cjs.js",
"default": "./dist/alpha.cjs.js"
},
"./package.json": "./package.json"
},
"scripts": {},
Expand All @@ -35,8 +31,7 @@
"files": [
"dist",
"config.d.ts",
"app-config.janus-idp.yaml",
"alpha"
"app-config.janus-idp.yaml"
],
"repository": {
"type": "git",
Expand All @@ -57,10 +52,7 @@
"author": "The Backstage Community",
"bundleDependencies": true,
"peerDependencies": {
"@backstage/backend-common": "^0.23.3",
"@backstage/backend-dynamic-feature-service": "^0.2.15",
"@backstage/backend-plugin-api": "^0.7.0",
"@backstage/catalog-model": "^1.5.0",
"@backstage/plugin-scaffolder-node": "^0.4.8"
},
"overrides": {
Expand Down
12 changes: 6 additions & 6 deletions plugins/scaffolder-annotator-action/dist-dynamic/yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions plugins/scaffolder-annotator-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
Expand All @@ -43,25 +39,21 @@
"tsc": "tsc"
},
"dependencies": {
"@backstage/backend-common": "^0.23.3",
"@backstage/backend-dynamic-feature-service": "^0.2.15",
"@backstage/backend-plugin-api": "^0.7.0",
"@backstage/catalog-model": "^1.5.0",
"@backstage/plugin-scaffolder-node": "^0.4.8",
"fs-extra": "^11.2.0",
"lodash": "^4.17.21",
"yaml": "^2.0.0"
},
"devDependencies": {
"@backstage/backend-common": "0.23.3",
"@backstage/backend-test-utils": "0.4.4",
"@backstage/cli": "0.26.11"
},
"files": [
"dist",
"config.d.ts",
"dist-dynamic/*.*",
"dist-dynamic/dist/**",
"dist-dynamic/alpha/*",
"app-config.janus-idp.yaml"
],
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getVoidLogger, resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { mockServices } from '@backstage/backend-test-utils';

import * as fs from 'fs-extra';
import * as yaml from 'yaml';
Expand Down Expand Up @@ -27,7 +28,7 @@ describe('catalog annotator', () => {
},
);

const logger = getVoidLogger();
const logger = mockServices.logger.mock();
jest.spyOn(logger, 'info');

await action.handler({
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('catalog annotator', () => {
},
);

const logger = getVoidLogger();
const logger = mockServices.logger.mock();
jest.spyOn(logger, 'info');

const mockContext = {
Expand Down Expand Up @@ -137,7 +138,7 @@ describe('catalog annotator', () => {
},
);

const logger = getVoidLogger();
const logger = mockServices.logger.mock();
jest.spyOn(logger, 'info');

const obj: { [key: string]: any } = {
Expand Down Expand Up @@ -212,7 +213,7 @@ describe('catalog annotator', () => {
},
);

const logger = getVoidLogger();
const logger = mockServices.logger.mock();
jest.spyOn(logger, 'info');

await action.handler({
Expand Down Expand Up @@ -262,7 +263,7 @@ describe('catalog annotator', () => {
},
);

const logger = getVoidLogger();
const logger = mockServices.logger.mock();
jest.spyOn(logger, 'info');

await action.handler({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';

import * as fs from 'fs-extra';
Expand Down
1 change: 0 additions & 1 deletion plugins/scaffolder-annotator-action/src/alpha.ts

This file was deleted.

16 changes: 0 additions & 16 deletions plugins/scaffolder-annotator-action/src/dynamic/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/scaffolder-annotator-action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
*/

export * from './actions';
export * from './dynamic';
export { scaffolderCustomActionsScaffolderModule as default } from './module';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolveSafeChildPath } from '@backstage/backend-common';
import { resolveSafeChildPath } from '@backstage/backend-plugin-api';

import * as fs from 'fs-extra';
import * as yaml from 'yaml';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionContext } from '@backstage/plugin-scaffolder-node';
import type { ActionContext } from '@backstage/plugin-scaffolder-node';

import { get } from 'lodash';

Expand Down
31 changes: 3 additions & 28 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 53e5175

Please sign in to comment.