Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 6901ca2

Browse files
authored
Add markup file for hld command (#513)
1 parent 6b653ee commit 6901ca2

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

docs/commands/data.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@
236236
"hld append-variable-group": {
237237
"command": "append-variable-group <variable-group-name>",
238238
"alias": "avg",
239-
"description": "Appends the name of an existing variable group to the current manifest-generation.yaml file."
239+
"description": "Appends the name of an existing variable group to the current manifest-generation.yaml file.",
240+
"markdown": "## Description\n\nAppend a variable group name to the current `manifest-generation.yaml` of an\ninitialized hld repository.\n\n## Example\n\nWhen an HLD repository is first initialized with `spk hld init`, the top portion\nof the `manifest-generation.yaml` looks like this:\n\n```yaml\n# GENERATED WITH SPK VERSION 0.5.8\ntrigger:\n branches:\n include:\n - master\nvariables: []\npool:\n vmImage: ubuntu-latest\nsteps:\n.\n.\n.\n```\n\nrunning `spk hld append-variable-group my-vg` with a variable group name, in\nthis case `my-vg`, will add it under the `variables` section if it does not\nalready exist:\n\n```yaml\n# GENERATED WITH SPK VERSION 0.5.8\ntrigger:\n branches:\n include:\n - master\nvariables:\n - group: my-variable-group\npool:\n vmImage: ubuntu-latest\nsteps:\n.\n.\n.\n```\n"
240241
},
241242
"hld init": {
242243
"command": "init",
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## Description
2+
3+
Append a variable group name to the current `manifest-generation.yaml` of an
4+
initialized hld repository.
5+
6+
## Example
7+
8+
When an HLD repository is first initialized with `spk hld init`, the top portion
9+
of the `manifest-generation.yaml` looks like this:
10+
11+
```yaml
12+
# GENERATED WITH SPK VERSION 0.5.8
13+
trigger:
14+
branches:
15+
include:
16+
- master
17+
variables: []
18+
pool:
19+
vmImage: ubuntu-latest
20+
steps:
21+
.
22+
.
23+
.
24+
```
25+
26+
running `spk hld append-variable-group my-vg` with a variable group name, in
27+
this case `my-vg`, will add it under the `variables` section if it does not
28+
already exist:
29+
30+
```yaml
31+
# GENERATED WITH SPK VERSION 0.5.8
32+
trigger:
33+
branches:
34+
include:
35+
- master
36+
variables:
37+
- group: my-variable-group
38+
pool:
39+
vmImage: ubuntu-latest
40+
steps:
41+
.
42+
.
43+
.
44+
```

src/lib/fileutils.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,23 @@ export const appendVariableGroupToPipelineYaml = (
496496
path.join(dir, fileName)
497497
) as AzurePipelinesYaml;
498498
pipelineFile.variables = pipelineFile.variables || [];
499+
let variableGroupExists = false;
500+
501+
pipelineFile.variables.forEach((variable) => {
502+
if ("group" in variable && variable.group === variableGroupName) {
503+
variableGroupExists = true;
504+
logger.info(
505+
`Variable group '${variableGroupName}' already exits in '${dir}/${fileName}'.`
506+
);
507+
}
508+
});
499509

500-
pipelineFile.variables.push({ group: variableGroupName });
510+
if (!variableGroupExists) {
511+
pipelineFile.variables.push({ group: variableGroupName });
501512

502-
logger.info(`Updating '${dir}/${fileName}'.`);
503-
write(pipelineFile, dir, fileName);
513+
logger.info(`Updating '${dir}/${fileName}'.`);
514+
write(pipelineFile, dir, fileName);
515+
}
504516
} catch (err) {
505517
throw buildError(
506518
errorStatusCode.FILE_IO_ERR,

0 commit comments

Comments
 (0)