Skip to content

Feature/netcore3.0 #1849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 10, 2019
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
3 changes: 2 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// Install addins.
#addin "nuget:?package=Cake.Codecov&version=0.7.0"
#addin "nuget:?package=Cake.Compression&version=0.2.4"
#addin "nuget:?package=Cake.Coverlet&version=2.3.4"
#addin "nuget:?package=Cake.Docker&version=0.10.1"
#addin "nuget:?package=Cake.Gem&version=0.8.1"
Expand All @@ -13,11 +14,11 @@
#addin "nuget:?package=Cake.Tfx&version=0.9.1"

#addin "nuget:?package=Newtonsoft.Json&version=12.0.2"
#addin "nuget:?package=SharpZipLib&version=1.2.0"
#addin "nuget:?package=xunit.assert&version=2.4.1"

// Install tools.
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.10.0"
#tool "nuget:?package=ILRepack&version=2.0.18"
#tool "nuget:?package=nuget.commandline&version=5.2.0"

// Install .NET Core Global tools.
Expand Down
2 changes: 1 addition & 1 deletion build.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
CAKE_VERSION=0.35
DOTNET_VERSION=2.2.401
DOTNET_VERSION=2.1.802,3.0.100
2 changes: 1 addition & 1 deletion build/docker.cake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ singleStageRun = !IsEnabled(Context, "ENABLED_MULTI_STAGE_BUILD", false);
Task("Docker-Build")
.WithCriteria<BuildParameters>((context, parameters) => !parameters.IsRunningOnMacOS, "Docker can be built only on Windows or Linux agents.")
.WithCriteria<BuildParameters>((context, parameters) => parameters.IsRunningOnAzurePipeline, "Docker-Build works only on AzurePipeline.")
.IsDependentOnWhen("Copy-Files", singleStageRun)
.IsDependentOnWhen("Pack-Prepare", singleStageRun)
.Does<BuildParameters>((parameters) =>
{
foreach(var dockerImage in parameters.Docker.Images)
Expand Down
167 changes: 87 additions & 80 deletions build/pack.cake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Task("Test")
.IsDependentOn("Build")
.Does<BuildParameters>((parameters) =>
{
var frameworks = new[] { parameters.CoreFxVersion21, parameters.FullFxVersion };
var frameworks = new[] { parameters.CoreFxVersion21, parameters.CoreFxVersion30, parameters.FullFxVersion472 };
var testResultsPath = parameters.Paths.Directories.TestResultsOutput;

foreach(var framework in frameworks)
Expand Down Expand Up @@ -71,7 +71,7 @@ Task("Test")
CoverletOutputName = $"{projectName}.coverage.xml"
};

if (IsRunningOnUnix() && string.Equals(framework, parameters.FullFxVersion))
if (IsRunningOnUnix() && string.Equals(framework, parameters.FullFxVersion472))
{
settings.Filter = "TestCategory!=NoMono";
}
Expand Down Expand Up @@ -119,70 +119,83 @@ Task("Test")
#endregion

#region Pack

Task("Copy-Files")
Task("Pack-Prepare")
.IsDependentOn("Test")
.Does<BuildParameters>((parameters) =>
{
// .NET Core
var coreFxDir = parameters.Paths.Directories.ArtifactsBinCoreFx21.Combine("tools");
DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", new DotNetCorePublishSettings
// publish single file for all native runtimes (self contained)
foreach(var runtime in parameters.NativeRuntimes)
{
Framework = parameters.CoreFxVersion21,
NoRestore = false,
Configuration = parameters.Configuration,
OutputDirectory = coreFxDir,
MSBuildSettings = parameters.MSBuildSettings
});
var runtimeName = runtime.Value;

// Copy license & Copy GitVersion.XML (since publish does not do this anymore)
CopyFileToDirectory("./LICENSE", coreFxDir);
CopyFileToDirectory($"./src/GitVersionExe/bin/{parameters.Configuration}/{parameters.CoreFxVersion21}/GitVersion.xml", coreFxDir);
var settings = new DotNetCorePublishSettings
{
Framework = parameters.CoreFxVersion30,
Runtime = runtimeName,
NoRestore = false,
Configuration = parameters.Configuration,
OutputDirectory = parameters.Paths.Directories.Native.Combine(runtimeName),
MSBuildSettings = parameters.MSBuildSettings,
};

// .NET Framework
DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", new DotNetCorePublishSettings
{
Framework = parameters.FullFxVersion,
NoBuild = true,
NoRestore = false,
Configuration = parameters.Configuration,
OutputDirectory = parameters.Paths.Directories.ArtifactsBinFullFx,
MSBuildSettings = parameters.MSBuildSettings
});
settings.ArgumentCustomization =
arg => arg
.Append("/p:PublishSingleFile=true")
.Append("/p:PublishTrimmed=true")
.Append("/p:IncludeSymbolsInSingleFile=true");

DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", settings);
}

var frameworks = new[] { parameters.CoreFxVersion21, parameters.CoreFxVersion30, parameters.FullFxVersion472 };

DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
// publish Framework-dependent deployment
foreach(var framework in frameworks)
{
Framework = parameters.FullFxVersion,
NoBuild = true,
NoRestore = true,
Configuration = parameters.Configuration,
MSBuildSettings = parameters.MSBuildSettings
});
var settings = new DotNetCorePublishSettings
{
Framework = framework,
NoRestore = false,
Configuration = parameters.Configuration,
OutputDirectory = parameters.Paths.Directories.ArtifactsBin.Combine(framework),
MSBuildSettings = parameters.MSBuildSettings,
};

DotNetCorePublish("./src/GitVersionExe/GitVersionExe.csproj", settings);
}

frameworks = new[] { parameters.CoreFxVersion21, parameters.FullFxVersion472 };

// .NET Core
DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
// MsBuild Task
foreach(var framework in frameworks)
{
Framework = parameters.CoreFxVersion21,
NoBuild = true,
NoRestore = true,
Configuration = parameters.Configuration,
MSBuildSettings = parameters.MSBuildSettings
});
var ilMergeDir = parameters.Paths.Directories.ArtifactsBinFullFxILMerge;
var portableDir = parameters.Paths.Directories.ArtifactsBinFullFxPortable.Combine("tools");
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");

// Portable
PublishILRepackedGitVersionExe(true, ilMergeDir, portableDir, parameters);
// Commandline
PublishILRepackedGitVersionExe(false, ilMergeDir, cmdlineDir, parameters);

// Ruby Gem
var gemPath = new DirectoryPath("./src/GitVersionRubyGem/bin");
EnsureDirectoryExists(gemPath);
CopyFileToDirectory(portableDir + "/" + "LibGit2Sharp.dll.config", gemPath);
CopyFileToDirectory(portableDir + "/" + "GitVersion.exe", gemPath);
CopyDirectory(portableDir.Combine("lib"), gemPath.Combine("lib"));
DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
{
Framework = framework,
Configuration = parameters.Configuration,
MSBuildSettings = parameters.MSBuildSettings
});
}

var sourceDir = parameters.Paths.Directories.Native.Combine(parameters.NativeRuntimes[PlatformFamily.Windows]);
var sourceFiles = GetFiles(sourceDir + "/*.*");

// RubyGem
var gemDir = new DirectoryPath("./src/GitVersionRubyGem/bin");
EnsureDirectoryExists(gemDir);
CopyFiles(sourceFiles, gemDir);

// Cmdline and Portable
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinCmdline.Combine("tools");
var portableDir = parameters.Paths.Directories.ArtifactsBinPortable.Combine("tools");

EnsureDirectoryExists(cmdlineDir);
EnsureDirectoryExists(portableDir);

CopyFiles(sourceFiles, cmdlineDir);

sourceFiles += GetFiles("./nuspec/*.ps1") + GetFiles("./nuspec/*.txt");
CopyFiles(sourceFiles, portableDir);
});

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

// build and pack

var settings = new TfxExtensionCreateSettings
{
ToolPath = workDir + "/node_modules/.bin/" + (parameters.IsRunningOnWindows ? "tfx.cmd" : "tfx"),
Expand All @@ -217,7 +229,7 @@ Task("Pack-Vsix")
});

Task("Pack-Gem")
.IsDependentOn("Copy-Files")
.IsDependentOn("Pack-Prepare")
.Does<BuildParameters>((parameters) =>
{
var workDir = "./src/GitVersionRubyGem";
Expand All @@ -237,7 +249,7 @@ Task("Pack-Gem")
});

Task("Pack-Nuget")
.IsDependentOn("Copy-Files")
.IsDependentOn("Pack-Prepare")
.Does<BuildParameters>((parameters) =>
{
foreach(var package in parameters.Packages.Nuget)
Expand All @@ -263,8 +275,6 @@ Task("Pack-Nuget")
{
Configuration = parameters.Configuration,
OutputDirectory = parameters.Paths.Directories.NugetRoot,
NoBuild = true,
NoRestore = true,
MSBuildSettings = parameters.MSBuildSettings
};

Expand All @@ -278,41 +288,38 @@ Task("Pack-Nuget")
Task("Pack-Chocolatey")
.WithCriteria<BuildParameters>((context, parameters) => parameters.IsRunningOnWindows, "Pack-Chocolatey works only on Windows agents.")
.WithCriteria<BuildParameters>((context, parameters) => parameters.IsMainBranch, "Pack-Chocolatey works only for main branch.")
.IsDependentOn("Copy-Files")
.IsDependentOn("Pack-Prepare")
.Does<BuildParameters>((parameters) =>
{
foreach(var package in parameters.Packages.Chocolatey)
{
if (FileExists(package.NuspecPath)) {
var artifactPath = MakeAbsolute(parameters.PackagesBuildMap[package.Id]).FullPath;

var files = GetFiles(artifactPath + "/**/*.*")
.Select(file => new ChocolateyNuSpecContent { Source = file.FullPath, Target = file.FullPath.Replace(artifactPath, "") });
var txtFiles = (GetFiles("./nuspec/*.txt") + GetFiles("./nuspec/*.ps1"))
.Select(file => new ChocolateyNuSpecContent { Source = file.FullPath, Target = file.GetFilename().ToString() });

ChocolateyPack(package.NuspecPath, new ChocolateyPackSettings {
var chocolateySettings = new ChocolateyPackSettings
{
Verbose = true,
Version = parameters.Version.SemVersion,
OutputDirectory = parameters.Paths.Directories.NugetRoot,
Files = files.Concat(txtFiles).ToArray()
});
Files = GetFiles(artifactPath + "/**/*.*")
.Select(file => new ChocolateyNuSpecContent { Source = file.FullPath, Target = file.FullPath.Replace(artifactPath, "") })
.ToArray()
};
ChocolateyPack(package.NuspecPath, chocolateySettings);
}
}
});

Task("Zip-Files")
.IsDependentOn("Copy-Files")
.IsDependentOn("Pack-Prepare")
.Does<BuildParameters>((parameters) =>
{
// .NET Framework
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");
var fullFxFiles = GetFiles(cmdlineDir.FullPath + "/**/*");
Zip(cmdlineDir, parameters.Paths.Files.ZipArtifactPathDesktop, fullFxFiles);

// .NET Core
var coreFxDir = parameters.Paths.Directories.ArtifactsBinCoreFx21.Combine("tools");
var coreclrFiles = GetFiles(coreFxDir.FullPath + "/**/*");
Zip(coreFxDir, parameters.Paths.Files.ZipArtifactPathCoreClr, coreclrFiles);
foreach(var runtime in parameters.NativeRuntimes)
{
var sourceDir = parameters.Paths.Directories.Native.Combine(runtime.Value);
var fileName = $"gitversion-{runtime.Key}-{parameters.Version.SemVersion}.tar.gz".ToLower();
var tarFile = parameters.Paths.Directories.Artifacts.CombineWithFilePath(fileName);
GZipCompress(sourceDir, tarFile);
}
});
#endregion
8 changes: 6 additions & 2 deletions build/publish.cake
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ Task("Release-Notes")
TargetCommitish = "master"
});

GitReleaseManagerAddAssets(token, repoOwner, repository, parameters.Version.Milestone, parameters.Paths.Files.ZipArtifactPathDesktop.ToString());
GitReleaseManagerAddAssets(token, repoOwner, repository, parameters.Version.Milestone, parameters.Paths.Files.ZipArtifactPathCoreClr.ToString());
var zipFiles = GetFiles(parameters.Paths.Directories.Artifacts + "/*.tar.gz");
foreach(var zipFile in zipFiles)
{
GitReleaseManagerAddAssets(token, repoOwner, repository, parameters.Version.Milestone, zipFile.ToString());
}

GitReleaseManagerClose(token, repoOwner, repository, parameters.Version.Milestone);

}).ReportError(exception =>
Expand Down
10 changes: 7 additions & 3 deletions build/stages/common-steps.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
steps:
- task: UseDotNet@2
displayName: 'Use .NET Core sdk'
displayName: 'Use .NET Core sdk 2.1'
inputs:
packageType: sdk
version: 2.2.401
installationPath: $(Agent.ToolsDirectory)/dotnet
version: 2.1.802
- task: UseDotNet@2
displayName: 'Use .NET Core sdk 3.0'
inputs:
packageType: sdk
version: 3.0.100
- task: Bash@3
displayName: 'Env Vars'
inputs:
Expand Down
9 changes: 6 additions & 3 deletions build/utils/docker.cake
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ void DockerBuild(DockerImage dockerImage, BuildParameters parameters)
var (os, distro, targetframework) = dockerImage;
var workDir = DirectoryPath.FromString($"./src/Docker");

var sourceDir = targetframework.StartsWith("netcoreapp")
? parameters.Paths.Directories.ArtifactsBinCoreFx21.Combine("tools")
: parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");
var sourceDir = parameters.Paths.Directories.ArtifactsBin.Combine(targetframework);

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

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

if (os == "windows" && targetframework == parameters.CoreFxVersion30)
{
cmd = "-Command " + cmd; // powershell 7 needs a -Command parameter
}

DockerTestRun(settings, parameters, tag, "pwsh", cmd);
}

Expand Down
21 changes: 14 additions & 7 deletions build/utils/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ public class BuildParameters

public const string MainRepoOwner = "gittools";
public const string MainRepoName = "GitVersion";
public string CoreFxVersion21 { get; private set; } = "netcoreapp2.1";
public string FullFxVersion { get; private set; } = "net472";
public string CoreFxVersion21 { get; private set; } = "netcoreapp2.1";
public string CoreFxVersion30 { get; private set; } = "netcoreapp3.0";
public string FullFxVersion472 { get; private set; } = "net472";

public string DockerDistro { get; private set; }
public string DockerDotnetVersion { get; private set; }
Expand Down Expand Up @@ -51,6 +52,7 @@ public class BuildParameters
public BuildArtifacts Artifacts { get; private set; }
public DockerImages Docker { get; private set; }
public Dictionary<string, DirectoryPath> PackagesBuildMap { get; private set; }
public Dictionary<PlatformFamily, string> NativeRuntimes { get; private set; }

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

var files = Paths.Files;

var buildArtifacts = context.GetFiles(Paths.Directories.BuildArtifact + "/*.*");
buildArtifacts += files.ZipArtifactPathDesktop;
buildArtifacts += files.ZipArtifactPathCoreClr;
var buildArtifacts = context.GetFiles(Paths.Directories.BuildArtifact + "/*.*") + context.GetFiles(Paths.Directories.Artifacts + "/*.tar.gz");
buildArtifacts += files.ReleaseNotesOutputFilePath;

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

PackagesBuildMap = new Dictionary<string, DirectoryPath>
{
["GitVersion.CommandLine"] = Paths.Directories.ArtifactsBinFullFxCmdline,
["GitVersion.Portable"] = Paths.Directories.ArtifactsBinFullFxPortable,
["GitVersion.CommandLine"] = Paths.Directories.ArtifactsBinCmdline,
["GitVersion.Portable"] = Paths.Directories.ArtifactsBinPortable,
};

NativeRuntimes = new Dictionary<PlatformFamily, string>
{
[PlatformFamily.Windows] = "win-x64",
[PlatformFamily.Linux] = "linux-x64",
[PlatformFamily.OSX] = "osx-x64",
};

Credentials = BuildCredentials.GetCredentials(context);
Expand Down
Loading