@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator
2
2
 
3
+ ## 0.3.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a9a6095]
8
+ - @red-hat-developer-hub/backstage-plugin-orchestrator-common@1.28.1
9
+
10
+ ## 0.3.4
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [53f3ffb]
15
+ - @red-hat-developer-hub/backstage-plugin-orchestrator-common@1.28.0
16
+
3
17
  ## 0.3.3
4
18
 
5
19
  ### Patch Changes
package/README.md CHANGED
@@ -6,15 +6,19 @@ An example of using these actions can be found in the `workspaces/orchestrator/e
6
6
 
7
7
  ## Installation
8
8
 
9
- ### As a static plugin
9
+ ### Static Plugin Installation
10
10
 
11
11
  In `packages/backend/src/index.ts`:
12
12
 
13
- ```
14
- backend.add(import('@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator'));
13
+ ```ts
14
+ backend.add(
15
+ import(
16
+ '@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator'
17
+ ),
18
+ );
15
19
  ```
16
20
 
17
- # The software template generating templates from workflows - convertWorkflowToTemplate
21
+ ## convertWorkflowToTemplate: A Software Template for Converting Workflows into Templates
18
22
 
19
23
  The `workspaces/orchestrator/entities/convertWorkflowToTemplate.yaml` scaffolder software template is used for generating templates to be used to execute a serverless workflow via the Orchestrator.
20
24
 
@@ -26,7 +30,7 @@ The rest of parameters cover details about the target GitHub repository to eithe
26
30
 
27
31
  The generated yaml template is accompanied by a README file highlighting instructions how to register the new template in the Backstage catalog.
28
32
 
29
- ## Important Note on Template Input Structure
33
+ **Important Note on Template Input Structure:**
30
34
 
31
35
  The structure of the template input differs from that of the page used for collecting input parameters for workflows, despite some similarities. These two pages are supported by distinct implementations. While the set of parameters should remain consistent, their visual representation and especially grouping into steps may vary.
32
36
 
@@ -35,7 +39,7 @@ The structure of the template input differs from that of the page used for colle
35
39
  The `[workflowId]` matches the identifier from the workflow definition.
36
40
  For example, in the [workflow definition](https://github.com/rhdhorchestrator/serverless-workflows/blob/main/workflows/greeting/greeting.sw.yaml) below, the identifier is `greeting`:
37
41
 
38
- ```yaml greeting.sw.yaml
42
+ ```yaml
39
43
  id: greeting
40
44
  version: '1.0'
41
45
  specVersion: '0.8'
@@ -49,6 +53,52 @@ extensions:
49
53
  outputSchema: schemas/workflow-output-schema.json
50
54
  ```
51
55
 
56
+ ## Available Actions
57
+
58
+ ### Action: `orchestrator:workflow:run`
59
+
60
+ Runs a SonataFlow workflow from a Software Template.
61
+
62
+ **Input:**
63
+
64
+ - `workflow_id` (string, required): The workflow ID from the definition.
65
+ - `parameters` (object, required): Input parameters for the workflow.
66
+
67
+ **Dry Run:** Supported — logs the event without executing the call.
68
+
69
+ **Example:**
70
+
71
+ ```yaml
72
+ steps:
73
+ - id: runWorkflow
74
+ name: Run workflow
75
+ action: orchestrator:workflow:run
76
+ input:
77
+ workflow_id: yamlgreet
78
+ parameters: ${{ parameters }}
79
+ ```
80
+
81
+ ---
82
+
83
+ ### Action: `orchestrator:workflow:get_params`
84
+
85
+ Retrieves metadata and input schema from a SonataFlow workflow.
86
+
87
+ **Input:**
88
+
89
+ - `workflow_id` (string, required): The workflow ID.
90
+ - `indent` (number, optional): Indentation level for the resulting YAML.
91
+
92
+ **Output:**
93
+
94
+ - `title`
95
+ - `description`
96
+ - `parameters`
97
+
98
+ **Dry Run:** Not supported.
99
+
100
+ ---
101
+
52
102
  ## GitHub integration
53
103
 
54
104
  The `convertWorkflowToTemplate.yaml` template pushes the result into a GitHub repository.
@@ -76,18 +126,26 @@ export GITHUB_TOKEN=.......
76
126
 
77
127
  - configure `app-config.yaml`:
78
128
 
79
- ```
80
- integrations:
81
- github:
82
- - token: ${GITHUB_TOKEN}
83
- ```
129
+ ```yaml
130
+ integrations:
131
+ github:
132
+ - token: ${GITHUB_TOKEN}
133
+ ```
84
134
 
85
- ## Resources
135
+ ---
136
+
137
+ ## Hints
86
138
 
87
- - [Upstream documentation](https://backstage.io/docs/features/software-templates/builtin-actions)
139
+ - When using **Node.js 20+**, add this environment variable **before** running the backend:
88
140
 
89
- # Hints
141
+ ```bash
142
+ export NODE_OPTIONS="${NODE_OPTIONS:-} --no-node-snapshot"
143
+ ```
90
144
 
91
- Mind using `export NODE_OPTIONS="${NODE_OPTIONS:-} --no-node-snapshot"` before running the Backstage backend app with Node 20+ (per actual [warning in the upstream documentation](https://backstage.io/docs/features/software-templates/#getting-started)) - this might be changed in the future.
145
+ [Reference from Backstage documentation](https://backstage.io/docs/features/software-templates/#getting-started)
146
+
147
+ ---
148
+
149
+ ## Resources
92
150
 
93
- Before running the Backstage backend app with **Node 20+**, be sure to execute `export NODE_OPTIONS="${NODE_OPTIONS:-} --no-node-snapshot` as recommended by the [warning in the upstream documentation](https://backstage.io/docs/features/software-templates/#getting-started) (this might be changed in the future).
151
+ - [Backstage Template Actions Documentation](https://backstage.io/docs/features/software-templates/builtin-actions)
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var catalogModel = require('@backstage/catalog-model');
4
3
  var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
5
4
  var axios = require('axios');
6
5
  var utils = require('./utils.cjs.js');
@@ -41,11 +40,15 @@ const createRunWorkflowAction = (discoveryService, authService) => pluginScaffol
41
40
  ctx.logger.info(`Dry run complete`);
42
41
  return;
43
42
  }
43
+ if (!ctx.input.workflow_id) {
44
+ throw new Error(
45
+ "Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input."
46
+ );
47
+ }
44
48
  try {
45
49
  const { data } = await api.executeWorkflow(
46
- catalogModel.parseEntityRef(entity).name,
50
+ ctx.input.workflow_id,
47
51
  { inputData: ctx.input.parameters },
48
- void 0,
49
52
  reqConfigOption
50
53
  );
51
54
  ctx.output("instanceUrl", `/orchestrator/instances/${data.id}`);
@@ -1 +1 @@
1
- {"version":3,"file":"runWorkflow.cjs.js","sources":["../../src/actions/runWorkflow.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { parseEntityRef } from '@backstage/catalog-model';\nimport { DiscoveryApi } from '@backstage/plugin-permission-common/index';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\n\nimport { isAxiosError } from 'axios';\n\nimport { getOrchestratorApi, getRequestConfigOption } from './utils';\n\ntype RunWorkflowTemplateActionInput = { parameters: JsonObject };\ntype RunWorkflowTemplateActionOutput = { instanceUrl: string };\n\nconst getError = (err: unknown): Error => {\n if (\n isAxiosError<{ error: { message: string; name: string } }>(err) &&\n err.response?.data?.error?.message\n ) {\n const error = new Error(err.response?.data?.error?.message);\n error.name = err.response?.data?.error?.name || 'Error';\n return error;\n }\n return err as Error;\n};\n\nexport const createRunWorkflowAction = (\n discoveryService: DiscoveryApi,\n authService: AuthService,\n) =>\n createTemplateAction<\n RunWorkflowTemplateActionInput,\n RunWorkflowTemplateActionOutput\n >({\n id: 'orchestrator:workflow:run',\n description: 'Run a SonataFlow workflow.',\n supportsDryRun: true,\n schema: {\n input: {\n required: ['parameters'],\n type: 'object',\n properties: {\n parameters: {\n type: 'object',\n title: 'Parameters',\n description: 'The workflow parameters.',\n },\n },\n },\n },\n async handler(ctx) {\n const entity = ctx.templateInfo?.entityRef;\n if (!entity) {\n throw new Error('No template entity');\n }\n\n const api = await getOrchestratorApi(discoveryService);\n const reqConfigOption = await getRequestConfigOption(authService, ctx);\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n try {\n const { data } = await api.executeWorkflow(\n parseEntityRef(entity).name,\n { inputData: ctx.input.parameters },\n undefined,\n reqConfigOption,\n );\n ctx.output('instanceUrl', `/orchestrator/instances/${data.id}`);\n } catch (err) {\n throw getError(err);\n }\n },\n });\n"],"names":["isAxiosError","createTemplateAction","getOrchestratorApi","getRequestConfigOption","parseEntityRef"],"mappings":";;;;;;;AA4BA,MAAM,QAAA,GAAW,CAAC,GAAwB,KAAA;AACxC,EAAA,IACEA,mBAA2D,GAAG,CAAA,IAC9D,IAAI,QAAU,EAAA,IAAA,EAAM,OAAO,OAC3B,EAAA;AACA,IAAA,MAAM,QAAQ,IAAI,KAAA,CAAM,IAAI,QAAU,EAAA,IAAA,EAAM,OAAO,OAAO,CAAA;AAC1D,IAAA,KAAA,CAAM,IAAO,GAAA,GAAA,CAAI,QAAU,EAAA,IAAA,EAAM,OAAO,IAAQ,IAAA,OAAA;AAChD,IAAO,OAAA,KAAA;AAAA;AAET,EAAO,OAAA,GAAA;AACT,CAAA;AAEO,MAAM,uBAA0B,GAAA,CACrC,gBACA,EAAA,WAAA,KAEAC,yCAGE,CAAA;AAAA,EACA,EAAI,EAAA,2BAAA;AAAA,EACJ,WAAa,EAAA,4BAAA;AAAA,EACb,cAAgB,EAAA,IAAA;AAAA,EAChB,MAAQ,EAAA;AAAA,IACN,KAAO,EAAA;AAAA,MACL,QAAA,EAAU,CAAC,YAAY,CAAA;AAAA,MACvB,IAAM,EAAA,QAAA;AAAA,MACN,UAAY,EAAA;AAAA,QACV,UAAY,EAAA;AAAA,UACV,IAAM,EAAA,QAAA;AAAA,UACN,KAAO,EAAA,YAAA;AAAA,UACP,WAAa,EAAA;AAAA;AACf;AACF;AACF,GACF;AAAA,EACA,MAAM,QAAQ,GAAK,EAAA;AACjB,IAAM,MAAA,MAAA,GAAS,IAAI,YAAc,EAAA,SAAA;AACjC,IAAA,IAAI,CAAC,MAAQ,EAAA;AACX,MAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AAGtC,IAAM,MAAA,GAAA,GAAM,MAAMC,wBAAA,CAAmB,gBAAgB,CAAA;AACrD,IAAA,MAAM,eAAkB,GAAA,MAAMC,4BAAuB,CAAA,WAAA,EAAa,GAAG,CAAA;AAGrE,IAAA,IAAI,IAAI,QAAU,EAAA;AAChB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,CAAkB,gBAAA,CAAA,CAAA;AAClC,MAAA;AAAA;AAGF,IAAI,IAAA;AACF,MAAA,MAAM,EAAE,IAAA,EAAS,GAAA,MAAM,GAAI,CAAA,eAAA;AAAA,QACzBC,2BAAA,CAAe,MAAM,CAAE,CAAA,IAAA;AAAA,QACvB,EAAE,SAAA,EAAW,GAAI,CAAA,KAAA,CAAM,UAAW,EAAA;AAAA,QAClC,KAAA,CAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,GAAA,CAAI,MAAO,CAAA,aAAA,EAAe,CAA2B,wBAAA,EAAA,IAAA,CAAK,EAAE,CAAE,CAAA,CAAA;AAAA,aACvD,GAAK,EAAA;AACZ,MAAA,MAAM,SAAS,GAAG,CAAA;AAAA;AACpB;AAEJ,CAAC;;;;"}
1
+ {"version":3,"file":"runWorkflow.cjs.js","sources":["../../src/actions/runWorkflow.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { AuthService } from '@backstage/backend-plugin-api';\nimport { DiscoveryApi } from '@backstage/plugin-permission-common/index';\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { JsonObject } from '@backstage/types';\n\nimport { isAxiosError } from 'axios';\n\nimport { getOrchestratorApi, getRequestConfigOption } from './utils';\n\ntype RunWorkflowTemplateActionInput = {\n parameters: JsonObject;\n workflow_id: string;\n};\ntype RunWorkflowTemplateActionOutput = { instanceUrl: string };\n\nconst getError = (err: unknown): Error => {\n if (\n isAxiosError<{ error: { message: string; name: string } }>(err) &&\n err.response?.data?.error?.message\n ) {\n const error = new Error(err.response?.data?.error?.message);\n error.name = err.response?.data?.error?.name || 'Error';\n return error;\n }\n return err as Error;\n};\n\nexport const createRunWorkflowAction = (\n discoveryService: DiscoveryApi,\n authService: AuthService,\n) =>\n createTemplateAction<\n RunWorkflowTemplateActionInput,\n RunWorkflowTemplateActionOutput\n >({\n id: 'orchestrator:workflow:run',\n description: 'Run a SonataFlow workflow.',\n supportsDryRun: true,\n schema: {\n input: {\n required: ['parameters'],\n type: 'object',\n properties: {\n parameters: {\n type: 'object',\n title: 'Parameters',\n description: 'The workflow parameters.',\n },\n },\n },\n },\n async handler(ctx) {\n const entity = ctx.templateInfo?.entityRef;\n if (!entity) {\n throw new Error('No template entity');\n }\n\n const api = await getOrchestratorApi(discoveryService);\n const reqConfigOption = await getRequestConfigOption(authService, ctx);\n\n // If this is a dry run, log and return\n if (ctx.isDryRun) {\n ctx.logger.info(`Dry run complete`);\n return;\n }\n\n if (!ctx.input.workflow_id) {\n throw new Error(\n \"Missing required 'workflow_id' input. Ensure that the step invoking the 'orchestrator:workflow:run' action includes an explicit 'workflow_id' field in its input.\",\n );\n }\n\n try {\n const { data } = await api.executeWorkflow(\n ctx.input.workflow_id,\n { inputData: ctx.input.parameters },\n reqConfigOption,\n );\n ctx.output('instanceUrl', `/orchestrator/instances/${data.id}`);\n } catch (err) {\n throw getError(err);\n }\n },\n });\n"],"names":["isAxiosError","createTemplateAction","getOrchestratorApi","getRequestConfigOption"],"mappings":";;;;;;AA8BA,MAAM,QAAA,GAAW,CAAC,GAAwB,KAAA;AACxC,EAAA,IACEA,mBAA2D,GAAG,CAAA,IAC9D,IAAI,QAAU,EAAA,IAAA,EAAM,OAAO,OAC3B,EAAA;AACA,IAAA,MAAM,QAAQ,IAAI,KAAA,CAAM,IAAI,QAAU,EAAA,IAAA,EAAM,OAAO,OAAO,CAAA;AAC1D,IAAA,KAAA,CAAM,IAAO,GAAA,GAAA,CAAI,QAAU,EAAA,IAAA,EAAM,OAAO,IAAQ,IAAA,OAAA;AAChD,IAAO,OAAA,KAAA;AAAA;AAET,EAAO,OAAA,GAAA;AACT,CAAA;AAEO,MAAM,uBAA0B,GAAA,CACrC,gBACA,EAAA,WAAA,KAEAC,yCAGE,CAAA;AAAA,EACA,EAAI,EAAA,2BAAA;AAAA,EACJ,WAAa,EAAA,4BAAA;AAAA,EACb,cAAgB,EAAA,IAAA;AAAA,EAChB,MAAQ,EAAA;AAAA,IACN,KAAO,EAAA;AAAA,MACL,QAAA,EAAU,CAAC,YAAY,CAAA;AAAA,MACvB,IAAM,EAAA,QAAA;AAAA,MACN,UAAY,EAAA;AAAA,QACV,UAAY,EAAA;AAAA,UACV,IAAM,EAAA,QAAA;AAAA,UACN,KAAO,EAAA,YAAA;AAAA,UACP,WAAa,EAAA;AAAA;AACf;AACF;AACF,GACF;AAAA,EACA,MAAM,QAAQ,GAAK,EAAA;AACjB,IAAM,MAAA,MAAA,GAAS,IAAI,YAAc,EAAA,SAAA;AACjC,IAAA,IAAI,CAAC,MAAQ,EAAA;AACX,MAAM,MAAA,IAAI,MAAM,oBAAoB,CAAA;AAAA;AAGtC,IAAM,MAAA,GAAA,GAAM,MAAMC,wBAAA,CAAmB,gBAAgB,CAAA;AACrD,IAAA,MAAM,eAAkB,GAAA,MAAMC,4BAAuB,CAAA,WAAA,EAAa,GAAG,CAAA;AAGrE,IAAA,IAAI,IAAI,QAAU,EAAA;AAChB,MAAI,GAAA,CAAA,MAAA,CAAO,KAAK,CAAkB,gBAAA,CAAA,CAAA;AAClC,MAAA;AAAA;AAGF,IAAI,IAAA,CAAC,GAAI,CAAA,KAAA,CAAM,WAAa,EAAA;AAC1B,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA;AAGF,IAAI,IAAA;AACF,MAAA,MAAM,EAAE,IAAA,EAAS,GAAA,MAAM,GAAI,CAAA,eAAA;AAAA,QACzB,IAAI,KAAM,CAAA,WAAA;AAAA,QACV,EAAE,SAAA,EAAW,GAAI,CAAA,KAAA,CAAM,UAAW,EAAA;AAAA,QAClC;AAAA,OACF;AACA,MAAA,GAAA,CAAI,MAAO,CAAA,aAAA,EAAe,CAA2B,wBAAA,EAAA,IAAA,CAAK,EAAE,CAAE,CAAA,CAAA;AAAA,aACvD,GAAK,EAAA;AACZ,MAAA,MAAM,SAAS,GAAG,CAAA;AAAA;AACpB;AAEJ,CAAC;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@red-hat-developer-hub/backstage-plugin-scaffolder-backend-module-orchestrator",
3
3
  "description": "The orchestrator module for @backstage/plugin-scaffolder-backend",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -63,7 +63,7 @@
63
63
  "@backstage/catalog-model": "^1.7.3",
64
64
  "@backstage/plugin-scaffolder-node": "^0.8.0",
65
65
  "@backstage/types": "^1.2.1",
66
- "@red-hat-developer-hub/backstage-plugin-orchestrator-common": "^1.27.3",
66
+ "@red-hat-developer-hub/backstage-plugin-orchestrator-common": "^1.28.1",
67
67
  "axios": "^1.7.9",
68
68
  "js-yaml": "^4.1.0"
69
69
  },