Skip to content

chore: fix lint issues and dynamic plugin exporting #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions plugins/scaffolder-annotator-action/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ backend.start();

1. Install the Annotator custom action plugin using the following command:

```console
yarn workspace backend add @janus-idp/backstage-scaffolder-backend-module-annotator
```
```console
yarn workspace backend add @janus-idp/backstage-scaffolder-backend-module-annotator
```

2. Integrate the custom actions in the `scaffolder-backend` `createRouter` function:

Expand All @@ -53,60 +53,58 @@ backend.start();

export default async function createPlugin(
const catalogClient = new CatalogClient({
discoveryApi: env.discovery,
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,
integrations: integrations as any,
catalogClient,
config: env.config,
reader: env.reader,
});
const actions = [...builtInActions, createTimestampAction(), createScaffoldedFromAction()];
/* highlight-add-end */


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

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:

````tsx title="template.yaml"

- 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 */

```
```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
```

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:

```tsx title="template.yaml"

- id: template
name: Fetch Skeleton + Template
action: fetch: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

/* highlight-add-start */
- id: append-templateRef
name: Append the entityRef of this template to the entityRef
action: catalog:scaffolded-from
/* highlight-add-end */

````
```
23 changes: 19 additions & 4 deletions plugins/scaffolder-annotator-action/dist-dynamic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@
"backstage": {
"role": "backend-plugin-module"
},
"exports": {
".": {
"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": {},
"dependencies": {
"fs-extra": "^11.2.0",
"lodash": "^4.17.21",
"yaml": "^2.0.0"
},
"devDependencies": {},
"files": [
"dist",
"dist-scalprum",
"app-config.janus-idp.yaml"
"config.d.ts",
"app-config.janus-idp.yaml",
"alpha"
],
"repository": "github:janus-idp/backstage-plugins",
"keywords": [
Expand All @@ -33,9 +46,11 @@
"bugs": "https://github.com/janus-idp/backstage-plugins/issues",
"bundleDependencies": true,
"peerDependencies": {
"@backstage/plugin-scaffolder-node": "^0.4.2",
"@backstage/backend-common": "^0.21.6",
"@backstage/catalog-model": "^1.4.5"
"@backstage/backend-dynamic-feature-service": "^0.2.9",
"@backstage/backend-plugin-api": "^0.6.17",
"@backstage/catalog-model": "^1.4.5",
"@backstage/plugin-scaffolder-node": "^0.4.2"
},
"overrides": {
"@aws-sdk/util-utf8-browser": {
Expand Down
5 changes: 5 additions & 0 deletions plugins/scaffolder-annotator-action/dist-dynamic/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"

lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

tslib@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae"
Expand Down
25 changes: 23 additions & 2 deletions plugins/scaffolder-annotator-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@
"backstage": {
"role": "backend-plugin-module"
},
"exports": {
".": "./src/index.ts",
"./alpha": "./src/alpha.ts",
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"alpha": [
"src/alpha.ts"
],
"package.json": [
"package.json"
]
}
},
"scripts": {
"start": "backstage-cli package start",
"build": "backstage-cli package build",
Expand All @@ -26,10 +41,13 @@
"tsc": "tsc"
},
"dependencies": {
"@backstage/plugin-scaffolder-node": "^0.4.2",
"@backstage/backend-common": "^0.21.6",
"@backstage/backend-dynamic-feature-service": "^0.2.9",
"@backstage/backend-plugin-api": "^0.6.17",
"@backstage/catalog-model": "^1.4.5",
"@backstage/plugin-scaffolder-node": "^0.4.2",
"fs-extra": "^11.2.0",
"lodash": "^4.17.21",
"yaml": "^2.0.0"
},
"devDependencies": {
Expand All @@ -38,7 +56,10 @@
},
"files": [
"dist",
"dist-scalprum",
"config.d.ts",
"dist-dynamic/*.*",
"dist-dynamic/dist/**",
"dist-dynamic/alpha/*",
"app-config.janus-idp.yaml"
],
"repository": "github:janus-idp/backstage-plugins",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ describe('catalog annotator', () => {
const entity = yaml.parse(updatedCatalogInfoYaml);

expect(logger.info).toHaveBeenCalledWith('some logger info msg');
expect(entity?.spec?.['scaffoldedFrom']).toBe('testt-ref');
expect(entity?.spec?.scaffoldedFrom).toBe('testt-ref');

// undo catalog-info.yaml file changes
delete entity?.spec?.['scaffoldedFrom'];
delete entity?.spec?.scaffoldedFrom;
await fs.writeFile(
resolveSafeChildPath(workspacePath, './catalog-info.yaml'),
yaml.stringify(entity),
Expand Down Expand Up @@ -260,10 +260,10 @@ describe('catalog annotator', () => {
const entity = yaml.parse(updatedCatalogInfoYaml);

expect(logger.info).toHaveBeenCalledWith('some logger info msg');
expect(entity?.spec?.['scaffoldedFrom']).toBe('test-entityRef');
expect(entity?.spec?.scaffoldedFrom).toBe('test-entityRef');

// undo catalog-info.yaml file changes
delete entity?.spec?.['scaffoldedFrom'];
delete entity?.spec?.scaffoldedFrom;
await fs.writeFile(
resolveSafeChildPath(workspacePath, './catalog-info.yaml'),
yaml.stringify(entity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getObjectToAnnotate } from '../../utils/getObjectToAnnotate';
import { resolveSpec } from '../../utils/resolveSpec';

/**
* Creates a new Scaffolder action to annotate a catalog-info.yaml with desired lable(s), annotation(s) and spec property(ies).
* Creates a new Scaffolder action to annotate a catalog-info.yaml with desired label(s), annotation(s) and spec property(ies).
*
*/

Expand Down Expand Up @@ -48,12 +48,12 @@ export const createAnnotatorAction = (
},
objectFilePath: {
title: 'Object File Path',
description: 'Path to the object yaml you want to annonate',
description: 'Path to the object yaml you want to annotate',
type: 'string',
},
objectYaml: {
title: 'Object Yaml',
description: 'Any object yaml you want to annonate',
description: 'Any object yaml you want to annotate',
type: 'object',
},
writeToFile: {
Expand Down
1 change: 1 addition & 0 deletions plugins/scaffolder-annotator-action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export * from './actions';
export * from './dynamic';
3 changes: 1 addition & 2 deletions plugins/scaffolder-annotator-action/src/utils/resolveSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const resolveSpec = (
return {};
}
return Object.keys(spec).reduce((acc, s) => {
acc = {
return {
...acc,
...{
[`${s}`]:
Expand All @@ -19,6 +19,5 @@ export const resolveSpec = (
: spec[s],
},
};
return acc;
}, {});
};
2 changes: 1 addition & 1 deletion plugins/scaffolder-annotator-action/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"include": ["src", "dev", "migrations"],
"exclude": ["node_modules"],
"compilerOptions": {
"outDir": "../../dist-types/plugins/scaffolder-timestamp-action",
"outDir": "../../dist-types/plugins/scaffolder-annotator-action",
"rootDir": "."
}
}
9 changes: 9 additions & 0 deletions plugins/scaffolder-annotator-action/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": ["//"],
"pipeline": {
"tsc": {
"outputs": ["../../dist-types/plugins/scaffolder-annotator-action/**"],
"dependsOn": ["^tsc"]
}
}
}
Loading