Skip to content

Commit 0543b60

Browse files
committed
added support for .net core 3.0.
Generate native executables for all os-es
1 parent fa4f255 commit 0543b60

File tree

8 files changed

+150
-194
lines changed

8 files changed

+150
-194
lines changed

build.cake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// Install addins.
55
#addin "nuget:?package=Cake.Codecov&version=0.7.0"
6+
#addin "nuget:?package=Cake.Compression&version=0.2.4"
67
#addin "nuget:?package=Cake.Coverlet&version=2.3.4"
78
#addin "nuget:?package=Cake.Docker&version=0.10.1"
89
#addin "nuget:?package=Cake.Gem&version=0.8.1"
@@ -13,11 +14,11 @@
1314
#addin "nuget:?package=Cake.Tfx&version=0.9.1"
1415

1516
#addin "nuget:?package=Newtonsoft.Json&version=12.0.2"
17+
#addin "nuget:?package=SharpZipLib&version=1.2.0"
1618
#addin "nuget:?package=xunit.assert&version=2.4.1"
1719

1820
// Install tools.
1921
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.10.0"
20-
#tool "nuget:?package=ILRepack&version=2.0.18"
2122
#tool "nuget:?package=nuget.commandline&version=5.2.0"
2223

2324
// Install .NET Core Global tools.

build/docker.cake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ singleStageRun = !IsEnabled(Context, "ENABLED_MULTI_STAGE_BUILD", false);
33
Task("Docker-Build")
44
.WithCriteria<BuildParameters>((context, parameters) => !parameters.IsRunningOnMacOS, "Docker can be built only on Windows or Linux agents.")
55
.WithCriteria<BuildParameters>((context, parameters) => parameters.IsRunningOnAzurePipeline, "Docker-Build works only on AzurePipeline.")
6-
.IsDependentOnWhen("Copy-Files", singleStageRun)
6+
.IsDependentOnWhen("Pack-Prepare", singleStageRun)
77
.Does<BuildParameters>((parameters) =>
88
{
99
foreach(var dockerImage in parameters.Docker.Images)

build/pack.cake

Lines changed: 87 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Task("Test")
3838
.IsDependentOn("Build")
3939
.Does<BuildParameters>((parameters) =>
4040
{
41-
var frameworks = new[] { parameters.CoreFxVersion21, parameters.FullFxVersion };
41+
var frameworks = new[] { parameters.CoreFxVersion21, parameters.CoreFxVersion30, parameters.FullFxVersion472 };
4242
var testResultsPath = parameters.Paths.Directories.TestResultsOutput;
4343

4444
foreach(var framework in frameworks)
@@ -71,7 +71,7 @@ Task("Test")
7171
CoverletOutputName = $"{projectName}.coverage.xml"
7272
};
7373

74-
if (IsRunningOnUnix() && string.Equals(framework, parameters.FullFxVersion))
74+
if (IsRunningOnUnix() && string.Equals(framework, parameters.FullFxVersion472))
7575
{
7676
settings.Filter = "TestCategory!=NoMono";
7777
}
@@ -119,70 +119,83 @@ Task("Test")
119119
#endregion
120120

121121
#region Pack
122-
123-
Task("Copy-Files")
122+
Task("Pack-Prepare")
124123
.IsDependentOn("Test")
125124
.Does<BuildParameters>((parameters) =>
126125
{
127-
// .NET Core
128-
var coreFxDir = parameters.Paths.Directories.ArtifactsBinCoreFx21.Combine("tools");
129-
DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", new DotNetCorePublishSettings
126+
// publish single file for all native runtimes (self contained)
127+
foreach(var runtime in parameters.NativeRuntimes)
130128
{
131-
Framework = parameters.CoreFxVersion21,
132-
NoRestore = false,
133-
Configuration = parameters.Configuration,
134-
OutputDirectory = coreFxDir,
135-
MSBuildSettings = parameters.MSBuildSettings
136-
});
129+
var runtimeName = runtime.Value;
137130

138-
// Copy license & Copy GitVersion.XML (since publish does not do this anymore)
139-
CopyFileToDirectory("./LICENSE", coreFxDir);
140-
CopyFileToDirectory($"./src/GitVersionExe/bin/{parameters.Configuration}/{parameters.CoreFxVersion21}/GitVersion.xml", coreFxDir);
131+
var settings = new DotNetCorePublishSettings
132+
{
133+
Framework = parameters.CoreFxVersion30,
134+
Runtime = runtimeName,
135+
NoRestore = false,
136+
Configuration = parameters.Configuration,
137+
OutputDirectory = parameters.Paths.Directories.Native.Combine(runtimeName),
138+
MSBuildSettings = parameters.MSBuildSettings,
139+
};
141140

142-
// .NET Framework
143-
DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", new DotNetCorePublishSettings
144-
{
145-
Framework = parameters.FullFxVersion,
146-
NoBuild = true,
147-
NoRestore = false,
148-
Configuration = parameters.Configuration,
149-
OutputDirectory = parameters.Paths.Directories.ArtifactsBinFullFx,
150-
MSBuildSettings = parameters.MSBuildSettings
151-
});
141+
settings.ArgumentCustomization =
142+
arg => arg
143+
.Append("/p:PublishSingleFile=true")
144+
.Append("/p:PublishTrimmed=true")
145+
.Append("/p:IncludeSymbolsInSingleFile=true");
146+
147+
DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", settings);
148+
}
149+
150+
var frameworks = new[] { parameters.CoreFxVersion21, parameters.CoreFxVersion30, parameters.FullFxVersion472 };
152151

153-
DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
152+
// publish Framework-dependent deployment
153+
foreach(var framework in frameworks)
154154
{
155-
Framework = parameters.FullFxVersion,
156-
NoBuild = true,
157-
NoRestore = true,
158-
Configuration = parameters.Configuration,
159-
MSBuildSettings = parameters.MSBuildSettings
160-
});
155+
var settings = new DotNetCorePublishSettings
156+
{
157+
Framework = framework,
158+
NoRestore = false,
159+
Configuration = parameters.Configuration,
160+
OutputDirectory = parameters.Paths.Directories.ArtifactsBin.Combine(framework),
161+
MSBuildSettings = parameters.MSBuildSettings,
162+
};
163+
164+
DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", settings);
165+
}
166+
167+
frameworks = new[] { parameters.CoreFxVersion21, parameters.FullFxVersion472 };
161168

162-
// .NET Core
163-
DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
169+
// MsBuild Task
170+
foreach(var framework in frameworks)
164171
{
165-
Framework = parameters.CoreFxVersion21,
166-
NoBuild = true,
167-
NoRestore = true,
168-
Configuration = parameters.Configuration,
169-
MSBuildSettings = parameters.MSBuildSettings
170-
});
171-
var ilMergeDir = parameters.Paths.Directories.ArtifactsBinFullFxILMerge;
172-
var portableDir = parameters.Paths.Directories.ArtifactsBinFullFxPortable.Combine("tools");
173-
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");
174-
175-
// Portable
176-
PublishILRepackedGitVersionExe(true, ilMergeDir, portableDir, parameters);
177-
// Commandline
178-
PublishILRepackedGitVersionExe(false, ilMergeDir, cmdlineDir, parameters);
179-
180-
// Ruby Gem
181-
var gemPath = new DirectoryPath("./src/GitVersionRubyGem/bin");
182-
EnsureDirectoryExists(gemPath);
183-
CopyFileToDirectory(portableDir + "/" + "LibGit2Sharp.dll.config", gemPath);
184-
CopyFileToDirectory(portableDir + "/" + "GitVersion.exe", gemPath);
185-
CopyDirectory(portableDir.Combine("lib"), gemPath.Combine("lib"));
172+
DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
173+
{
174+
Framework = framework,
175+
Configuration = parameters.Configuration,
176+
MSBuildSettings = parameters.MSBuildSettings
177+
});
178+
}
179+
180+
var sourceDir = parameters.Paths.Directories.Native.Combine(parameters.NativeRuntimes[PlatformFamily.Windows]);
181+
var sourceFiles = GetFiles(sourceDir + "/*.*");
182+
183+
// RubyGem
184+
var gemDir = new DirectoryPath("./src/GitVersionRubyGem/bin");
185+
EnsureDirectoryExists(gemDir);
186+
CopyFiles(sourceFiles, gemDir);
187+
188+
// Cmdline and Portable
189+
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinCmdline.Combine("tools");
190+
var portableDir = parameters.Paths.Directories.ArtifactsBinPortable.Combine("tools");
191+
192+
EnsureDirectoryExists(cmdlineDir);
193+
EnsureDirectoryExists(portableDir);
194+
195+
CopyFiles(sourceFiles, cmdlineDir);
196+
197+
sourceFiles += GetFiles("./nuspec/*.ps1") + GetFiles("./nuspec/*.txt");
198+
CopyFiles(sourceFiles, portableDir);
186199
});
187200

188201
Task("Pack-Vsix")
@@ -204,7 +217,6 @@ Task("Pack-Vsix")
204217
UpdateTaskVersion(new FilePath(workDir + "/GitVersionTask/task.json"), taskId, parameters.Version.GitVersion);
205218

206219
// build and pack
207-
208220
var settings = new TfxExtensionCreateSettings
209221
{
210222
ToolPath = workDir + "/node_modules/.bin/" + (parameters.IsRunningOnWindows ? "tfx.cmd" : "tfx"),
@@ -217,7 +229,7 @@ Task("Pack-Vsix")
217229
});
218230

219231
Task("Pack-Gem")
220-
.IsDependentOn("Copy-Files")
232+
.IsDependentOn("Pack-Prepare")
221233
.Does<BuildParameters>((parameters) =>
222234
{
223235
var workDir = "./src/GitVersionRubyGem";
@@ -237,7 +249,7 @@ Task("Pack-Gem")
237249
});
238250

239251
Task("Pack-Nuget")
240-
.IsDependentOn("Copy-Files")
252+
.IsDependentOn("Pack-Prepare")
241253
.Does<BuildParameters>((parameters) =>
242254
{
243255
foreach(var package in parameters.Packages.Nuget)
@@ -263,8 +275,6 @@ Task("Pack-Nuget")
263275
{
264276
Configuration = parameters.Configuration,
265277
OutputDirectory = parameters.Paths.Directories.NugetRoot,
266-
NoBuild = true,
267-
NoRestore = true,
268278
MSBuildSettings = parameters.MSBuildSettings
269279
};
270280

@@ -278,41 +288,38 @@ Task("Pack-Nuget")
278288
Task("Pack-Chocolatey")
279289
.WithCriteria<BuildParameters>((context, parameters) => parameters.IsRunningOnWindows, "Pack-Chocolatey works only on Windows agents.")
280290
.WithCriteria<BuildParameters>((context, parameters) => parameters.IsMainBranch, "Pack-Chocolatey works only for main branch.")
281-
.IsDependentOn("Copy-Files")
291+
.IsDependentOn("Pack-Prepare")
282292
.Does<BuildParameters>((parameters) =>
283293
{
284294
foreach(var package in parameters.Packages.Chocolatey)
285295
{
286296
if (FileExists(package.NuspecPath)) {
287297
var artifactPath = MakeAbsolute(parameters.PackagesBuildMap[package.Id]).FullPath;
288298

289-
var files = GetFiles(artifactPath + "/**/*.*")
290-
.Select(file => new ChocolateyNuSpecContent { Source = file.FullPath, Target = file.FullPath.Replace(artifactPath, "") });
291-
var txtFiles = (GetFiles("./nuspec/*.txt") + GetFiles("./nuspec/*.ps1"))
292-
.Select(file => new ChocolateyNuSpecContent { Source = file.FullPath, Target = file.GetFilename().ToString() });
293-
294-
ChocolateyPack(package.NuspecPath, new ChocolateyPackSettings {
299+
var chocolateySettings = new ChocolateyPackSettings
300+
{
295301
Verbose = true,
296302
Version = parameters.Version.SemVersion,
297303
OutputDirectory = parameters.Paths.Directories.NugetRoot,
298-
Files = files.Concat(txtFiles).ToArray()
299-
});
304+
Files = GetFiles(artifactPath + "/**/*.*")
305+
.Select(file => new ChocolateyNuSpecContent { Source = file.FullPath, Target = file.FullPath.Replace(artifactPath, "") })
306+
.ToArray()
307+
};
308+
ChocolateyPack(package.NuspecPath, chocolateySettings);
300309
}
301310
}
302311
});
303312

304313
Task("Zip-Files")
305-
.IsDependentOn("Copy-Files")
314+
.IsDependentOn("Pack-Prepare")
306315
.Does<BuildParameters>((parameters) =>
307316
{
308-
// .NET Framework
309-
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");
310-
var fullFxFiles = GetFiles(cmdlineDir.FullPath + "/**/*");
311-
Zip(cmdlineDir, parameters.Paths.Files.ZipArtifactPathDesktop, fullFxFiles);
312-
313-
// .NET Core
314-
var coreFxDir = parameters.Paths.Directories.ArtifactsBinCoreFx21.Combine("tools");
315-
var coreclrFiles = GetFiles(coreFxDir.FullPath + "/**/*");
316-
Zip(coreFxDir, parameters.Paths.Files.ZipArtifactPathCoreClr, coreclrFiles);
317+
foreach(var runtime in parameters.NativeRuntimes)
318+
{
319+
var sourceDir = parameters.Paths.Directories.Native.Combine(runtime.Value);
320+
var fileName = $"gitversion-{runtime.Key}-{parameters.Version.SemVersion}.tar.gz".ToLower();
321+
var tarFile = parameters.Paths.Directories.Artifacts.CombineWithFilePath(fileName);
322+
GZipCompress(sourceDir, tarFile);
323+
}
317324
});
318325
#endregion

build/publish.cake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ Task("Release-Notes")
2222
TargetCommitish = "master"
2323
});
2424

25-
GitReleaseManagerAddAssets(token, repoOwner, repository, parameters.Version.Milestone, parameters.Paths.Files.ZipArtifactPathDesktop.ToString());
26-
GitReleaseManagerAddAssets(token, repoOwner, repository, parameters.Version.Milestone, parameters.Paths.Files.ZipArtifactPathCoreClr.ToString());
25+
var zipFiles = GetFiles(parameters.Paths.Directories.Artifacts + "/*.tar.gz");
26+
foreach(var zipFile in zipFiles)
27+
{
28+
GitReleaseManagerAddAssets(token, repoOwner, repository, parameters.Version.Milestone, zipFile.ToString());
29+
}
30+
2731
GitReleaseManagerClose(token, repoOwner, repository, parameters.Version.Milestone);
2832

2933
}).ReportError(exception =>

build/utils/docker.cake

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ void DockerBuild(DockerImage dockerImage, BuildParameters parameters)
2828
var (os, distro, targetframework) = dockerImage;
2929
var workDir = DirectoryPath.FromString($"./src/Docker");
3030

31-
var sourceDir = targetframework.StartsWith("netcoreapp")
32-
? parameters.Paths.Directories.ArtifactsBinCoreFx21.Combine("tools")
33-
: parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");
31+
var sourceDir = parameters.Paths.Directories.ArtifactsBin.Combine(targetframework);
3432

3533
CopyDirectory(sourceDir, workDir.Combine("content"));
3634

@@ -102,6 +100,11 @@ void DockerTestArtifact(DockerImage dockerImage, BuildParameters parameters, str
102100
Information("Docker tag: {0}", tag);
103101
Information("Docker cmd: {0}", cmd);
104102

103+
if (os == "windows" && targetframework == parameters.CoreFxVersion30)
104+
{
105+
cmd = "-Command " + cmd; // powershell 7 needs a -Command parameter
106+
}
107+
105108
DockerTestRun(settings, parameters, tag, "pwsh", cmd);
106109
}
107110

build/utils/parameters.cake

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ public class BuildParameters
1010

1111
public const string MainRepoOwner = "gittools";
1212
public const string MainRepoName = "GitVersion";
13-
public string CoreFxVersion21 { get; private set; } = "netcoreapp2.1";
14-
public string FullFxVersion { get; private set; } = "net472";
13+
public string CoreFxVersion21 { get; private set; } = "netcoreapp2.1";
14+
public string CoreFxVersion30 { get; private set; } = "netcoreapp3.0";
15+
public string FullFxVersion472 { get; private set; } = "net472";
1516

1617
public string DockerDistro { get; private set; }
1718
public string DockerDotnetVersion { get; private set; }
@@ -51,6 +52,7 @@ public class BuildParameters
5152
public BuildArtifacts Artifacts { get; private set; }
5253
public DockerImages Docker { get; private set; }
5354
public Dictionary<string, DirectoryPath> PackagesBuildMap { get; private set; }
55+
public Dictionary<PlatformFamily, string> NativeRuntimes { get; private set; }
5456

5557
public bool IsStableRelease() => !IsLocalBuild && IsMainRepo && IsMainBranch && !IsPullRequest && IsTagged;
5658
public bool IsPreRelease() => !IsLocalBuild && IsMainRepo && IsMainBranch && !IsPullRequest && !IsTagged;
@@ -125,17 +127,22 @@ public class BuildParameters
125127

126128
var files = Paths.Files;
127129

128-
var buildArtifacts = context.GetFiles(Paths.Directories.BuildArtifact + "/*.*");
129-
buildArtifacts += files.ZipArtifactPathDesktop;
130-
buildArtifacts += files.ZipArtifactPathCoreClr;
130+
var buildArtifacts = context.GetFiles(Paths.Directories.BuildArtifact + "/*.*") + context.GetFiles(Paths.Directories.Artifacts + "/*.tar.gz");
131131
buildArtifacts += files.ReleaseNotesOutputFilePath;
132132

133133
Artifacts = BuildArtifacts.GetArtifacts(buildArtifacts.ToArray());
134134

135135
PackagesBuildMap = new Dictionary<string, DirectoryPath>
136136
{
137-
["GitVersion.CommandLine"] = Paths.Directories.ArtifactsBinFullFxCmdline,
138-
["GitVersion.Portable"] = Paths.Directories.ArtifactsBinFullFxPortable,
137+
["GitVersion.CommandLine"] = Paths.Directories.ArtifactsBinCmdline,
138+
["GitVersion.Portable"] = Paths.Directories.ArtifactsBinPortable,
139+
};
140+
141+
NativeRuntimes = new Dictionary<PlatformFamily, string>
142+
{
143+
[PlatformFamily.Windows] = "win-x64",
144+
[PlatformFamily.Linux] = "linux-x64",
145+
[PlatformFamily.OSX] = "osx-x64",
139146
};
140147

141148
Credentials = BuildCredentials.GetCredentials(context);

0 commit comments

Comments
 (0)