Skip to content

Commit 961cbb5

Browse files
committed
create generic action for annotating objects
1 parent dd2d1bc commit 961cbb5

28 files changed

+775
-196
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Annotator custom action for Scaffolder Backstage
2+
3+
The annotator module for [@backstage/plugin-scaffolder-backend](https://www.npmjs.com/package/@backstage/plugin-scaffolder-backend).
4+
5+
## Getting started
6+
7+
### Installing on the new backend system
8+
9+
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:
10+
11+
```ts title="packages/backend/src/index.ts
12+
const backend = createBackend();
13+
14+
// highlight-add-start
15+
backend.add(
16+
import('@janus-idp/backstage-scaffolder-backend-module-annotator/alpha'),
17+
);
18+
// highlight-add-end
19+
20+
backend.start();
21+
```
22+
23+
### Installing on the legacy backend system
24+
25+
1. Install the Annotator custom action plugin using the following command:
26+
27+
```console
28+
yarn workspace backend add @janus-idp/backstage-scaffolder-backend-module-annotator
29+
```
30+
31+
2. Integrate the custom actions in the `scaffolder-backend` `createRouter` function:
32+
33+
- Install the `@backstage/integration` package using the following command:
34+
35+
```console
36+
yarn workspace backend add @backstage/integration
37+
```
38+
39+
- Add the `createTimestampAction` and `createScaffoldedFromAction` actions with the other built-in actions:
40+
41+
```ts title="packages/backend/src/plugins/scaffolder.ts"
42+
43+
import { CatalogClient } from '@backstage/catalog-client';
44+
/* highlight-add-start */
45+
import { ScmIntegrations } from '@backstage/integration';
46+
import {
47+
createBuiltinActions,
48+
createRouter,
49+
} from '@backstage/plugin-scaffolder-backend';
50+
import { createTimestampAction, createScaffoldedFromAction } from '@janus-idp/backstage-scaffolder-backend-module-annotator';
51+
/* highlight-add-end */
52+
...
53+
54+
export default async function createPlugin(
55+
const catalogClient = new CatalogClient({
56+
discoveryApi: env.discovery,
57+
});
58+
59+
/* highlight-add-start */
60+
const integrations = ScmIntegrations.fromConfig(env.config);
61+
62+
const builtInActions = createBuiltinActions({
63+
integrations: integrations as any,
64+
catalogClient,
65+
config: env.config,
66+
reader: env.reader,
67+
});
68+
const actions = [...builtInActions, createTimestampAction(), createScaffoldedFromAction()];
69+
/* highlight-add-end */
70+
71+
72+
return await createRouter({
73+
/* highlight-add-next-line */
74+
actions,
75+
logger: env.logger,
76+
...
77+
});
78+
```
79+
80+
3. To annotate the catalog-info.yaml skeleton with the current timestamp, add the **catalog:timestamping** custom action in your template yaml after the `Fetch Skeleton + Template` step:
81+
82+
````tsx title="template.yaml"
83+
84+
- id: template
85+
name: Fetch Skeleton + Template
86+
action: fetch:template
87+
...
88+
89+
/* highlight-add-start */
90+
- id: timestamp
91+
name: Add Timestamp to catalog-info.yaml
92+
action: catalog:timestamping
93+
/* highlight-add-end */
94+
95+
```
96+
97+
4. To annotate the catalog-info.yaml skeleton with the template entityRef, add the **catalog:scaffolded-from** custom action in your template yaml after the `Fetch Skeleton + Template` step:
98+
99+
```tsx title="template.yaml"
100+
101+
- id: template
102+
name: Fetch Skeleton + Template
103+
action: fetch:template
104+
...
105+
106+
/* highlight-add-start */
107+
- id: append-templateRef
108+
name: Append the entityRef of this template to the entityRef
109+
action: catalog:scaffolded-from
110+
/* highlight-add-end */
111+
112+
````
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "@janus-idp/backstage-scaffolder-backend-module-annotator-dynamic",
3+
"description": "The annotator module for @backstage/plugin-scaffolder-backend",
4+
"version": "0.1.0",
5+
"main": "dist/index.cjs.js",
6+
"types": "dist/index.d.ts",
7+
"license": "Apache-2.0",
8+
"publishConfig": {
9+
"access": "public",
10+
"main": "dist/index.cjs.js",
11+
"types": "dist/index.d.ts"
12+
},
13+
"backstage": {
14+
"role": "backend-plugin-module"
15+
},
16+
"scripts": {},
17+
"dependencies": {
18+
"fs-extra": "^11.2.0",
19+
"yaml": "^2.0.0"
20+
},
21+
"devDependencies": {},
22+
"files": [
23+
"dist",
24+
"dist-scalprum",
25+
"app-config.janus-idp.yaml"
26+
],
27+
"repository": "github:janus-idp/backstage-plugins",
28+
"keywords": [
29+
"backstage",
30+
"plugin"
31+
],
32+
"homepage": "https://janus-idp.io/",
33+
"bugs": "https://github.com/janus-idp/backstage-plugins/issues",
34+
"bundleDependencies": true,
35+
"peerDependencies": {
36+
"@backstage/plugin-scaffolder-node": "^0.4.2",
37+
"@backstage/backend-common": "^0.21.6",
38+
"@backstage/catalog-model": "^1.4.5"
39+
},
40+
"overrides": {
41+
"@aws-sdk/util-utf8-browser": {
42+
"@smithy/util-utf8": "^2.0.0"
43+
}
44+
},
45+
"resolutions": {
46+
"@aws-sdk/util-utf8-browser": "npm:@smithy/util-utf8@~2"
47+
}
48+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"@aws-sdk/util-utf8-browser@npm:@smithy/util-utf8@~2":
6+
version "2.3.0"
7+
resolved "https://registry.yarnpkg.com/@smithy/util-utf8/-/util-utf8-2.3.0.tgz#dd96d7640363259924a214313c3cf16e7dd329c5"
8+
integrity sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==
9+
dependencies:
10+
"@smithy/util-buffer-from" "^2.2.0"
11+
tslib "^2.6.2"
12+
13+
"@smithy/is-array-buffer@^2.2.0":
14+
version "2.2.0"
15+
resolved "https://registry.yarnpkg.com/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz#f84f0d9f9a36601a9ca9381688bd1b726fd39111"
16+
integrity sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==
17+
dependencies:
18+
tslib "^2.6.2"
19+
20+
"@smithy/util-buffer-from@^2.2.0":
21+
version "2.2.0"
22+
resolved "https://registry.yarnpkg.com/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz#6fc88585165ec73f8681d426d96de5d402021e4b"
23+
integrity sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==
24+
dependencies:
25+
"@smithy/is-array-buffer" "^2.2.0"
26+
tslib "^2.6.2"
27+
28+
fs-extra@^11.2.0:
29+
version "11.2.0"
30+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.2.0.tgz#e70e17dfad64232287d01929399e0ea7c86b0e5b"
31+
integrity sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==
32+
dependencies:
33+
graceful-fs "^4.2.0"
34+
jsonfile "^6.0.1"
35+
universalify "^2.0.0"
36+
37+
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
38+
version "4.2.11"
39+
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3"
40+
integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==
41+
42+
jsonfile@^6.0.1:
43+
version "6.1.0"
44+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
45+
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
46+
dependencies:
47+
universalify "^2.0.0"
48+
optionalDependencies:
49+
graceful-fs "^4.1.6"
50+
51+
tslib@^2.6.2:
52+
version "2.6.2"
53+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
54+
integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==
55+
56+
universalify@^2.0.0:
57+
version "2.0.1"
58+
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.1.tgz#168efc2180964e6386d061e094df61afe239b18d"
59+
integrity sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==
60+
61+
yaml@^2.0.0:
62+
version "2.4.2"
63+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.4.2.tgz#7a2b30f2243a5fc299e1f14ca58d475ed4bc5362"
64+
integrity sha512-B3VqDZ+JAg1nZpaEmWtTXUlBneoGx6CPM9b0TENK6aoSu5t73dItudwdgmi6tHlIZZId4dZ9skcAQ2UbcyAeVA==

plugins/scaffolder-timestamp-action/package.json renamed to plugins/scaffolder-annotator-action/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
2-
"name": "@janus-idp/backstage-scaffolder-backend-module-timestamp",
3-
"description": "The timestamp module for @backstage/plugin-scaffolder-backend",
2+
"name": "@janus-idp/backstage-scaffolder-backend-module-annotator",
3+
"description": "The annotator module for @backstage/plugin-scaffolder-backend",
44
"version": "0.1.0",
55
"main": "src/index.ts",
66
"types": "src/index.ts",
77
"license": "Apache-2.0",
8-
"private": true,
98
"publishConfig": {
109
"access": "public",
1110
"main": "dist/index.cjs.js",
@@ -23,6 +22,7 @@
2322
"prepack": "backstage-cli package prepack",
2423
"postpack": "backstage-cli package postpack",
2524
"export-dynamic": "janus-cli package export-dynamic-plugin",
25+
"lodash": "^4.17.21",
2626
"tsc": "tsc"
2727
},
2828
"dependencies": {

0 commit comments

Comments
 (0)