public static BuildTargetResult GenerateVersions(BuildTargetContext c) { var gitResult = Cmd("git", "rev-list", "--count", "HEAD") .CaptureStdOut() .Execute(); gitResult.EnsureSuccessful(); var commitCount = int.Parse(gitResult.StdOut); gitResult = Cmd("git", "rev-parse", "HEAD") .CaptureStdOut() .Execute(); gitResult.EnsureSuccessful(); var commitHash = gitResult.StdOut.Trim(); var branchInfo = ReadBranchInfo(c, Path.Combine(c.BuildContext.BuildDirectory, "branchinfo.txt")); var buildVersion = new BuildVersion() { Major = int.Parse(branchInfo["MAJOR_VERSION"]), Minor = int.Parse(branchInfo["MINOR_VERSION"]), Patch = int.Parse(branchInfo["PATCH_VERSION"]), ReleaseSuffix = branchInfo["RELEASE_SUFFIX"], CommitCount = commitCount }; c.BuildContext["BuildVersion"] = buildVersion; c.BuildContext["CommitHash"] = commitHash; c.Info($"Building Version: {buildVersion.SimpleVersion} (NuGet Packages: {buildVersion.NuGetVersion})"); c.Info($"From Commit: {commitHash}"); return c.Success(); }
private static void AcquireWix(BuildTargetContext c) { if (File.Exists(Path.Combine(WixRoot, "candle.exe"))) { return; } Directory.CreateDirectory(WixRoot); c.Info("Downloading WixTools.."); DownloadFile($"https://dotnetcli.blob.core.windows.net/build/wix/wix.{WixVersion}.zip", Path.Combine(WixRoot, "WixTools.zip")); c.Info("Extracting WixTools.."); ZipFile.ExtractToDirectory(Path.Combine(WixRoot, "WixTools.zip"), WixRoot); }
public static BuildTargetResult ReplaceProjectJson(BuildTargetContext c) { List<DependencyInfo> dependencyInfos = c.GetDependencyInfos(); IEnumerable<string> projectJsonFiles = Enumerable.Union( Directory.GetFiles(Dirs.RepoRoot, "project.json", SearchOption.AllDirectories), Directory.GetFiles(Path.Combine(Dirs.RepoRoot, @"src\dotnet\commands\dotnet-new"), "project.json.template", SearchOption.AllDirectories)); JObject projectRoot; foreach (string projectJsonFile in projectJsonFiles) { try { projectRoot = ReadProject(projectJsonFile); } catch (Exception e) { c.Warn($"Non-fatal exception occurred reading '{projectJsonFile}'. Skipping file. Exception: {e}. "); continue; } bool changedAnyPackage = FindAllDependencyProperties(projectRoot) .Select(dependencyProperty => ReplaceDependencyVersion(dependencyProperty, dependencyInfos)) .ToArray() .Any(shouldWrite => shouldWrite); if (changedAnyPackage) { c.Info($"Writing changes to {projectJsonFile}"); WriteProject(projectRoot, projectJsonFile); } } return c.Success(); }
private static void AcquireWix(BuildTargetContext c) { if (File.Exists(Path.Combine(WixRoot, "candle.exe"))) { return; } Directory.CreateDirectory(WixRoot); c.Info("Downloading WixTools.."); // Download Wix version 3.10.2 - https://wix.codeplex.com/releases/view/619491 Cmd("powershell", "-NoProfile", "-NoLogo", $"Invoke-WebRequest -Uri https://wix.codeplex.com/downloads/get/1540241 -Method Get -OutFile {WixRoot}\\WixTools.zip") .Execute() .EnsureSuccessful(); c.Info("Extracting WixTools.."); ZipFile.ExtractToDirectory($"{WixRoot}\\WixTools.zip", WixRoot); }
public static BuildTargetResult Init(BuildTargetContext c) { var configEnv = Environment.GetEnvironmentVariable("CONFIGURATION"); if (string.IsNullOrEmpty(configEnv)) { configEnv = "Debug"; } c.BuildContext["Configuration"] = configEnv; c.BuildContext["Channel"] = Environment.GetEnvironmentVariable("CHANNEL"); c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}"); c.Info("Build Environment:"); c.Info($" Operating System: {RuntimeEnvironment.OperatingSystem} {RuntimeEnvironment.OperatingSystemVersion}"); c.Info($" Platform: {RuntimeEnvironment.OperatingSystemPlatform}"); return c.Success(); }
public static BuildTargetResult GenerateVersions(BuildTargetContext c) { var commitCount = GitUtils.GetCommitCount(); var commitHash = GitUtils.GetCommitHash(); var branchInfo = ReadBranchInfo(c, Path.Combine(c.BuildContext.BuildDirectory, "branchinfo.txt")); var buildVersion = new BuildVersion() { Major = int.Parse(branchInfo["MAJOR_VERSION"]), Minor = int.Parse(branchInfo["MINOR_VERSION"]), Patch = int.Parse(branchInfo["PATCH_VERSION"]), ReleaseSuffix = branchInfo["RELEASE_SUFFIX"], CommitCount = commitCount }; c.BuildContext["BuildVersion"] = buildVersion; c.BuildContext["BranchName"] = branchInfo["BRANCH_NAME"]; c.BuildContext["CommitHash"] = commitHash; c.Info($"Building Version: {buildVersion.SimpleVersion} (NuGet Packages: {buildVersion.NuGetVersion})"); c.Info($"From Commit: {commitHash}"); return c.Success(); }
public static BuildTargetResult GenerateSdkDeb(BuildTargetContext c) { // Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools // So we need to skip this target if the tools aren't present. // https://github.com/dotnet/core-setup/issues/167 if (DebuildNotPresent()) { c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}"); return c.Success(); } var channel = c.BuildContext.Get<string>("Channel").ToLower(); var packageName = CliMonikers.GetSdkDebianPackageName(c); var version = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion; var debFile = c.BuildContext.Get<string>("SdkInstallerFile"); var manPagesDir = Path.Combine(Dirs.RepoRoot, "Documentation", "manpages"); var sdkPublishRoot = c.BuildContext.Get<string>("CLISDKRoot"); var sharedFxDebianPackageName = Monikers.GetDebianSharedFrameworkPackageName(CliDependencyVersions.SharedFrameworkVersion); var debianConfigFile = Path.Combine(Dirs.DebPackagingConfig, "dotnet-debian_config.json"); var postinstallFile = Path.Combine(Dirs.DebPackagingConfig, "postinst"); var debianConfigVariables = new Dictionary<string, string>() { { "SHARED_FRAMEWORK_DEBIAN_PACKAGE_NAME", sharedFxDebianPackageName }, { "SHARED_FRAMEWORK_NUGET_NAME", Monikers.SharedFrameworkName }, { "SHARED_FRAMEWORK_NUGET_VERSION", CliDependencyVersions.SharedFrameworkVersion }, { "SHARED_FRAMEWORK_BRAND_NAME", Monikers.SharedFxBrandName }, { "SDK_NUGET_VERSION", version }, { "CLI_SDK_BRAND_NAME", Monikers.CLISdkBrandName } }; var debCreator = new DebPackageCreator( DotNetCli.Stage2, Dirs.Intermediate); debCreator.CreateDeb( debianConfigFile, packageName, version, sdkPublishRoot, debianConfigVariables, debFile, manpagesDirectory: manPagesDir, versionManpages: true, debianFiles: new string[] { postinstallFile }); return c.Success(); }
public static void BuildTestAssetPackages(BuildTargetContext c) { var dotnet = DotNetCli.Stage2; Rmdir(Dirs.TestPackages); Mkdirp(Dirs.TestPackages); foreach (var relativePath in TestPackageProjects) { var fullPath = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages", relativePath.Replace('/', Path.DirectorySeparatorChar)); c.Info($"Packing: {fullPath}"); dotnet.Pack("--output", Dirs.TestPackages) .WorkingDirectory(fullPath) .Execute() .EnsureSuccessful(); } }
public static void BuildTestAssetProjects(BuildTargetContext c) { var dotnet = DotNetCli.Stage2; string testProjectsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"); List<string> exclusionList = new List<string> { Path.Combine(testProjectsRoot, "CompileFail", "project.json") }; var projects = Directory.GetFiles(testProjectsRoot, "project.json", SearchOption.AllDirectories) .Where(p => !exclusionList.Any(e => e.Contains(p))); foreach (var project in projects) { c.Info($"Building: {project}"); dotnet.Build("--framework", "dnxcore50") .WorkingDirectory(Path.GetDirectoryName(project)) .Execute() .EnsureSuccessful(); } }
public static BuildTargetResult ValidateDependencies(BuildTargetContext c) { var configuration = c.BuildContext.Get<string>("Configuration"); var dotnet = DotNetCli.Stage2; c.Info("Publishing MultiProjectValidator"); dotnet.Publish("--output", Path.Combine(Dirs.Output, "tools"), "--configuration", configuration) .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "tools", "MultiProjectValidator")) .Execute() .EnsureSuccessful(); var validator = Path.Combine(Dirs.Output, "tools", $"pjvalidate{Constants.ExeSuffix}"); Cmd(validator, Path.Combine(c.BuildContext.BuildDirectory, "src")) .Execute(); return c.Success(); }
private static Dictionary<string, string> LoadVsVars(BuildTargetContext c) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return new Dictionary<string, string>(); } c.Verbose("Start Collecting Visual Studio Environment Variables"); var vsvarsPath = Path.GetFullPath(Path.Combine(Environment.GetEnvironmentVariable("VS140COMNTOOLS"), "..", "..", "VC")); // Write a temp batch file because that seems to be the easiest way to do this (argument parsing is hard) var temp = Path.Combine(Path.GetTempPath(), $"{Path.GetRandomFileName()}.cmd"); File.WriteAllText(temp, $@"@echo off cd {vsvarsPath} call vcvarsall.bat x64 set"); CommandResult result; try { result = Cmd(Environment.GetEnvironmentVariable("COMSPEC"), "/c", temp) .WorkingDirectory(vsvarsPath) .CaptureStdOut() .Execute(); } finally { if (File.Exists(temp)) { File.Delete(temp); } } result.EnsureSuccessful(); var vars = new Dictionary<string, string>(); foreach (var line in result.StdOut.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { var splat = line.Split(new[] { '=' }, 2); if (splat.Length == 2) { c.Verbose($"Adding variable '{line}'"); vars[splat[0]] = splat[1]; } else { c.Info($"Skipping VS Env Variable. Unknown format: '{line}'"); } } c.Verbose("Finish Collecting Visual Studio Environment Variables"); return vars; }
public static BuildTargetResult BuildTestAssetPackages(BuildTargetContext c) { CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages")); var dotnet = DotNetCli.Stage2; Rmdir(Dirs.TestPackages); Mkdirp(Dirs.TestPackages); foreach (var testPackageProject in TestPackageProjects.Projects.Where(p => p.IsApplicable)) { var relativePath = testPackageProject.Path; var versionSuffix = testPackageProject.VersionSuffix; if (versionSuffix.Equals(s_testPackageBuildVersionSuffix)) { versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").CommitCountString; } var fullPath = Path.Combine(c.BuildContext.BuildDirectory, relativePath.Replace('/', Path.DirectorySeparatorChar)); c.Info($"Packing: {fullPath}"); var packageBuildFrameworks = testPackageProject.Frameworks.ToList(); if (!CurrentPlatform.IsWindows) { packageBuildFrameworks.RemoveAll(f => f.StartsWith("net4")); } foreach (var packageBuildFramework in packageBuildFrameworks) { var buildArgs = new List<string>(); buildArgs.Add("-f"); buildArgs.Add(packageBuildFramework); buildArgs.Add("--build-base-path"); buildArgs.Add(Dirs.TestPackagesBuild); buildArgs.Add(fullPath); Mkdirp(Dirs.TestPackagesBuild); dotnet.Build(buildArgs.ToArray()) .Execute() .EnsureSuccessful(); } var projectJson = Path.Combine(fullPath, "project.json"); var dotnetPackArgs = new List<string> { projectJson, "--no-build", "--build-base-path", Dirs.TestPackagesBuild, "--output", Dirs.TestPackages }; if (!string.IsNullOrEmpty(versionSuffix)) { dotnetPackArgs.Add("--version-suffix"); dotnetPackArgs.Add(versionSuffix); } dotnet.Pack(dotnetPackArgs.ToArray()) .Execute() .EnsureSuccessful(); } return c.Success(); }
public static BuildTargetResult RunXUnitTests(BuildTargetContext c) { // Need to load up the VS Vars var dotnet = DotNetCli.Stage2; var vsvars = LoadVsVars(c); // Copy the test projects var testProjectsDir = Path.Combine(Dirs.TestOutput, "TestProjects"); Rmdir(testProjectsDir); Mkdirp(testProjectsDir); CopyRecursive(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"), testProjectsDir); // Run the tests and set the VS vars in the environment when running them var failingTests = new List<string>(); foreach (var project in TestProjects) { c.Info("Running tests in: {project}"); var result = dotnet.Test("-xml", $"{project}-testResults.xml", "-notrait", "category=failing") .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", project)) .Environment(vsvars) .EnvironmentVariable("PATH", $"{DotNetCli.Stage2.BinPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}") .Execute(); if (result.ExitCode != 0) { failingTests.Add(project); } } if (failingTests.Any()) { foreach (var project in failingTests) { c.Error($"{project} failed"); } return c.Failed("Tests failed!"); } return c.Success(); }
private static BuildTargetResult Crossgen(BuildTargetContext c, string outputDir) { // Check if we need to skip crossgen if (string.Equals(Environment.GetEnvironmentVariable("DOTNET_BUILD_SKIP_CROSSGEN"), "1")) { c.Warn("Skipping crossgen because DOTNET_BUILD_SKIP_CROSSGEN is set"); return c.Success(); } // Find crossgen string packageId; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { packageId = "runtime.win7-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var osname = PlatformServices.Default.Runtime.OperatingSystem; if (string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase)) { packageId = "runtime.ubuntu.14.04-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else if (string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase)) { // CentOS runtime is in the runtime.rhel.7-x64... package. packageId = "runtime.rhel.7-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else { return c.Failed($"Unknown Linux Distro: {osname}"); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { packageId = "runtime.osx.10.10-x64.Microsoft.NETCore.Runtime.CoreCLR"; } else { return c.Failed("Unsupported OS Platform"); } var crossGenExePath = Path.Combine( Dirs.NuGetPackages, packageId, CoreCLRVersion, "tools", $"crossgen{Constants.ExeSuffix}"); // We have to copy crossgen next to mscorlib var crossgen = Path.Combine(outputDir, $"crossgen{Constants.ExeSuffix}"); File.Copy(crossGenExePath, crossgen, overwrite: true); Chmod(crossgen, "a+x"); // And if we have mscorlib.ni.dll, we need to rename it to mscorlib.dll if (File.Exists(Path.Combine(outputDir, "mscorlib.ni.dll"))) { File.Copy(Path.Combine(outputDir, "mscorlib.ni.dll"), Path.Combine(outputDir, "mscorlib.dll"), overwrite: true); } foreach (var assemblyToCrossgen in AssembliesToCrossGen) { c.Info($"Crossgenning {assemblyToCrossgen}"); ExecInSilent(outputDir, crossgen, "-nologo", "-platform_assemblies_paths", outputDir, assemblyToCrossgen); } c.Info("Crossgen complete"); // Check if csc/vbc.ni.exe exists, and overwrite the dll with it just in case if (File.Exists(Path.Combine(outputDir, "csc.ni.exe")) && !File.Exists(Path.Combine(outputDir, "csc.ni.dll"))) { File.Move(Path.Combine(outputDir, "csc.ni.exe"), Path.Combine(outputDir, "csc.ni.dll")); } if (File.Exists(Path.Combine(outputDir, "vbc.ni.exe")) && !File.Exists(Path.Combine(outputDir, "vbc.ni.dll"))) { File.Move(Path.Combine(outputDir, "vbc.ni.exe"), Path.Combine(outputDir, "vbc.ni.dll")); } return c.Success(); }
public static BuildTargetResult CheckPackageCache(BuildTargetContext c) { var ciBuild = string.Equals(Environment.GetEnvironmentVariable("CI_BUILD"), "1", StringComparison.Ordinal); if (ciBuild) { // On CI, HOME is redirected under the repo, which gets deleted after every build. // So make NUGET_PACKAGES outside of the repo. var nugetPackages = Path.GetFullPath(Path.Combine(c.BuildContext.BuildDirectory, "..", ".nuget", "packages")); Environment.SetEnvironmentVariable("NUGET_PACKAGES", nugetPackages); Dirs.NuGetPackages = nugetPackages; } // Set the package cache location in NUGET_PACKAGES just to be safe if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NUGET_PACKAGES"))) { Environment.SetEnvironmentVariable("NUGET_PACKAGES", Dirs.NuGetPackages); } CleanNuGetTempCache(); // Determine cache expiration time var cacheExpiration = 7 * 24; // cache expiration in hours var cacheExpirationStr = Environment.GetEnvironmentVariable("NUGET_PACKAGES_CACHE_TIME_LIMIT"); if (!string.IsNullOrEmpty(cacheExpirationStr)) { cacheExpiration = int.Parse(cacheExpirationStr); } if (ciBuild) { var cacheTimeFile = Path.Combine(Dirs.NuGetPackages, "packageCacheTime.txt"); DateTime? cacheTime = null; try { // Read the cache file if (File.Exists(cacheTimeFile)) { var content = File.ReadAllText(cacheTimeFile); if (!string.IsNullOrEmpty(content)) { cacheTime = DateTime.ParseExact("O", content, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } } } catch (Exception ex) { c.Warn($"Error reading NuGet cache time file, leaving the cache alone"); c.Warn($"Error Detail: {ex.ToString()}"); } if (cacheTime == null || (cacheTime.Value.AddHours(cacheExpiration) < DateTime.UtcNow)) { // Cache has expired or the status is unknown, clear it and write the file c.Info("Clearing NuGet cache"); Rmdir(Dirs.NuGetPackages); Mkdirp(Dirs.NuGetPackages); File.WriteAllText(cacheTimeFile, DateTime.UtcNow.ToString("O")); } } return c.Success(); }
public static BuildTargetResult RemovePackages(BuildTargetContext c) { // Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools // So we need to skip this target if the tools aren't present. // https://github.com/dotnet/core-setup/issues/167 if (DebuildNotPresent()) { c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}"); return c.Success(); } IEnumerable<string> orderedPackageNames = new List<string>() { CliMonikers.GetSdkDebianPackageName(c), Monikers.GetDebianSharedFrameworkPackageName(CliDependencyVersions.SharedFrameworkVersion), Monikers.GetDebianHostFxrPackageName(CliDependencyVersions.HostFxrVersion), Monikers.GetDebianSharedHostPackageName(c) }; foreach(var packageName in orderedPackageNames) { RemovePackage(packageName); } return c.Success(); }
public static BuildTargetResult LocateStage0(BuildTargetContext c) { // We should have been run in the repo root, so locate the stage 0 relative to current directory var stage0 = DotNetCli.Stage0.BinPath; if (!Directory.Exists(stage0)) { return c.Failed($"Stage 0 directory does not exist: {stage0}"); } // Identify the version string versionFile = Directory.GetFiles(stage0, ".version", SearchOption.AllDirectories).FirstOrDefault(); if (string.IsNullOrEmpty(versionFile)) { throw new Exception($"'.version' file not found in '{stage0}' folder"); } var version = File.ReadAllLines(versionFile); c.Info($"Using Stage 0 Version: {version[1]}"); return c.Success(); }
public static BuildTargetResult RunE2ETest(BuildTargetContext c) { // Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools // So we need to skip this target if the tools aren't present. // https://github.com/dotnet/core-setup/issues/167 if (DebuildNotPresent()) { c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}"); return c.Success(); } Directory.SetCurrentDirectory(Path.Combine(Dirs.RepoRoot, "test", "EndToEnd")); Cmd("dotnet", "build") .Execute() .EnsureSuccessful(); var testResultsPath = Path.Combine(Dirs.Output, "obj", "debian", "test", "debian-endtoend-testResults.xml"); Cmd("dotnet", "test", "-xml", testResultsPath) .Execute() .EnsureSuccessful(); return c.Success(); }
public static BuildTargetResult BuildTestAssetProjects(BuildTargetContext c) { var dotnet = DotNetCli.Stage2; var nobuildFileName = ".noautobuild"; string testProjectsRoot = Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"); var projects = Directory.GetFiles(testProjectsRoot, "project.json", SearchOption.AllDirectories) .Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), nobuildFileName))); foreach (var project in projects) { c.Info($"Building: {project}"); dotnet.Build("--framework", "dnxcore50") .WorkingDirectory(Path.GetDirectoryName(project)) .Execute() .EnsureSuccessful(); } return c.Success(); }
public static BuildTargetResult BuildTests(BuildTargetContext c) { var dotnet = DotNetCli.Stage2; var configuration = c.BuildContext.Get<string>("Configuration"); foreach (var testProject in GetTestProjects()) { c.Info($"Building tests: {testProject}"); dotnet.Build("--configuration", configuration) .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", testProject)) .Execute() .EnsureSuccessful(); } return c.Success(); }
public static BuildTargetResult TriggerDockerHubBuilds(BuildTargetContext c) { string dockerHubRepo = Environment.GetEnvironmentVariable("DOCKER_HUB_REPO"); string dockerHubTriggerToken = Environment.GetEnvironmentVariable("DOCKER_HUB_TRIGGER_TOKEN"); Uri baseDockerHubUri = new Uri("https://registry.hub.docker.com/u/"); Uri dockerHubTriggerUri; if (!Uri.TryCreate(baseDockerHubUri, $"{dockerHubRepo}/trigger/{dockerHubTriggerToken}/", out dockerHubTriggerUri)) { return c.Failed("Invalid DOCKER_HUB_REPO and/or DOCKER_HUB_TRIGGER_TOKEN"); } c.Info($"Triggering automated DockerHub builds for {dockerHubRepo}"); using (HttpClient client = new HttpClient()) { StringContent requestContent = new StringContent("{\"build\": true}", Encoding.UTF8, "application/json"); try { HttpResponseMessage response = client.PostAsync(dockerHubTriggerUri, requestContent).Result; if (!response.IsSuccessStatusCode) { StringBuilder sb = new StringBuilder(); sb.AppendLine($"HTTP request to {dockerHubTriggerUri.ToString()} was unsuccessful."); sb.AppendLine($"Response status code: {response.StatusCode}. Reason phrase: {response.ReasonPhrase}."); sb.Append($"Respone content: {response.Content.ReadAsStringAsync().Result}"); return c.Failed(sb.ToString()); } } catch (AggregateException e) { return c.Failed($"HTTP request to {dockerHubTriggerUri.ToString()} failed. {e.ToString()}"); } } return c.Success(); }
private static BuildTargetResult BuildTestAssets(BuildTargetContext c, string testAssetsRoot, DotNetCli dotnet, string framework) { CleanBinObj(c, testAssetsRoot); var nobuildFileName = ".noautobuild"; var projects = Directory.GetFiles(testAssetsRoot, "project.json", SearchOption.AllDirectories) .Where(p => !ConditionalTestAssets.Where(s => !s.Skip() && p.EndsWith(Path.Combine(s.Path, "project.json"))).Any()) .Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), nobuildFileName))); foreach (var project in projects) { c.Info($"Building: {project}"); dotnet.Build("--framework", framework) .WorkingDirectory(Path.GetDirectoryName(project)) .Execute() .EnsureSuccessful(); } return c.Success(); }
public static BuildTargetResult Publish(BuildTargetContext c) { if (string.Equals(Environment.GetEnvironmentVariable("DOTNET_BUILD_SKIP_PACKAGING"), "1", StringComparison.Ordinal)) { c.Info("Skipping packaging because DOTNET_BUILD_SKIP_PACKAGING is set"); return c.Success(); } // NOTE(anurse): Currently, this just invokes the remaining build scripts as-is. We should port those to C# as well, but // I want to get the merged in. // Set up the environment variables previously defined by common.sh/ps1 // This is overkill, but I want to cover all the variables used in all OSes (including where some have the same names) var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion"); var env = new Dictionary<string, string>() { { "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() }, { "OSNAME", PlatformServices.Default.Runtime.OperatingSystem }, { "TFM", "dnxcore50" }, { "OutputDir", Dirs.Output }, { "Stage1Dir", Dirs.Stage1 }, { "Stage1CompilationDir", Dirs.Stage1Compilation }, { "Stage2Dir", Dirs.Stage2 }, { "STAGE2_DIR", Dirs.Stage2 }, { "Stage2CompilationDir", Dirs.Stage2Compilation }, { "HostDir", Dirs.Corehost }, { "PackageDir", Path.Combine(Dirs.Packages, "dnvm") }, // Legacy name { "TestBinRoot", Dirs.TestOutput }, { "TestPackageDir", Dirs.TestPackages }, { "MajorVersion", buildVersion.Major.ToString() }, { "MinorVersion", buildVersion.Minor.ToString() }, { "PatchVersion", buildVersion.Patch.ToString() }, { "CommitCountVersion", buildVersion.CommitCountString }, { "COMMIT_COUNT_VERSION", buildVersion.CommitCountString }, { "DOTNET_CLI_VERSION", buildVersion.SimpleVersion }, { "DOTNET_MSI_VERSION", buildVersion.GenerateMsiVersion() }, { "VersionSuffix", buildVersion.VersionSuffix } }; if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { env["OSNAME"] = "osx"; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Cmd("powershell", "-NoProfile", "-NoLogo", Path.Combine(c.BuildContext.BuildDirectory, "scripts", "package", "package.ps1")) .Environment(env) .Execute() .EnsureSuccessful(); } else { // Can directly execute scripts on Unix :). Thank you shebangs! Cmd(Path.Combine(c.BuildContext.BuildDirectory, "scripts", "package", "package.sh")) .Environment(env) .Execute() .EnsureSuccessful(); } return c.Success(); }
public static BuildTargetResult LocateStage0(BuildTargetContext c) { // We should have been run in the repo root, so locate the stage 0 relative to current directory var stage0 = DotNetCli.Stage0.BinPath; if (!Directory.Exists(stage0)) { return c.Failed($"Stage 0 directory does not exist: {stage0}"); } // Identify the version var version = File.ReadAllLines(Path.Combine(stage0, "..", ".version")); c.Info($"Using Stage 0 Version: {version[1]}"); return c.Success(); }
public static BuildTargetResult CreatePR(BuildTargetContext c) { string remoteBranchName = c.GetRemoteBranchName(); NewPullRequest prInfo = new NewPullRequest( PullRequestTitle, s_config.GitHubOriginOwner + ":" + remoteBranchName, s_config.GitHubUpstreamBranch); GitHubClient gitHub = new GitHubClient(new ProductHeaderValue("dotnetDependencyUpdater")); gitHub.Credentials = new Credentials(s_config.Password); PullRequest createdPR = gitHub.PullRequest.Create(s_config.GitHubUpstreamOwner, s_config.GitHubProject, prInfo).Result; c.Info($"Created Pull Request: {createdPR.HtmlUrl}"); return c.Success(); }
public static BuildTargetResult BuildTests(BuildTargetContext c) { var dotnet = DotNetCli.Stage2; foreach (var testProject in TestProjects) { c.Info($"Building tests: {testProject}"); dotnet.Build() .WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "test", testProject)) .Execute() .EnsureSuccessful(); } return c.Success(); }
public static BuildTargetResult InstallHostFxr(BuildTargetContext c) { // Ubuntu 16.04 Jenkins Machines don't have docker or debian package build tools // So we need to skip this target if the tools aren't present. // https://github.com/dotnet/core-setup/issues/167 if (DebuildNotPresent()) { c.Info("Debuild not present, skipping target: {nameof(RemovePackages)}"); return c.Success(); } InstallPackage(c.BuildContext.Get<string>("HostFxrInstallerFile")); return c.Success(); }
public static BuildTargetResult BuildTestAssetPackages(BuildTargetContext c) { CleanBinObj(c, Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestPackages")); var dotnet = DotNetCli.Stage2; Rmdir(Dirs.TestPackages); Mkdirp(Dirs.TestPackages); foreach (var relativePath in TestPackageProjects.Where(p => p.IsApplicable()).Select(p => p.Path)) { var fullPath = Path.Combine(c.BuildContext.BuildDirectory, relativePath.Replace('/', Path.DirectorySeparatorChar)); c.Info($"Packing: {fullPath}"); dotnet.Pack("--output", Dirs.TestPackages) .WorkingDirectory(fullPath) .Execute() .EnsureSuccessful(); } return c.Success(); }
public static BuildTargetResult CreatePR(BuildTargetContext c) { string remoteBranchName = c.GetRemoteBranchName(); string commitMessage = c.GetCommitMessage(); NewPullRequest prInfo = new NewPullRequest( commitMessage, s_config.GitHubOriginOwner + ":" + remoteBranchName, s_config.GitHubUpstreamBranch); string[] prNotifications = s_config.GitHubPullRequestNotifications; if (prNotifications.Length > 0) { prInfo.Body = $"/cc @{string.Join(" @", prNotifications)}"; } GitHubClient gitHub = new GitHubClient(new ProductHeaderValue("dotnetDependencyUpdater")); gitHub.Credentials = new Credentials(s_config.Password); PullRequest createdPR = gitHub.PullRequest.Create(s_config.GitHubUpstreamOwner, s_config.GitHubProject, prInfo).Result; c.Info($"Created Pull Request: {createdPR.HtmlUrl}"); return c.Success(); }
public static BuildTargetResult CheckPackageCache(BuildTargetContext c) { var ciBuild = string.Equals(Environment.GetEnvironmentVariable("CI_BUILD"), "1", StringComparison.Ordinal); // Always set the package cache location local to the build Environment.SetEnvironmentVariable("NUGET_PACKAGES", Dirs.NuGetPackages); CleanNuGetTempCache(); // Determine cache expiration time var cacheExpiration = 7 * 24; // cache expiration in hours var cacheExpirationStr = Environment.GetEnvironmentVariable("NUGET_PACKAGES_CACHE_TIME_LIMIT"); if (!string.IsNullOrEmpty(cacheExpirationStr)) { cacheExpiration = int.Parse(cacheExpirationStr); } if (ciBuild) { var cacheTimeFile = Path.Combine(Dirs.NuGetPackages, "packageCacheTime.txt"); DateTime? cacheTime = null; try { // Read the cache file if (File.Exists(cacheTimeFile)) { var content = File.ReadAllText(cacheTimeFile); if (!string.IsNullOrEmpty(content)) { cacheTime = DateTime.ParseExact("O", content, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal); } } } catch (Exception ex) { c.Warn($"Error reading NuGet cache time file, leaving the cache alone"); c.Warn($"Error Detail: {ex.ToString()}"); } if (cacheTime == null || (cacheTime.Value.AddHours(cacheExpiration) < DateTime.UtcNow)) { // Cache has expired or the status is unknown, clear it and write the file c.Info("Clearing NuGet cache"); Rmdir(Dirs.NuGetPackages); Mkdirp(Dirs.NuGetPackages); File.WriteAllText(cacheTimeFile, DateTime.UtcNow.ToString("O")); } } return c.Success(); }