@roadiehq/scaffolder-backend-module-utils 1.7.0 → 1.7.1
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/README.md +175 -87
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
# scaffolder-backend-module-utils actions package
|
|
2
2
|
|
|
3
|
+
## Intro
|
|
4
|
+
|
|
3
5
|
Welcome to the roadie `utils` actions for the `scaffolder-backend`.
|
|
4
6
|
|
|
5
|
-
This contains a collection of actions:
|
|
7
|
+
This contains a collection of actions to use in scaffolder templates:
|
|
8
|
+
|
|
9
|
+
- [Zip](#zip)
|
|
10
|
+
- [Sleep](#sleep)
|
|
11
|
+
- [Deserialise a file](#deserialise)
|
|
12
|
+
- [Serialise to json or yaml](#serialise)
|
|
13
|
+
- [Extract values from Json](#parse-json)
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
- `roadiehq:utils:sleep`
|
|
9
|
-
- `roadiehq:utils:fs:write`
|
|
10
|
-
- `roadiehq:utils:fs:append`
|
|
15
|
+
## Setup
|
|
11
16
|
|
|
12
|
-
##
|
|
17
|
+
## Setting up Backstage
|
|
13
18
|
|
|
14
19
|
Create your Backstage application using the Backstage CLI as described here:
|
|
15
20
|
https://backstage.io/docs/getting-started/create-an-app
|
|
@@ -18,7 +23,7 @@ https://backstage.io/docs/getting-started/create-an-app
|
|
|
18
23
|
|
|
19
24
|
You need to configure the action in your backend:
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
### Installing the actions
|
|
22
27
|
|
|
23
28
|
```
|
|
24
29
|
cd packages/backend
|
|
@@ -83,7 +88,16 @@ return await createRouter({
|
|
|
83
88
|
});
|
|
84
89
|
```
|
|
85
90
|
|
|
86
|
-
|
|
91
|
+
## Actions:
|
|
92
|
+
|
|
93
|
+
### Zip - `roadiehq:utils:zip`
|
|
94
|
+
|
|
95
|
+
Compress files and store them to the temporary workspace in .zip format.
|
|
96
|
+
|
|
97
|
+
_Required Params:_
|
|
98
|
+
|
|
99
|
+
- path: The path in your workspace of the file you want to zip
|
|
100
|
+
- outputPath: The path you want to use to save the generated zip file.
|
|
87
101
|
|
|
88
102
|
```yaml
|
|
89
103
|
---
|
|
@@ -118,10 +132,16 @@ spec:
|
|
|
118
132
|
outputPath: ${{ parameters.outputPath }}
|
|
119
133
|
|
|
120
134
|
output:
|
|
121
|
-
|
|
135
|
+
outputPath: ${{ steps.zip.output.path }}
|
|
122
136
|
```
|
|
123
137
|
|
|
124
|
-
###
|
|
138
|
+
### Sleep - `roadiehq:utils:sleep`
|
|
139
|
+
|
|
140
|
+
Waits a number of seconds before continuing to the next scaffolder step.
|
|
141
|
+
|
|
142
|
+
_Required params:_
|
|
143
|
+
|
|
144
|
+
- amount: Number of seconds to sleep
|
|
125
145
|
|
|
126
146
|
```yaml
|
|
127
147
|
---
|
|
@@ -151,75 +171,14 @@ spec:
|
|
|
151
171
|
path: ${{ parameters.amount }}
|
|
152
172
|
```
|
|
153
173
|
|
|
154
|
-
###
|
|
174
|
+
### Deserialise - `roadiehq:utils:fs:parse`
|
|
155
175
|
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
apiVersion: scaffolder.backstage.io/v1beta3
|
|
159
|
-
kind: Template
|
|
160
|
-
metadata:
|
|
161
|
-
name: create-file-template
|
|
162
|
-
title: Create File template
|
|
163
|
-
description: Example template to create a file with on the given path with the given content in the workspace.
|
|
164
|
-
spec:
|
|
165
|
-
owner: roadie
|
|
166
|
-
type: service
|
|
176
|
+
This action deserialises json or yaml files in the temporary scaffolder workspace to a javascript object in memory that can then be passed to another step.
|
|
167
177
|
|
|
168
|
-
|
|
169
|
-
- title: Create File
|
|
170
|
-
properties:
|
|
171
|
-
path:
|
|
172
|
-
title: Path
|
|
173
|
-
type: string
|
|
174
|
-
description: The path to the desired new file
|
|
175
|
-
content:
|
|
176
|
-
title: Content
|
|
177
|
-
type: string
|
|
178
|
-
description: The content of the newly created file
|
|
179
|
-
steps:
|
|
180
|
-
- id: writeFile
|
|
181
|
-
name: Create File
|
|
182
|
-
action: roadiehq:utils:fs:write
|
|
183
|
-
input:
|
|
184
|
-
path: ${{ parameters.path }}
|
|
185
|
-
content: ${{ parameters.content }}
|
|
186
|
-
```
|
|
178
|
+
Required params:
|
|
187
179
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
```yaml
|
|
191
|
-
---
|
|
192
|
-
apiVersion: scaffolder.backstage.io/v1beta3
|
|
193
|
-
kind: Template
|
|
194
|
-
metadata:
|
|
195
|
-
name: append-file-template
|
|
196
|
-
title: Append To File template
|
|
197
|
-
description: Example template to append to a file with on the given path with the given content in the workspace.
|
|
198
|
-
spec:
|
|
199
|
-
owner: roadie
|
|
200
|
-
type: service
|
|
201
|
-
|
|
202
|
-
parameters:
|
|
203
|
-
- title: Append To File
|
|
204
|
-
properties:
|
|
205
|
-
path:
|
|
206
|
-
title: Path
|
|
207
|
-
type: string
|
|
208
|
-
description: The path to the file
|
|
209
|
-
content:
|
|
210
|
-
title: Content
|
|
211
|
-
type: string
|
|
212
|
-
description: The content to append to the file
|
|
213
|
-
steps:
|
|
214
|
-
- id: appendFile
|
|
215
|
-
name: Append To File
|
|
216
|
-
action: roadiehq:utils:fs:append
|
|
217
|
-
input:
|
|
218
|
-
path: ${{ parameters.path }}
|
|
219
|
-
content: ${{ parameters.content }}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
### Example of using parseFile action
|
|
180
|
+
- path: The path to the file in the temporary scaffolder workspace that you want to de-serialaise
|
|
181
|
+
- parser: The type of content found in the file you want to de-serialise
|
|
223
182
|
|
|
224
183
|
```yaml
|
|
225
184
|
---
|
|
@@ -256,10 +215,14 @@ spec:
|
|
|
256
215
|
path: ${{ parameters.path }}
|
|
257
216
|
parser: ${{ parameters.parser }}
|
|
258
217
|
output:
|
|
259
|
-
|
|
218
|
+
content: ${{ steps.serialize.output.content }}
|
|
260
219
|
```
|
|
261
220
|
|
|
262
|
-
###
|
|
221
|
+
### Parse JSON - `roadiehq:utils:jsonata`
|
|
222
|
+
|
|
223
|
+
This action allows you to parse a file in your workspace or output from a previous step and extract values from Json to output or use in subsequent actions.
|
|
224
|
+
|
|
225
|
+
This action uses [Jsonata](https://jsonata.org/) to parse Json. You can test Jsonata expressions [here](https://try.jsonata.org/) while writing your template.
|
|
263
226
|
|
|
264
227
|
```yaml
|
|
265
228
|
---
|
|
@@ -284,10 +247,10 @@ spec:
|
|
|
284
247
|
- item1
|
|
285
248
|
expression: '$ ~> | $ | { "items": [items, "item2"] }|'
|
|
286
249
|
output:
|
|
287
|
-
|
|
250
|
+
result: ${{ steps.serialize.output.result }}
|
|
288
251
|
```
|
|
289
252
|
|
|
290
|
-
|
|
253
|
+
Transform a JSON file:
|
|
291
254
|
|
|
292
255
|
```yaml
|
|
293
256
|
---
|
|
@@ -310,10 +273,10 @@ spec:
|
|
|
310
273
|
path: input-data.jaon
|
|
311
274
|
expression: '$ ~> | $ | { "items": [items, "item2"] }|'
|
|
312
275
|
output:
|
|
313
|
-
|
|
276
|
+
result: ${{ steps.serialize.output.result }}
|
|
314
277
|
```
|
|
315
278
|
|
|
316
|
-
|
|
279
|
+
Transform a YAML file:
|
|
317
280
|
|
|
318
281
|
```yaml
|
|
319
282
|
---
|
|
@@ -336,10 +299,110 @@ spec:
|
|
|
336
299
|
path: input-data.yaml
|
|
337
300
|
expression: '$ ~> | $ | { "items": [items, "item2"] }|'
|
|
338
301
|
output:
|
|
339
|
-
|
|
302
|
+
result: ${{ steps.serialize.output.result }}
|
|
340
303
|
```
|
|
341
304
|
|
|
342
|
-
###
|
|
305
|
+
### Write - `roadiehq:utils:fs:write`
|
|
306
|
+
|
|
307
|
+
This action writes a string to a temporary file in the scaffolder workspace.
|
|
308
|
+
|
|
309
|
+
_Required params:_
|
|
310
|
+
|
|
311
|
+
- path: The file path you want to save your new file at in the workspace.
|
|
312
|
+
- content: The string content you want to write.
|
|
313
|
+
|
|
314
|
+
```yaml
|
|
315
|
+
---
|
|
316
|
+
apiVersion: scaffolder.backstage.io/v1beta3
|
|
317
|
+
kind: Template
|
|
318
|
+
metadata:
|
|
319
|
+
name: create-file-template
|
|
320
|
+
title: Create File template
|
|
321
|
+
description: Example template to create a file with on the given path with the given content in the workspace.
|
|
322
|
+
spec:
|
|
323
|
+
owner: roadie
|
|
324
|
+
type: service
|
|
325
|
+
|
|
326
|
+
parameters:
|
|
327
|
+
- title: Create File
|
|
328
|
+
properties:
|
|
329
|
+
path:
|
|
330
|
+
title: Path
|
|
331
|
+
type: string
|
|
332
|
+
description: The path to the desired new file
|
|
333
|
+
content:
|
|
334
|
+
title: Content
|
|
335
|
+
type: string
|
|
336
|
+
description: The content of the newly created file
|
|
337
|
+
steps:
|
|
338
|
+
- id: writeFile
|
|
339
|
+
name: Create File
|
|
340
|
+
action: roadiehq:utils:fs:write
|
|
341
|
+
input:
|
|
342
|
+
path: ${{ parameters.path }}
|
|
343
|
+
content: ${{ parameters.content }}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Append - `roadiehq:utils:fs:append`
|
|
347
|
+
|
|
348
|
+
This action adds content to the end of an existing file or creates a new one if it doesn't already exist.
|
|
349
|
+
|
|
350
|
+
_Required params:_
|
|
351
|
+
|
|
352
|
+
- path: The path of the file you want to add content to in the workspace.
|
|
353
|
+
- content: The string content you want to append.
|
|
354
|
+
|
|
355
|
+
```yaml
|
|
356
|
+
---
|
|
357
|
+
apiVersion: scaffolder.backstage.io/v1beta3
|
|
358
|
+
kind: Template
|
|
359
|
+
metadata:
|
|
360
|
+
name: append-file-template
|
|
361
|
+
title: Append To File template
|
|
362
|
+
description: Example template to append to a file with on the given path with the given content in the workspace.
|
|
363
|
+
spec:
|
|
364
|
+
owner: roadie
|
|
365
|
+
type: service
|
|
366
|
+
|
|
367
|
+
parameters:
|
|
368
|
+
- title: Append To File
|
|
369
|
+
properties:
|
|
370
|
+
path:
|
|
371
|
+
title: Path
|
|
372
|
+
type: string
|
|
373
|
+
description: The path to the file
|
|
374
|
+
content:
|
|
375
|
+
title: Text area input
|
|
376
|
+
type: string
|
|
377
|
+
description: Add your new entity
|
|
378
|
+
ui:widget: textarea
|
|
379
|
+
ui:options:
|
|
380
|
+
rows: 10
|
|
381
|
+
ui:help: 'Make sure it is valid by checking the schema at `/tools/entity-preview`'
|
|
382
|
+
ui:placeholder: |
|
|
383
|
+
---
|
|
384
|
+
apiVersion: backstage.io/v1alpha1
|
|
385
|
+
kind: Component
|
|
386
|
+
metadata:
|
|
387
|
+
name: backstage
|
|
388
|
+
spec:
|
|
389
|
+
type: library
|
|
390
|
+
owner: CNCF
|
|
391
|
+
lifecycle: experimental
|
|
392
|
+
steps:
|
|
393
|
+
- id: appendFile
|
|
394
|
+
name: Append To File
|
|
395
|
+
action: roadiehq:utils:fs:append
|
|
396
|
+
input:
|
|
397
|
+
path: ${{ parameters.path }}
|
|
398
|
+
content: ${{ parameters.content }}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Serialise to json or yaml - `roadiehq:utils:serialize:[json|yaml]`
|
|
402
|
+
|
|
403
|
+
This action creates a json or yaml formatted string representation of key value pairs written in yaml under the data input field.
|
|
404
|
+
|
|
405
|
+
#### To yaml:
|
|
343
406
|
|
|
344
407
|
```yaml
|
|
345
408
|
---
|
|
@@ -362,10 +425,25 @@ spec:
|
|
|
362
425
|
data:
|
|
363
426
|
hello: world
|
|
364
427
|
output:
|
|
365
|
-
|
|
428
|
+
yaml: ${{ steps.serialize.output.serialized }}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
// input:
|
|
432
|
+
|
|
433
|
+
```js
|
|
434
|
+
{
|
|
435
|
+
hello: 'world';
|
|
436
|
+
}
|
|
366
437
|
```
|
|
367
438
|
|
|
368
|
-
|
|
439
|
+
// output:
|
|
440
|
+
|
|
441
|
+
```yaml
|
|
442
|
+
---
|
|
443
|
+
hello: world
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
#### To JSON:
|
|
369
447
|
|
|
370
448
|
```yaml
|
|
371
449
|
---
|
|
@@ -388,5 +466,15 @@ spec:
|
|
|
388
466
|
data:
|
|
389
467
|
hello: world
|
|
390
468
|
output:
|
|
391
|
-
|
|
469
|
+
json: ${{ steps.serialize.output.serialized }}
|
|
392
470
|
```
|
|
471
|
+
|
|
472
|
+
// input:
|
|
473
|
+
|
|
474
|
+
```js
|
|
475
|
+
{
|
|
476
|
+
hello: 'world';
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
// output: `"\"hello\": \"world\""`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roadiehq/scaffolder-backend-module-utils",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"clean": "backstage-cli clean"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@backstage/backend-common": "^0.
|
|
35
|
-
"@backstage/config": "^1.0.
|
|
36
|
-
"@backstage/errors": "^1.1.
|
|
37
|
-
"@backstage/plugin-scaffolder-backend": "^1.
|
|
34
|
+
"@backstage/backend-common": "^0.17.0",
|
|
35
|
+
"@backstage/config": "^1.0.5",
|
|
36
|
+
"@backstage/errors": "^1.1.4",
|
|
37
|
+
"@backstage/plugin-scaffolder-backend": "^1.9.0",
|
|
38
38
|
"adm-zip": "^0.5.9",
|
|
39
39
|
"cross-fetch": "^3.1.4",
|
|
40
40
|
"fs-extra": "^10.0.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"winston": "^3.2.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@backstage/cli": "^0.
|
|
47
|
+
"@backstage/cli": "^0.22.0",
|
|
48
48
|
"@types/adm-zip": "^0.4.34",
|
|
49
49
|
"@types/fs-extra": "^9.0.13",
|
|
50
50
|
"@types/jest": "^26.0.7",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"files": [
|
|
56
56
|
"dist"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "e86b8f5169879a363707eb05172e462335c9fb41"
|
|
59
59
|
}
|