Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions build/pack.cake
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ Task("Build")
.IsDependentOn("Clean")
.Does<BuildParameters>((parameters) =>
{
// build .Net code
Build(parameters.Configuration);

var workDir = "./src/GitVersionVsixTask";
// build typescript code
NpmSet(new NpmSetSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, Key = "progress", Value = "false" });
NpmInstall(new NpmInstallSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent });
NpmRunScript(new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "build" });
});

#endregion
Expand All @@ -32,6 +39,7 @@ Task("Test")
.Does<BuildParameters>((parameters) =>
{
var frameworks = new[] { parameters.CoreFxVersion, parameters.FullFxVersion };
var testResultsPath = parameters.Paths.Directories.TestResultsOutput;

foreach(var framework in frameworks)
{
Expand All @@ -42,7 +50,6 @@ Task("Test")
{
actions.Add(() =>
{
var testResultsPath = parameters.Paths.Directories.TestResultsOutput + "/";
var projectName = $"{project.GetFilenameWithoutExtension()}.{framework}";
var settings = new DotNetCoreTestSettings {
Framework = framework,
Expand All @@ -53,7 +60,8 @@ Task("Test")

if (!parameters.IsRunningOnMacOS) {
settings.TestAdapterPath = new DirectoryPath(".");
settings.Logger = $"nunit;LogFilePath={MakeAbsolute(new FilePath($"{testResultsPath}{projectName}.results.xml"))}";
var resultsPath = MakeAbsolute(testResultsPath.CombineWithFilePath($"{projectName}.results.xml"));
settings.Logger = $"nunit;LogFilePath={resultsPath}";
}

var coverletSettings = new CoverletSettings {
Expand All @@ -80,6 +88,12 @@ Task("Test")

Parallel.Invoke(options, actions.ToArray());
}

var workDir = "./src/GitVersionVsixTask";
var npmSettings = new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "test" };
var vsixResultsPath = MakeAbsolute(testResultsPath.CombineWithFilePath("vsix.results.xml"));
npmSettings.Arguments.Add($"--reporter-options mochaFile={vsixResultsPath}");
NpmRunScript(npmSettings);
})
.ReportError(exception =>
{
Expand Down Expand Up @@ -204,9 +218,6 @@ Task("Pack-Vsix")
UpdateTaskVersion(new FilePath(workDir + "/GitVersionTask/task.json"), taskId, parameters.Version.GitVersion);

// build and pack
NpmSet(new NpmSetSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, Key = "progress", Value = "false" });
NpmInstall(new NpmInstallSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent });
NpmRunScript(new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "build" });

var settings = new TfxExtensionCreateSettings
{
Expand Down
75 changes: 48 additions & 27 deletions src/GitVersionVsixTask/GitVersion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import tl = require('azure-pipelines-task-lib/task');
import tr = require('azure-pipelines-task-lib/toolrunner');
import path = require('path');
import os = require('os');
import * as path from 'path';
import * as os from 'os';

import * as tl from 'azure-pipelines-task-lib/task';
import * as tr from 'azure-pipelines-task-lib/toolrunner';

export class GitVersionTask {
execOptions: tr.IExecOptions;
Expand All @@ -15,31 +16,26 @@ export class GitVersionTask {
additionalArguments: string;
targetPath: string;
sourcesDirectory: string;
currentDirectory: string;
workingDirectory: string;
gitVersionPath: string;
runtime: string;

constructor() {
this.preferBundledVersion = tl.getBoolInput('preferBundledVersion') || true;

this.targetPath = tl.getInput('targetPath');

this.useConfigFile = tl.getBoolInput('useConfigFile');
this.configFilePath = tl.getInput('configFilePath');

this.updateAssemblyInfo = tl.getBoolInput('updateAssemblyInfo');
this.updateAssemblyInfoFilename = tl.getInput('updateAssemblyInfoFilename');

this.additionalArguments = tl.getInput('additionalArguments');
this.targetPath = tl.getInput('targetPath');
this.runtime = tl.getInput('runtime') || "core";
this.preferBundledVersion = tl.getBoolInput('preferBundledVersion');
this.runtime = tl.getInput('runtime') || 'core';
this.gitVersionPath = tl.getInput('gitVersionPath');

this.sourcesDirectory = tl.getVariable("Build.SourcesDirectory");
this.additionalArguments = tl.getInput('additionalArguments');

this.currentDirectory = __dirname;
this.workingDirectory = !this.targetPath
? this.sourcesDirectory
: path.join(this.sourcesDirectory, this.targetPath);
this.sourcesDirectory = tl.getVariable('Build.SourcesDirectory').replace(/\\/g, '/');

this.execOptions = {
cwd: undefined,
Expand All @@ -55,9 +51,10 @@ export class GitVersionTask {

public async execute() {
try {
let workingDirectory = this.getWorkingDirectory(this.targetPath);
let exe = this.getExecutable();
exe.arg([
this.workingDirectory,
workingDirectory,
"/output",
"buildserver",
"/nofetch"]);
Expand All @@ -67,7 +64,7 @@ export class GitVersionTask {
exe.arg(["/config", this.configFilePath]);
}
else {
throw 'GitVersion configuration file not found at ' + this.configFilePath;
throw new Error('GitVersion configuration file not found at ' + this.configFilePath);
}
}

Expand All @@ -77,7 +74,7 @@ export class GitVersionTask {
exe.arg(this.updateAssemblyInfoFilename);
}
else {
throw 'AssemblyInfoFilename file not found at ' + this.updateAssemblyInfoFilename;
throw new Error('AssemblyInfoFilename file not found at ' + this.updateAssemblyInfoFilename);
}
}

Expand All @@ -87,14 +84,14 @@ export class GitVersionTask {

const result = await exe.exec(this.execOptions);
if (result) {
tl.setResult(tl.TaskResult.Failed, "An error occured during GitVersion execution")
tl.setResult(tl.TaskResult.Failed, "An error occured during GitVersion execution");
} else {
tl.setResult(tl.TaskResult.Succeeded, "GitVersion executed successfully")
tl.setResult(tl.TaskResult.Succeeded, "GitVersion executed successfully");
}
}
catch (err) {
tl.debug(err.stack);
tl.setResult(tl.TaskResult.Failed, err);
tl.setResult(tl.TaskResult.Failed, err, true);
}
}

Expand Down Expand Up @@ -124,13 +121,37 @@ export class GitVersionTask {
}

public getExecutablePath(exeName:string) {
if (this.gitVersionPath){
return this.gitVersionPath;
} else if (this.preferBundledVersion) {
return path.join(this.currentDirectory, this.runtime, exeName);
let exePath;
if (this.preferBundledVersion) {
let currentDirectory = __dirname;
exePath = path.join(currentDirectory, this.runtime, exeName);
} else {
if (tl.filePathSupplied('gitVersionPath') && tl.exist(this.gitVersionPath) && tl.stats(this.gitVersionPath).isFile()) {
exePath = this.gitVersionPath;
} else{
throw new Error('GitVersion executable not found at ' + this.gitVersionPath);
}
}

return exePath.replace(/\\/g, '/');
}

public getWorkingDirectory(targetPath: string) {
let workDir;

if (!targetPath){
workDir = this.sourcesDirectory;
} else {
if (tl.exist(targetPath) && tl.stats(targetPath).isDirectory()) {
workDir = path.join(this.sourcesDirectory, targetPath);
}
else {
throw new Error('Directory not found at ' + targetPath);
}
}
return workDir.replace(/\\/g, '/');
}
}

var exe = new GitVersionTask();
exe.execute().catch((reason) => tl.setResult(tl.TaskResult.Failed, reason));
var task = new GitVersionTask();
task.execute().catch((reason) => tl.setResult(tl.TaskResult.Failed, reason));
146 changes: 74 additions & 72 deletions src/GitVersionVsixTask/GitVersionTask/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,83 +25,85 @@
}],
"instanceNameFormat": "GitVersion",
"inputs": [{
"name": "runtime",
"type": "radio",
"label": "Runtime",
"defaultValue": "core",
"required": true,
"options": {
"core": "dotnet core",
"full": "dotnet fullframework (or mono)"
"name": "runtime",
"type": "radio",
"label": "Runtime",
"defaultValue": "core",
"required": true,
"options": {
"core": "dotnet core",
"full": "dotnet fullframework (or mono)"
},
"helpMarkDown": "Specify the runtime used for running the tool"
}, {
"name": "preferBundledVersion",
"type": "boolean",
"label": "Prefer bundled GitVersion",
"defaultValue": "true",
"required": false,
"helpMarkDown": "If checked it will prefer the bundled version over a version found in path"
}, {
"name": "gitVersionPath",
"type": "string",
"label": "Path to GitVersion",
"defaultValue": "",
"required": false,
"helpMarkDown": "Optionally supply the path to GitVersion",
"visibleRule": "preferBundledVersion = true"
},
"helpMarkDown": "Specify the runtime used for running the tool"
}, {
"name": "preferBundledVersion",
"type": "boolean",
"label": "Prefer bundled GitVersion",
"defaultValue": "true",
"required": false,
"helpMarkDown": "If checked it will prefer the bundled version over a version found in path"
}, {
"name": "useConfigFile",
"type": "boolean",
"label": "Specify Configuration file",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Whether to use a custom configuration file"
}, {
"name": "configFilePath",
"type": "filePath",
"label": "Configuration file",
"defaultValue": "",
"required": false,
"helpMarkDown": "Optional path to config file (defaults to GitVersion.yml)",
"visibleRule": "useConfigFile = true"
}, {
"name": "updateAssemblyInfo",
"type": "boolean",
"label": "Update AssemblyInfo files",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Whether to update versions in the AssemblyInfo files"
}, {
"name": "updateAssemblyInfoFilename",
"type": "string",
"label": "Update Assembly File",
"defaultValue": "",
"required": false,
"helpMarkDown": "Update versions in specified file",
"visibleRule": "updateAssemblyInfo = true"
}, {
"name": "gitVersionPath",
"type": "string",
"label": "Path to GitVersion",
"defaultValue": "",
"required": false,
"helpMarkDown": "Optionally supply the path to GitVersion",
"groupName": "gitversionDetails"
}, {
"name": "targetPath",
"type": "string",
"label": "Working directory path",
"defaultValue": "",
"required": false,
"helpMarkDown": "Optionally supply the path to the working directory",
"groupName": "gitversionDetails"
}, {
"name": "additionalArguments",
"type": "string",
"label": "Additional GitVersion arguments",
"defaultValue": "",
"required": false,
"helpMarkDown": "Additional arguments to send to GitVersion",
"groupName": "additional"
}],
{
"name": "useConfigFile",
"type": "boolean",
"label": "Specify Configuration file",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Whether to use a custom configuration file"
}, {
"name": "configFilePath",
"type": "filePath",
"label": "Configuration file",
"defaultValue": "",
"required": false,
"helpMarkDown": "Optional path to config file (defaults to GitVersion.yml)",
"visibleRule": "useConfigFile = true"
}, {
"name": "updateAssemblyInfo",
"type": "boolean",
"label": "Update AssemblyInfo files",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Whether to update versions in the AssemblyInfo files"
}, {
"name": "updateAssemblyInfoFilename",
"type": "string",
"label": "Update Assembly File",
"defaultValue": "",
"required": false,
"helpMarkDown": "Update versions in specified file",
"visibleRule": "updateAssemblyInfo = true"
}, {
"name": "targetPath",
"type": "string",
"label": "Working directory path",
"defaultValue": "",
"required": false,
"helpMarkDown": "Optionally supply the path to the working directory",
"groupName": "gitversionDetails"
}, {
"name": "additionalArguments",
"type": "string",
"label": "Additional GitVersion arguments",
"defaultValue": "",
"required": false,
"helpMarkDown": "Additional arguments to send to GitVersion",
"groupName": "additional"
}
],
"execution": {
"Node": {
"target": "GitVersion.js",
"argumentFormat": "",
"workingDirectory": "."
}
}
}
}
Loading