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

Commit

Permalink
Add markup file for hld command (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
edaena authored Apr 7, 2020
1 parent 6b653ee commit 6901ca2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@
"hld append-variable-group": {
"command": "append-variable-group <variable-group-name>",
"alias": "avg",
"description": "Appends the name of an existing variable group to the current manifest-generation.yaml file."
"description": "Appends the name of an existing variable group to the current manifest-generation.yaml file.",
"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"
},
"hld init": {
"command": "init",
Expand Down
44 changes: 44 additions & 0 deletions src/commands/hld/append-variable-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Description

Append a variable group name to the current `manifest-generation.yaml` of an
initialized hld repository.

## Example

When an HLD repository is first initialized with `spk hld init`, the top portion
of the `manifest-generation.yaml` looks like this:

```yaml
# GENERATED WITH SPK VERSION 0.5.8
trigger:
branches:
include:
- master
variables: []
pool:
vmImage: ubuntu-latest
steps:
.
.
.
```

running `spk hld append-variable-group my-vg` with a variable group name, in
this case `my-vg`, will add it under the `variables` section if it does not
already exist:

```yaml
# GENERATED WITH SPK VERSION 0.5.8
trigger:
branches:
include:
- master
variables:
- group: my-variable-group
pool:
vmImage: ubuntu-latest
steps:
.
.
.
```
18 changes: 15 additions & 3 deletions src/lib/fileutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,23 @@ export const appendVariableGroupToPipelineYaml = (
path.join(dir, fileName)
) as AzurePipelinesYaml;
pipelineFile.variables = pipelineFile.variables || [];
let variableGroupExists = false;

pipelineFile.variables.forEach((variable) => {
if ("group" in variable && variable.group === variableGroupName) {
variableGroupExists = true;
logger.info(
`Variable group '${variableGroupName}' already exits in '${dir}/${fileName}'.`
);
}
});

pipelineFile.variables.push({ group: variableGroupName });
if (!variableGroupExists) {
pipelineFile.variables.push({ group: variableGroupName });

logger.info(`Updating '${dir}/${fileName}'.`);
write(pipelineFile, dir, fileName);
logger.info(`Updating '${dir}/${fileName}'.`);
write(pipelineFile, dir, fileName);
}
} catch (err) {
throw buildError(
errorStatusCode.FILE_IO_ERR,
Expand Down

0 comments on commit 6901ca2

Please sign in to comment.