Skip to content

Commit e2b1836

Browse files
committed
Change the implementation of AzureDevops task.
Change the implementation of AzureDevops task. Instead of embedding the executables, installing GitVersion.Tool with a versionSpec
1 parent 84b4af9 commit e2b1836

File tree

9 files changed

+414
-291
lines changed

9 files changed

+414
-291
lines changed

build/pack.cake

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,6 @@ Task("Copy-Files")
177177
// Commandline
178178
PublishILRepackedGitVersionExe(false, ilMergeDir, cmdlineDir, parameters);
179179

180-
// Vsix
181-
var vsixPath = new DirectoryPath("./src/GitVersionVsixTask/GitVersionTask");
182-
183-
var vsixPathFull = vsixPath.Combine("full");
184-
EnsureDirectoryExists(vsixPathFull);
185-
CopyFileToDirectory(portableDir + "/" + "LibGit2Sharp.dll.config", vsixPathFull);
186-
CopyFileToDirectory(portableDir + "/" + "GitVersion.exe", vsixPathFull);
187-
CopyDirectory(portableDir.Combine("lib"), vsixPathFull.Combine("lib"));
188-
189-
// Vsix dotnet core
190-
var vsixPathCore = vsixPath.Combine("core");
191-
EnsureDirectoryExists(vsixPathCore);
192-
CopyDirectory(coreFxDir, vsixPathCore);
193-
194180
// Ruby Gem
195181
var gemPath = new DirectoryPath("./src/GitVersionRubyGem/bin");
196182
EnsureDirectoryExists(gemPath);
@@ -200,7 +186,7 @@ Task("Copy-Files")
200186
});
201187

202188
Task("Pack-Vsix")
203-
.IsDependentOn("Copy-Files")
189+
.IsDependentOn("Test")
204190
.Does<BuildParameters>((parameters) =>
205191
{
206192
var workDir = "./src/GitVersionVsixTask";

src/GitVersionVsixTask/GitVersion.ts

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
import * as path from 'path';
2-
import * as os from 'os';
32

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

6+
import { ToolInstaller } from './ToolInstaller';
7+
78
export class GitVersionTask {
89
execOptions: tr.IExecOptions;
910

10-
preferBundledVersion: boolean;
11+
versionSpec: string;
12+
includePrerelease: boolean;
13+
targetPath: string;
14+
1115
useConfigFile: boolean;
1216
configFilePath: string;
13-
updateAssemblyInfo: boolean;
1417

18+
updateAssemblyInfo: boolean;
1519
updateAssemblyInfoFilename: string;
20+
1621
additionalArguments: string;
17-
targetPath: string;
22+
1823
sourcesDirectory: string;
19-
gitVersionPath: string;
20-
runtime: string;
2124

2225
constructor() {
2326

27+
this.versionSpec = tl.getInput('versionSpec', true);
28+
this.includePrerelease = tl.getBoolInput('includePrerelease');
2429
this.targetPath = tl.getInput('targetPath');
2530

2631
this.useConfigFile = tl.getBoolInput('useConfigFile');
@@ -29,10 +34,6 @@ export class GitVersionTask {
2934
this.updateAssemblyInfo = tl.getBoolInput('updateAssemblyInfo');
3035
this.updateAssemblyInfoFilename = tl.getInput('updateAssemblyInfoFilename');
3136

32-
this.preferBundledVersion = tl.getBoolInput('preferBundledVersion');
33-
this.runtime = tl.getInput('runtime') || 'core';
34-
this.gitVersionPath = tl.getInput('gitVersionPath');
35-
3637
this.additionalArguments = tl.getInput('additionalArguments');
3738

3839
this.sourcesDirectory = tl.getVariable('Build.SourcesDirectory').replace(/\\/g, '/');
@@ -51,8 +52,10 @@ export class GitVersionTask {
5152

5253
public async execute() {
5354
try {
55+
let toolPath = await this.installTool(this.versionSpec, this.includePrerelease);
56+
5457
let workingDirectory = this.getWorkingDirectory(this.targetPath);
55-
let exe = this.getExecutable();
58+
let exe = tl.tool('dotnet-gitversion');
5659
exe.arg([
5760
workingDirectory,
5861
"/output",
@@ -95,48 +98,14 @@ export class GitVersionTask {
9598
}
9699
}
97100

98-
public getExecutable(){
99-
let exe: tr.ToolRunner;
100-
101-
switch (this.runtime) {
102-
case "full":
103-
const isWin32 = os.platform() == "win32";
104-
let exePath = this.getExecutablePath("GitVersion.exe") || tl.which("GitVersion.exe", true);
105-
if (isWin32) {
106-
exe = tl.tool(exePath);
107-
} else {
108-
exe = tl.tool("mono");
109-
exe.arg(exePath);
110-
}
111-
break;
112-
case "core":
113-
let assemblyPath = this.getExecutablePath("GitVersion.dll");
114-
let dotnetPath = tl.which("dotnet", true);
115-
exe = tl.tool(dotnetPath);
116-
exe.arg(assemblyPath);
117-
break;
101+
async installTool(version: string, includePrerelease: boolean) : Promise<string> {
102+
let installTool = tl.getVariable("INSTALL_TOOL");
103+
if (installTool === null || installTool === undefined || installTool.toUpperCase() == "TRUE") {
104+
return await new ToolInstaller().downloadAndInstall("GitVersion.Tool", version, false, includePrerelease);
118105
}
119-
120-
return exe;
121-
}
122-
123-
public getExecutablePath(exeName:string) {
124-
let exePath;
125-
if (this.preferBundledVersion) {
126-
let currentDirectory = __dirname;
127-
exePath = path.join(currentDirectory, this.runtime, exeName);
128-
} else {
129-
if (tl.filePathSupplied('gitVersionPath') && tl.exist(this.gitVersionPath) && tl.stats(this.gitVersionPath).isFile()) {
130-
exePath = this.gitVersionPath;
131-
} else{
132-
throw new Error('GitVersion executable not found at ' + this.gitVersionPath);
133-
}
134-
}
135-
136-
return exePath.replace(/\\/g, '/');
137106
}
138107

139-
public getWorkingDirectory(targetPath: string) {
108+
getWorkingDirectory(targetPath: string) {
140109
let workDir;
141110

142111
if (!targetPath){

src/GitVersionVsixTask/GitVersionTask/task.json

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,47 @@
88
"category": "Build",
99
"demands": [],
1010
"version": {
11-
"Major": "4",
11+
"Major": "5",
1212
"Minor": "0",
13-
"Patch": "0"
13+
"Patch": "2"
1414
},
1515
"minimumAgentVersion": "2.115.0",
1616
"groups": [{
17-
"name": "gitversionDetails",
18-
"displayName": "GitVersion details",
19-
"isExpanded": true,
20-
"visibleRule": "preferBundledVersion = false"
21-
}, {
22-
"name": "additional",
23-
"displayName": "Additional Options",
24-
"isExpanded": false
25-
}],
17+
"name": "gitversionDetails",
18+
"displayName": "GitVersion details",
19+
"isExpanded": true
20+
},
21+
{
22+
"name": "additional",
23+
"displayName": "Additional Options",
24+
"isExpanded": false
25+
}
26+
],
2627
"instanceNameFormat": "GitVersion",
2728
"inputs": [{
28-
"name": "runtime",
29-
"type": "radio",
30-
"label": "Runtime",
31-
"defaultValue": "core",
29+
"name": "versionSpec",
30+
"type": "string",
31+
"label": "The version spec",
32+
"defaultValue": "",
3233
"required": true,
33-
"options": {
34-
"core": "dotnet core",
35-
"full": "dotnet fullframework (or mono)"
36-
},
37-
"helpMarkDown": "Specify the runtime used for running the tool"
38-
}, {
39-
"name": "preferBundledVersion",
34+
"helpMarkDown": "Required version in the form of 5.x or exact version like 5.0.0"
35+
},
36+
{
37+
"name": "includePrerelease",
4038
"type": "boolean",
41-
"label": "Prefer bundled GitVersion",
42-
"defaultValue": "true",
39+
"label": "Include pre-release versions",
40+
"defaultValue": "false",
4341
"required": false,
44-
"helpMarkDown": "If checked it will prefer the bundled version over a version found in path"
45-
}, {
46-
"name": "gitVersionPath",
42+
"helpMarkDown": "Include pre-release versions when matching a version"
43+
},
44+
{
45+
"name": "targetPath",
4746
"type": "string",
48-
"label": "Path to GitVersion",
47+
"label": "Working directory path",
4948
"defaultValue": "",
5049
"required": false,
51-
"helpMarkDown": "Optionally supply the path to GitVersion",
52-
"visibleRule": "preferBundledVersion = true"
50+
"helpMarkDown": "Optionally supply the path to the working directory",
51+
"groupName": "gitversionDetails"
5352
},
5453
{
5554
"name": "useConfigFile",
@@ -58,38 +57,34 @@
5857
"defaultValue": "false",
5958
"required": false,
6059
"helpMarkDown": "Whether to use a custom configuration file"
61-
}, {
60+
},
61+
{
6262
"name": "configFilePath",
6363
"type": "filePath",
6464
"label": "Configuration file",
6565
"defaultValue": "",
6666
"required": false,
6767
"helpMarkDown": "Optional path to config file (defaults to GitVersion.yml)",
6868
"visibleRule": "useConfigFile = true"
69-
}, {
69+
},
70+
{
7071
"name": "updateAssemblyInfo",
7172
"type": "boolean",
7273
"label": "Update AssemblyInfo files",
7374
"defaultValue": "false",
7475
"required": false,
7576
"helpMarkDown": "Whether to update versions in the AssemblyInfo files"
76-
}, {
77+
},
78+
{
7779
"name": "updateAssemblyInfoFilename",
7880
"type": "string",
7981
"label": "Update Assembly File",
8082
"defaultValue": "",
8183
"required": false,
8284
"helpMarkDown": "Update versions in specified file",
8385
"visibleRule": "updateAssemblyInfo = true"
84-
}, {
85-
"name": "targetPath",
86-
"type": "string",
87-
"label": "Working directory path",
88-
"defaultValue": "",
89-
"required": false,
90-
"helpMarkDown": "Optionally supply the path to the working directory",
91-
"groupName": "gitversionDetails"
92-
}, {
86+
},
87+
{
9388
"name": "additionalArguments",
9489
"type": "string",
9590
"label": "Additional GitVersion arguments",

0 commit comments

Comments
 (0)