Skip to content

Commit b117bc4

Browse files
committed
(vsix) re-implement the vsix extension as a bundle for .net core/full framework
1 parent d5ba89d commit b117bc4

17 files changed

+223
-388
lines changed

.vscode/launch.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"version": "0.2.0",
33
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Launch Program",
8+
"program": "${workspaceFolder}/src/GitVersionTfsTask/GitVersionTask/GitVersion.js"
9+
},
410
{
511
"name": ".NET Core Launch (console)",
612
"type": "coreclr",
@@ -16,4 +22,4 @@
1622
"externalConsole": false
1723
}
1824
]
19-
}
25+
}

build.cake

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,17 @@ Task("Copy-Files")
267267

268268
// Vsix
269269
var vsixPath = new DirectoryPath("./src/GitVersionTfsTask/GitVersionTask");
270-
EnsureDirectoryExists(vsixPath);
271-
CopyFileToDirectory(portableDir + "/" + "LibGit2Sharp.dll.config", vsixPath);
272-
CopyFileToDirectory(portableDir + "/" + "GitVersion.exe", vsixPath);
273-
CopyDirectory(portableDir.Combine("lib"), vsixPath.Combine("lib"));
270+
271+
var vsixPathFull = vsixPath.Combine("full");
272+
EnsureDirectoryExists(vsixPathFull);
273+
CopyFileToDirectory(portableDir + "/" + "LibGit2Sharp.dll.config", vsixPathFull);
274+
CopyFileToDirectory(portableDir + "/" + "GitVersion.exe", vsixPathFull);
275+
CopyDirectory(portableDir.Combine("lib"), vsixPathFull.Combine("lib"));
274276

275277
// Vsix dotnet core
276-
var vsixCoreFxPath = new DirectoryPath("./src/GitVersionTfsTask/GitVersionNetCoreTask");
277-
EnsureDirectoryExists(vsixCoreFxPath);
278-
CopyDirectory(coreFxDir, vsixCoreFxPath.Combine("netcore"));
278+
var vsixPathCore = vsixPath.Combine("core");
279+
EnsureDirectoryExists(vsixPathCore);
280+
CopyDirectory(coreFxDir, vsixPathCore);
279281

280282
// Ruby Gem
281283
var gemPath = new DirectoryPath("./src/GitVersionRubyGem/bin");
@@ -293,21 +295,15 @@ Task("Pack-Vsix")
293295
var idSuffix = parameters.IsStableRelease() ? "" : "-preview";
294296
var titleSuffix = parameters.IsStableRelease() ? "" : " (Preview)";
295297
var visibility = parameters.IsStableRelease() ? "Public" : "Preview";
296-
var taskIdFullFx = parameters.IsStableRelease() ? "e5983830-3f75-11e5-82ed-81492570a08e" : "25b46667-d5a9-4665-97f7-e23de366ecdf";
297-
var taskIdCoreFx = parameters.IsStableRelease() ? "ce526674-dbd1-4023-ad6d-2a6b9742ee31" : "edf331e1-d1c0-413a-9735-fce0b22a46f5";
298+
var taskId = parameters.IsStableRelease() ? "bfb2f1f8-b852-4db1-ae50-35c79c9161e0" : "761ce478-068a-441a-8f2b-aae0987e7d88";
298299

299-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.mono.json"), "$idSuffix$", idSuffix);
300-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.netcore.json"), "$idSuffix$", idSuffix);
301-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.mono.json"), "$titleSuffix$", titleSuffix);
302-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.netcore.json"), "$titleSuffix$", titleSuffix);
303-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.mono.json"), "$visibility$", visibility);
304-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.netcore.json"), "$visibility$", visibility);
300+
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.json"), "$idSuffix$", idSuffix);
301+
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.json"), "$titleSuffix$", titleSuffix);
302+
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.json"), "$visibility$", visibility);
305303

306304
// update version number
307-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.mono.json"), "$version$", parameters.Version.VsixVersion);
308-
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.netcore.json"), "$version$", parameters.Version.VsixVersion);
309-
UpdateTaskVersion(new FilePath(workDir + "/GitVersionTask/task.json"), taskIdFullFx, parameters.Version.GitVersion);
310-
UpdateTaskVersion(new FilePath(workDir + "/GitVersionNetCoreTask/task.json"), taskIdCoreFx, parameters.Version.GitVersion);
305+
ReplaceTextInFile(new FilePath(workDir + "/vss-extension.json"), "$version$", parameters.Version.VsixVersion);
306+
UpdateTaskVersion(new FilePath(workDir + "/GitVersionTask/task.json"), taskId, parameters.Version.GitVersion);
311307

312308
// build and pack
313309
NpmSet(new NpmSetSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, Key = "progress", Value = "false" });
@@ -321,10 +317,7 @@ Task("Pack-Vsix")
321317
OutputPath = parameters.Paths.Directories.BuildArtifact
322318
};
323319

324-
settings.ManifestGlobs = new List<string>(){ "vss-extension.mono.json" };
325-
TfxExtensionCreate(settings);
326-
327-
settings.ManifestGlobs = new List<string>(){ "vss-extension.netcore.json" };
320+
settings.ManifestGlobs = new List<string>(){ "vss-extension.json" };
328321
TfxExtensionCreate(settings);
329322
});
330323

@@ -620,11 +613,11 @@ Task("Publish-Vsix")
620613
{
621614
ToolPath = workDir + "/node_modules/.bin/" + (parameters.IsRunningOnWindows ? "tfx.cmd" : "tfx"),
622615
AuthType = TfxAuthType.Pat,
623-
Token = token
616+
Token = token,
617+
ArgumentCustomization = args => args.Render() + " --no-wait-validation"
624618
};
625619

626620
TfxExtensionPublish(parameters.Paths.Files.VsixOutputFilePath, settings);
627-
TfxExtensionPublish(parameters.Paths.Files.VsixCoreFxOutputFilePath, settings);
628621
})
629622
.OnError(exception =>
630623
{

build/parameters.cake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public class BuildParameters
108108
files.TestCoverageOutputFilePath,
109109
files.ReleaseNotesOutputFilePath,
110110
files.VsixOutputFilePath,
111-
files.VsixCoreFxOutputFilePath,
112111
files.GemOutputFilePath
113112
});
114113

build/paths.cake

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public class BuildPaths
4545
var gemOutputFilePath = buildArtifactDir.CombineWithFilePath("gitversion-" + version.GemVersion + ".gem");
4646

4747
var vsixSuffix = parameters.IsStableRelease() ? "" : "preview-";
48-
var vsixOutputFilePath = buildArtifactDir.CombineWithFilePath("gittools.gitversion-" + vsixSuffix + version.VsixVersion + ".vsix");
49-
var vsixCoreFxOutputFilePath = buildArtifactDir.CombineWithFilePath("gittools.gitversion-netcore-" + vsixSuffix + version.VsixVersion + ".vsix");
48+
var vsixOutputFilePath = buildArtifactDir.CombineWithFilePath("GitVersion.gitversion-" + vsixSuffix + version.VsixVersion + ".vsix");
5049

5150
// Directories
5251
var buildDirectories = new BuildDirectories(
@@ -69,7 +68,6 @@ public class BuildPaths
6968
testCoverageOutputFilePath,
7069
releaseNotesOutputFilePath,
7170
vsixOutputFilePath,
72-
vsixCoreFxOutputFilePath,
7371
gemOutputFilePath);
7472

7573
return new BuildPaths
@@ -87,7 +85,6 @@ public class BuildFiles
8785
public FilePath TestCoverageOutputFilePath { get; private set; }
8886
public FilePath ReleaseNotesOutputFilePath { get; private set; }
8987
public FilePath VsixOutputFilePath { get; private set; }
90-
public FilePath VsixCoreFxOutputFilePath { get; private set; }
9188
public FilePath GemOutputFilePath { get; private set; }
9289

9390
public BuildFiles(
@@ -97,7 +94,6 @@ public class BuildFiles
9794
FilePath testCoverageOutputFilePath,
9895
FilePath releaseNotesOutputFilePath,
9996
FilePath vsixOutputFilePath,
100-
FilePath vsixCoreFxOutputFilePath,
10197
FilePath gemOutputFilePath
10298
)
10399
{
@@ -106,7 +102,6 @@ public class BuildFiles
106102
TestCoverageOutputFilePath = testCoverageOutputFilePath;
107103
ReleaseNotesOutputFilePath = releaseNotesOutputFilePath;
108104
VsixOutputFilePath = vsixOutputFilePath;
109-
VsixCoreFxOutputFilePath = vsixCoreFxOutputFilePath;
110105
GemOutputFilePath = gemOutputFilePath;
111106
}
112107
}

src/GitVersionTfsTask/GitVersion.ts

Lines changed: 90 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,75 @@
11
import tl = require('azure-pipelines-task-lib/task');
2-
import { IExecOptions, ToolRunner } from 'azure-pipelines-task-lib/toolrunner';
2+
import tr = require('azure-pipelines-task-lib/toolrunner');
33
import path = require('path');
44
import os = require('os');
5-
import { ArgumentParser } from 'argparse';
65

76
export class GitVersionTask {
7+
execOptions: tr.IExecOptions;
8+
9+
preferBundledVersion: boolean;
10+
updateAssemblyInfo: boolean;
11+
12+
updateAssemblyInfoFilename: string;
13+
additionalArguments: string;
14+
targetPath: string;
15+
sourcesDirectory: string;
16+
currentDirectory: string;
17+
workingDirectory: string;
18+
gitVersionPath: string;
19+
runtime: string;
20+
21+
constructor() {
22+
this.preferBundledVersion = tl.getBoolInput('preferBundledVersion') || true;
23+
this.updateAssemblyInfo = tl.getBoolInput('updateAssemblyInfo');
24+
25+
this.updateAssemblyInfoFilename = tl.getInput('updateAssemblyInfoFilename');
26+
this.additionalArguments = tl.getInput('additionalArguments');
27+
this.targetPath = tl.getInput('targetPath');
28+
this.runtime = tl.getInput('runtime') || "core";
29+
this.gitVersionPath = tl.getInput('gitVersionPath');
30+
31+
this.sourcesDirectory = tl.getVariable("Build.SourcesDirectory");
32+
33+
this.currentDirectory = __dirname;
34+
this.workingDirectory = !this.targetPath
35+
? this.sourcesDirectory
36+
: path.join(this.sourcesDirectory, this.targetPath);
37+
38+
this.execOptions = {
39+
cwd: undefined,
40+
env: undefined,
41+
silent: undefined,
42+
failOnStdErr: undefined,
43+
ignoreReturnCode: undefined,
44+
errStream: undefined,
45+
outStream: undefined,
46+
windowsVerbatimArguments: undefined
47+
};
48+
}
849

9-
public static async execute() {
50+
public async execute() {
1051
try {
11-
12-
const updateAssemblyInfo = tl.getBoolInput('updateAssemblyInfo');
13-
const updateAssemblyInfoFilename = tl.getInput('updateAssemblyInfoFilename');
14-
const additionalArguments = tl.getInput('additionalArguments');
15-
const targetPath = tl.getInput('targetPath');
16-
const preferBundledVersion = tl.getBoolInput('preferBundledVersion');
17-
18-
const currentDirectory = __dirname;
19-
const workingDirectory = !targetPath
20-
? tl.getVariable("Build.SourcesDirectory")
21-
: path.join(tl.getVariable("Build.SourcesDirectory"), targetPath);
22-
23-
let gitVersionPath = tl.getInput('gitVersionPath');
24-
if (!gitVersionPath) {
25-
gitVersionPath = tl.which("GitVersion.exe");
26-
if (preferBundledVersion || !gitVersionPath) {
27-
gitVersionPath = path.join(currentDirectory, "GitVersion.exe");
28-
}
29-
}
30-
31-
const execOptions: IExecOptions = {
32-
cwd: undefined,
33-
env: undefined,
34-
silent: undefined,
35-
failOnStdErr: undefined,
36-
ignoreReturnCode: undefined,
37-
errStream: undefined,
38-
outStream: undefined,
39-
windowsVerbatimArguments: undefined
40-
};
41-
42-
let toolRunner: ToolRunner;
43-
44-
const parser = new ArgumentParser();
45-
parser.addArgument(
46-
[ '-r', '--runtime'],
47-
{
48-
help: '[full|netcore]',
49-
defaultValue: 'full'
50-
}
51-
);
52-
53-
const args = parser.parseArgs();
54-
switch (args.runtime) {
55-
case 'netcore':
56-
gitVersionPath = path.join(currentDirectory, "netcore", "GitVersion.dll");
57-
toolRunner = tl.tool("dotnet");
58-
toolRunner.arg(gitVersionPath);
59-
break;
60-
61-
case 'full':
62-
default:
63-
const isWin32 = os.platform() == "win32";
64-
if (isWin32) {
65-
toolRunner = tl.tool(gitVersionPath);
66-
} else {
67-
toolRunner = tl.tool("mono");
68-
toolRunner.arg(gitVersionPath);
69-
}
70-
71-
break;
72-
}
73-
74-
toolRunner.arg([
75-
workingDirectory,
52+
let exe = this.getExecutable();
53+
exe.arg([
54+
this.workingDirectory,
7655
"/output",
7756
"buildserver",
7857
"/nofetch"]);
7958

80-
if (updateAssemblyInfo) {
81-
toolRunner.arg("/updateassemblyinfo");
82-
if (updateAssemblyInfoFilename) {
83-
toolRunner.arg(updateAssemblyInfoFilename);
59+
if (this.updateAssemblyInfo) {
60+
exe.arg("/updateassemblyinfo");
61+
if (this.updateAssemblyInfoFilename) {
62+
exe.arg(this.updateAssemblyInfoFilename);
8463
} else {
85-
toolRunner.arg("true");
64+
exe.arg("true");
8665
}
8766
}
8867

89-
if (additionalArguments) {
90-
toolRunner.line(additionalArguments);
68+
if (this.additionalArguments) {
69+
exe.line(this.additionalArguments);
9170
}
9271

93-
const result = await toolRunner.exec(execOptions);
72+
const result = await exe.exec(this.execOptions);
9473
if (result) {
9574
tl.setResult(tl.TaskResult.Failed, "An error occured during GitVersion execution")
9675
} else {
@@ -102,6 +81,40 @@ export class GitVersionTask {
10281
tl.setResult(tl.TaskResult.Failed, err);
10382
}
10483
}
84+
85+
public getExecutable(){
86+
let exe: tr.ToolRunner;
87+
88+
switch (this.runtime) {
89+
case "full":
90+
const isWin32 = os.platform() == "win32";
91+
let exePath = this.getExecutablePath("GitVersion.exe") || tl.which("GitVersion.exe", true);
92+
if (isWin32) {
93+
exe = tl.tool(exePath);
94+
} else {
95+
exe = tl.tool("mono");
96+
exe.arg(exePath);
97+
}
98+
break;
99+
case "core":
100+
let assemblyPath = this.getExecutablePath("GitVersion.dll");
101+
let dotnetPath = tl.which("dotnet", true);
102+
exe = tl.tool(dotnetPath);
103+
exe.arg(assemblyPath);
104+
break;
105+
}
106+
107+
return exe;
108+
}
109+
110+
public getExecutablePath(exeName:string) {
111+
if (this.gitVersionPath){
112+
return this.gitVersionPath;
113+
} else if (this.preferBundledVersion) {
114+
return path.join(this.currentDirectory, this.runtime, exeName);
115+
}
116+
}
105117
}
106118

107-
GitVersionTask.execute();
119+
var exe = new GitVersionTask();
120+
exe.execute().catch((reason) => tl.setResult(tl.TaskResult.Failed, reason));
Binary file not shown.

0 commit comments

Comments
 (0)