Skip to content

Commit

Permalink
Fix various issues with passing of parameters to the CLI (#14)
Browse files Browse the repository at this point in the history
This fixes a couple of issues where parameters that were set on the Augurk CLI task were not being passed onto the Augurk CLI itself, causing them to not have any effect.

Co-authored-by: Jonathan Mezach <[email protected]>

+semver: patch
  • Loading branch information
Mobrockers authored and Jonathan Mezach committed Jan 17, 2020
1 parent 7815524 commit e258331
Show file tree
Hide file tree
Showing 18 changed files with 188 additions and 70 deletions.
10 changes: 7 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
# https://aka.ms/yaml

pool:
vmImage: 'VS2017-Win2016'
vmImage: 'ubuntu-18.04'

steps:
- task: GitVersion@4
- task: GitVersion@5
inputs:
useConfigFile: true
configFilePath: '$(Build.SourcesDirectory)/GitVersion.yml'

- task: NodeTool@0
inputs:
versionSpec: '8.x'
versionSpec: '10.x'

- bash: |
npm install -g typescript
Expand Down
4 changes: 3 additions & 1 deletion src/build-task/AugurkCLI/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function buildBaseToolRunner(command: string): ToolRunner {
const augurkUrl = tl.getEndpointUrl(endpoint, false);
const productName = tl.getInput("productName", true);
const groupName = tl.getInput("groupName", false);
const additionalArguments = tl.getInput("additionalArguments", false);

// Discover the location of the CLI and make sure it is available
const cliPath = tl.which('augurk', true);
Expand All @@ -45,7 +46,8 @@ export function buildBaseToolRunner(command: string): ToolRunner {
.arg(command)
.arg(["--url", augurkUrl])
.arg(["--productName", productName])
.argIf(groupName, ["--groupName", groupName]);
.argIf(groupName, ["--groupName", groupName])
.argIf(additionalArguments, additionalArguments);
}

run();
24 changes: 12 additions & 12 deletions src/build-task/AugurkCLI/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/build-task/AugurkCLI/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "An Azure DevOps (Server) build task that invokes Augurk's CLI",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "tsc && mocha tests/_suite.js"
},
"repository": {
"type": "git",
Expand All @@ -17,11 +17,11 @@
},
"homepage": "https://github.com/augurk/vsts-extension#readme",
"dependencies": {
"azure-pipelines-task-lib": "^2.8.0"
"azure-pipelines-task-lib": "2.8.0"
},
"devDependencies": {
"@types/mocha": "^5.2.6",
"@types/node": "^10.14.5",
"@types/mocha": "^5.2.7",
"@types/node": "^10.17.13",
"@types/q": "^1.5.2"
}
}
13 changes: 9 additions & 4 deletions src/build-task/AugurkCLI/publishCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import path = require('path');
import { buildBaseToolRunner } from './cli';

export async function publishCommand() {
// Get the configured version
const version = tl.getInput('version', false);

// Find the feature files we're going to publish
const features = tl.getPathInput('features', true);
const featureFiles = tl.findMatch(process.cwd(), features);
Expand All @@ -22,13 +25,13 @@ export async function publishCommand() {

// Check whether we should use the folder structure
if (tl.getBoolInput('useFolderStructure', true)) {
await publishUsingFolderStructure(featureFiles, productDescription);
await publishUsingFolderStructure(version, featureFiles, productDescription);
} else {
await publishIndividualGroup(featureFiles, productDescription);
await publishIndividualGroup(version, featureFiles, productDescription);
}
}

async function publishUsingFolderStructure(featureFiles: string[], productDescription: string | null) {
async function publishUsingFolderStructure(version: string | null, featureFiles: string[], productDescription: string | null) {
// Group the found files by their parent directory
const groupedFeatures = featureFiles.reduce<{ [index: string]: string[] }>((groups, item) => {
const parent = path.dirname(item).split(path.sep).pop() as string;
Expand All @@ -42,6 +45,7 @@ async function publishUsingFolderStructure(featureFiles: string[], productDescri
const publishCommand = buildBaseToolRunner("publish");
publishCommand.arg(['--featureFiles', groupedFeatures[key].join(',')]);
publishCommand.arg(['--groupName', key]);
publishCommand.argIf(version != null, ['--version', version]);
publishCommand.argIf(productDescription != null, ['--productDesc', productDescription]);

const publishResult = await publishCommand.exec();
Expand All @@ -54,9 +58,10 @@ async function publishUsingFolderStructure(featureFiles: string[], productDescri
}
}

async function publishIndividualGroup(featureFiles: string[], productDescription: string | null) {
async function publishIndividualGroup(version: string | null, featureFiles: string[], productDescription: string | null) {
const publishCommand = buildBaseToolRunner('publish');
publishCommand.arg(['--featureFiles', featureFiles.join(',')]);
publishCommand.argIf(version != null, ['--version', version]);
publishCommand.argIf(productDescription != null, ['--productDesc', productDescription]);

const publishResult = await publishCommand.exec();
Expand Down
2 changes: 1 addition & 1 deletion src/build-task/AugurkCLI/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"version": {
"Major": 0,
"Minor": 3,
"Patch": 6
"Patch": 8
},
"demands": [
"augurk-cli"
Expand Down
26 changes: 26 additions & 0 deletions src/build-task/AugurkCLI/tests/_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ describe('Augurk CLI Task', function () {
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});

it ('should succesfully publish with a version', function(done: MochaDone) {
this.timeout(1000);

let tp = path.join(__dirname, 'publish-version.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();
assert.equal(tr.succeeded, true, "should have succeeded");
assert.equal(tr.warningIssues.length, 0, "should have no warnings");
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});

it('should succesfully publish an individual group', function(done: MochaDone) {
this.timeout(1000);
Expand All @@ -31,6 +44,19 @@ describe('Augurk CLI Task', function () {
done();
});

it('should succesfully publish with additional arguments', function() {
this.timeout(1000);

let tp = path.join(__dirname, 'publish-additional-arguments.js');
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);

tr.run();
assert.deepEqual(tr.errorIssues, []);
assert.equal(tr.succeeded, true, 'should have succeeded');
assert.equal(tr.warningIssues.length, 0, "should have no warnings");
assert.equal(tr.errorIssues.length, 0, "should have no errors");
});

it('logs warning if multiple product descriptions found', function(done: MochaDone) {
this.timeout(1000);

Expand Down
37 changes: 37 additions & 0 deletions src/build-task/AugurkCLI/tests/publish-additional-arguments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'cli.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tmr.setInput('command', 'publish');
tmr.setInput('features', '**/*.feature');
tmr.setInput('augurkInstance', 'SomeAugurkInstance');
tmr.setInput('productName', 'Augurk');
tmr.setInput('includeProductDescription', 'false');
tmr.setInput('useFolderStructure', 'true');

tmr.setInput('additionalArguments', '--useIntegratedSecurity --compat-level 3 --productDesc product-description.md')

process.env["ENDPOINT_URL_SomeAugurkInstance"] = "https://some.augurk.instance";

tmr.setAnswers({
findMatch: {
"**/*.feature": [
"Configuration/RetentionPolicy.feature"
]
},
which: {
"augurk": "/some/path/to/augurk"
},
checkPath: {
"/some/path/to/augurk": true
},
exec: {
"/some/path/to/augurk publish --url https://some.augurk.instance --productName Augurk --useIntegratedSecurity --compat-level 3 --productDesc product-description.md --featureFiles Configuration/RetentionPolicy.feature --groupName Configuration": {
code: 0,
}
}
});

tmr.run();
44 changes: 44 additions & 0 deletions src/build-task/AugurkCLI/tests/publish-version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import tmrm = require('azure-pipelines-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'cli.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tmr.setInput('command', 'publish');
tmr.setInput('features', '**/*.feature');
tmr.setInput('augurkInstance', 'SomeAugurkInstance');
tmr.setInput('productName', 'Augurk');
tmr.setInput('useFolderStructure', 'true');
tmr.setInput('version', '1.0.0');
tmr.setInput('includeProductDescription', 'true');
tmr.setInput('productDescription', 'product-description.md');

process.env["ENDPOINT_URL_SomeAugurkInstance"] = "https://some.augurk.instance";

tmr.setAnswers({
findMatch: {
"**/*.feature": [
"Configuration/RetentionPolicy.feature",
"Gherkin/ChildOfTag.feature",
],
"product-description.md": [
"product-description.md"
]
},
which: {
"augurk": "/some/path/to/augurk"
},
checkPath: {
"/some/path/to/augurk": true
},
exec: {
"/some/path/to/augurk publish --url https://some.augurk.instance --productName Augurk --featureFiles Configuration/RetentionPolicy.feature --groupName Configuration --version 1.0.0 --productDesc product-description.md": {
code: 0,
},
"/some/path/to/augurk publish --url https://some.augurk.instance --productName Augurk --featureFiles Gherkin/ChildOfTag.feature --groupName Gherkin --version 1.0.0 --productDesc product-description.md": {
code: 0,
},
}
});

tmr.run();
18 changes: 9 additions & 9 deletions src/build-task/AugurkCLIInstaller/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/build-task/AugurkCLIInstaller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
},
"homepage": "https://github.com/augurk/vsts-extension#readme",
"dependencies": {
"azure-pipelines-task-lib": "^2.7.7",
"azure-pipelines-task-lib": "2.8.0",
"vsts-task-tool-lib": "^0.10.0"
},
"devDependencies": {
"@types/node": "^10.12.15",
"@types/q": "^1.5.1"
"@types/node": "^13.1.7",
"@types/q": "^1.5.2"
}
}
2 changes: 1 addition & 1 deletion src/build-task/AugurkCLIInstaller/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"version": {
"Major": 0,
"Minor": 1,
"Patch": 6
"Patch": 7
},
"capabilities": [
"augurk-cli"
Expand Down
Loading

0 comments on commit e258331

Please sign in to comment.