Refactor the build scripts
- Bifurcate Package and Publish targets to enable signing. - Move publish from bash/ps into c#. - Create multiple targets to create MSIs and Bundles.
This commit is contained in:
parent
781678de92
commit
d4a3190bfc
25 changed files with 754 additions and 577 deletions
51
scripts/dotnet-cli-build/InstallerTargets.cs
Normal file
51
scripts/dotnet-cli-build/InstallerTargets.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class InstallerTargets
|
||||
{
|
||||
[Target(nameof(MsiTargets.GenerateMsis),
|
||||
nameof(MsiTargets.GenerateBundle),
|
||||
nameof(InstallerTargets.GeneratePkg),
|
||||
nameof(InstallerTargets.GenerateDeb))]
|
||||
public static BuildTargetResult GenerateInstaller(BuildTargetContext c)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.OSX)]
|
||||
public static BuildTargetResult GeneratePkg(BuildTargetContext c)
|
||||
{
|
||||
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||
var pkg = c.BuildContext.Get<string>("InstallerFile");
|
||||
Cmd(Path.Combine(Dirs.RepoRoot, "packaging", "osx", "package-osx.sh"),
|
||||
"-v", version, "-i", Dirs.Stage2, "-o", pkg)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Ubuntu)]
|
||||
public static BuildTargetResult GenerateDeb(BuildTargetContext c)
|
||||
{
|
||||
var env = PackageTargets.GetCommonEnvVars(c);
|
||||
Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "package", "package-debian.sh"))
|
||||
.Environment(env)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
}
|
||||
}
|
139
scripts/dotnet-cli-build/MsiTargets.cs
Normal file
139
scripts/dotnet-cli-build/MsiTargets.cs
Normal file
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class MsiTargets
|
||||
{
|
||||
private const string ENGINE = "engine.exe";
|
||||
|
||||
private static string WixRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(Dirs.Output, "WixTools");
|
||||
}
|
||||
}
|
||||
|
||||
private static string Msi { get; set; }
|
||||
|
||||
private static string Bundle { get; set; }
|
||||
|
||||
private static string Engine { get; set; }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult InitMsi(BuildTargetContext c)
|
||||
{
|
||||
Bundle = c.BuildContext.Get<string>("InstallerFile");
|
||||
Msi = Path.ChangeExtension(Bundle, "msi");
|
||||
Engine = Path.Combine(Path.GetDirectoryName(Bundle), ENGINE);
|
||||
AcquireWix(c);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(MsiTargets.InitMsi),
|
||||
nameof(GenerateDotnetMuxerMsi),
|
||||
nameof(GenerateDotnetSharedFxMsi),
|
||||
nameof(GenerateCLISDKMsi))]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult GenerateMsis(BuildTargetContext c)
|
||||
{
|
||||
var env = PackageTargets.GetCommonEnvVars(c);
|
||||
Cmd("powershell", "-NoProfile", "-NoLogo",
|
||||
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "generatemsi.ps1"), Dirs.Stage2, Msi, WixRoot)
|
||||
.Environment(env)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult GenerateCLISDKMsi(BuildTargetContext c)
|
||||
{
|
||||
var env = PackageTargets.GetCommonEnvVars(c);
|
||||
Cmd("powershell", "-NoProfile", "-NoLogo",
|
||||
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "generatemsi.ps1"), Dirs.Stage2, Msi, WixRoot)
|
||||
.Environment(env)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult GenerateDotnetMuxerMsi(BuildTargetContext c)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult GenerateDotnetSharedFxMsi(BuildTargetContext c)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
|
||||
[Target(nameof(MsiTargets.InitMsi))]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult GenerateBundle(BuildTargetContext c)
|
||||
{
|
||||
var env = PackageTargets.GetCommonEnvVars(c);
|
||||
Cmd("powershell", "-NoProfile", "-NoLogo",
|
||||
Path.Combine(Dirs.RepoRoot, "packaging", "windows", "generatebundle.ps1"), Msi, Bundle, WixRoot)
|
||||
.Environment(env)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(MsiTargets.InitMsi))]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult ExtractEngineFromBundle(BuildTargetContext c)
|
||||
{
|
||||
Cmd($"{WixRoot}\\insignia.exe", "-ib", Bundle, "-o", Engine)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(MsiTargets.InitMsi))]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult ReattachEngineToBundle(BuildTargetContext c)
|
||||
{
|
||||
Cmd($"{WixRoot}\\insignia.exe", "-ab", Engine, Bundle, "-o", Bundle)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
}
|
||||
}
|
138
scripts/dotnet-cli-build/PackageTargets.cs
Normal file
138
scripts/dotnet-cli-build/PackageTargets.cs
Normal file
|
@ -0,0 +1,138 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public static class PackageTargets
|
||||
{
|
||||
[Target]
|
||||
public static BuildTargetResult InitPackage(BuildTargetContext c)
|
||||
{
|
||||
Directory.CreateDirectory(Dirs.Packages);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(PrepareTargets.Init),
|
||||
nameof(PackageTargets.InitPackage),
|
||||
nameof(PackageTargets.GenerateVersionBadge),
|
||||
nameof(PackageTargets.GenerateCompressedFile),
|
||||
nameof(InstallerTargets.GenerateInstaller),
|
||||
nameof(PackageTargets.GenerateNugetPackages))]
|
||||
[Environment("DOTNET_BUILD_SKIP_PACKAGING", null)]
|
||||
public static BuildTargetResult Package(BuildTargetContext c)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult GenerateVersionBadge(BuildTargetContext c)
|
||||
{
|
||||
var buildVersion = c.BuildContext.Get<BuildVersion>("BuildVersion");
|
||||
var versionSvg = Path.Combine(Dirs.RepoRoot, "resources", "images", "version_badge.svg");
|
||||
var outputVersionSvg = c.BuildContext.Get<string>("VersionBadge");
|
||||
|
||||
var versionSvgContent = File.ReadAllText(versionSvg);
|
||||
versionSvgContent = versionSvgContent.Replace("ver_number", buildVersion.SimpleVersion);
|
||||
File.WriteAllText(outputVersionSvg, versionSvgContent);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(PackageTargets.GenerateZip), nameof(PackageTargets.GenerateTarBall))]
|
||||
public static BuildTargetResult GenerateCompressedFile(BuildTargetContext c)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(PackageTargets.InitPackage))]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult GenerateZip(BuildTargetContext c)
|
||||
{
|
||||
var zipFile = c.BuildContext.Get<string>("CompressedFile");
|
||||
|
||||
if (File.Exists(zipFile))
|
||||
{
|
||||
File.Delete(zipFile);
|
||||
}
|
||||
|
||||
ZipFile.CreateFromDirectory(Dirs.Stage2, zipFile, CompressionLevel.Optimal, false);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(PackageTargets.InitPackage))]
|
||||
[BuildPlatforms(BuildPlatform.Unix)]
|
||||
public static BuildTargetResult GenerateTarBall(BuildTargetContext c)
|
||||
{
|
||||
var tarFile = c.BuildContext.Get<string>("CompressedFile");
|
||||
|
||||
if (File.Exists(tarFile))
|
||||
{
|
||||
File.Delete(tarFile);
|
||||
}
|
||||
|
||||
Cmd("tar", "-czf", tarFile, "-C", Dirs.Stage2, ".")
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Windows)]
|
||||
public static BuildTargetResult GenerateNugetPackages(BuildTargetContext c)
|
||||
{
|
||||
var versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").VersionSuffix;
|
||||
var env = GetCommonEnvVars(c);
|
||||
Cmd("powershell", "-NoProfile", "-NoLogo",
|
||||
Path.Combine(Dirs.RepoRoot, "packaging", "nuget", "package.ps1"), Path.Combine(Dirs.Stage2, "bin"), versionSuffix)
|
||||
.Environment(env)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
internal static Dictionary<string, string> GetCommonEnvVars(BuildTargetContext c)
|
||||
{
|
||||
// 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 configuration = c.BuildContext.Get<string>("Configuration");
|
||||
var architecture = PlatformServices.Default.Runtime.RuntimeArchitecture;
|
||||
var env = new Dictionary<string, string>()
|
||||
{
|
||||
{ "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() },
|
||||
{ "OSNAME", PlatformServices.Default.Runtime.OperatingSystem },
|
||||
{ "TFM", "dnxcore50" },
|
||||
{ "REPOROOT", Dirs.RepoRoot },
|
||||
{ "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) }, // 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 },
|
||||
{ "CONFIGURATION", configuration },
|
||||
{ "ARCHITECTURE", architecture }
|
||||
};
|
||||
|
||||
return env;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
public static BuildTargetResult CheckInstallerBuildPlatformDependencies(BuildTargetContext c) => c.Success();
|
||||
|
||||
// All major targets will depend on this in order to ensure variables are set up right if they are run independently
|
||||
[Target(nameof(GenerateVersions), nameof(CheckPrereqs), nameof(LocateStage0))]
|
||||
[Target(nameof(GenerateVersions), nameof(CheckPrereqs), nameof(LocateStage0), nameof(ExpectedBuildArtifacts))]
|
||||
public static BuildTargetResult Init(BuildTargetContext c)
|
||||
{
|
||||
var runtimeInfo = PlatformServices.Default.Runtime;
|
||||
|
@ -104,6 +104,41 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult ExpectedBuildArtifacts(BuildTargetContext c)
|
||||
{
|
||||
var productName = Monikers.GetProductMoniker(c);
|
||||
var config = Environment.GetEnvironmentVariable("CONFIGURATION");
|
||||
var versionBadgeName = $"{CurrentPlatform.Current}_{CurrentArchitecture.Current}_{config}_version_badge.svg";
|
||||
c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName);
|
||||
|
||||
var extension = CurrentPlatform.IsWindows ? ".zip" : ".tar.gz";
|
||||
c.BuildContext["CompressedFile"] = Path.Combine(Dirs.Packages, productName + extension);
|
||||
|
||||
string installer = "";
|
||||
switch(CurrentPlatform.Current)
|
||||
{
|
||||
case BuildPlatform.Windows:
|
||||
installer = productName + ".exe";
|
||||
break;
|
||||
case BuildPlatform.OSX:
|
||||
installer = productName + ".pkg";
|
||||
break;
|
||||
case BuildPlatform.Ubuntu:
|
||||
installer = productName + ".deb";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if(!string.IsNullOrEmpty(installer))
|
||||
{
|
||||
c.BuildContext["InstallerFile"] = Path.Combine(Dirs.Packages, installer);
|
||||
}
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult CheckPackageCache(BuildTargetContext c)
|
||||
{
|
||||
|
|
|
@ -4,6 +4,10 @@ using System.IO;
|
|||
using System.Runtime.InteropServices;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Microsoft.WindowsAzure;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.WindowsAzure.Storage.Auth;
|
||||
using Microsoft.WindowsAzure.Storage.Blob;
|
||||
|
||||
using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers;
|
||||
|
||||
|
@ -11,71 +15,110 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
{
|
||||
public static class PublishTargets
|
||||
{
|
||||
[Target(nameof(PrepareTargets.Init))]
|
||||
private static CloudBlobContainer BlobContainer { get; set; }
|
||||
|
||||
private static string Channel { get; } = "Test";// Environment.GetEnvironmentVariable("RELEASE_SUFFIX");
|
||||
|
||||
private static string Version { get; set; }
|
||||
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult InitPublish(BuildTargetContext c)
|
||||
{
|
||||
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("CONNECTION_STRING").Trim('"'));
|
||||
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
|
||||
BlobContainer = blobClient.GetContainerReference("dotnet");
|
||||
|
||||
Version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target(nameof(PrepareTargets.Init),
|
||||
nameof(PublishTargets.InitPublish),
|
||||
nameof(PublishTargets.PublishArtifacts))]
|
||||
[Environment("PUBLISH_TO_AZURE_BLOB", "true")] // This is set by CI systems
|
||||
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 configuration = c.BuildContext.Get<string>("Configuration");
|
||||
var architecture = PlatformServices.Default.Runtime.RuntimeArchitecture;
|
||||
var env = new Dictionary<string, string>()
|
||||
{
|
||||
{ "RID", PlatformServices.Default.Runtime.GetRuntimeIdentifier() },
|
||||
{ "OSNAME", PlatformServices.Default.Runtime.OperatingSystem },
|
||||
{ "TFM", "netstandardapp1.5" },
|
||||
{ "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 },
|
||||
{ "CONFIGURATION", configuration },
|
||||
{ "ARCHITECTURE", architecture }
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
[Target(nameof(PublishTargets.PublishVersionBadge),
|
||||
nameof(PublishTargets.PublishCompressedFile),
|
||||
nameof(PublishTargets.PublishInstallerFile),
|
||||
nameof(PublishTargets.PublishLatestVersionTextFile))]
|
||||
public static BuildTargetResult PublishArtifacts(BuildTargetContext c)
|
||||
{
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult PublishVersionBadge(BuildTargetContext c)
|
||||
{
|
||||
var versionBadge = c.BuildContext.Get<string>("VersionBadge");
|
||||
var latestVersionBadgeBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(versionBadge)}";
|
||||
var versionBadgeBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(versionBadge)}";
|
||||
|
||||
PublishFileAzure(versionBadgeBlob, versionBadge);
|
||||
PublishFileAzure(latestVersionBadgeBlob, versionBadge);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult PublishCompressedFile(BuildTargetContext c)
|
||||
{
|
||||
var compressedFile = c.BuildContext.Get<string>("CompressedFile");
|
||||
var compressedFileBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(compressedFile)}";
|
||||
var latestCompressedFile = compressedFile.Replace(Version, "latest");
|
||||
var latestCompressedFileBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(latestCompressedFile)}";
|
||||
|
||||
PublishFileAzure(compressedFileBlob, compressedFile);
|
||||
PublishFileAzure(latestCompressedFileBlob, compressedFile);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
[BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX, BuildPlatform.Ubuntu)]
|
||||
public static BuildTargetResult PublishInstallerFile(BuildTargetContext c)
|
||||
{
|
||||
var installerFile = c.BuildContext.Get<string>("InstallerFile");
|
||||
var installerFileBlob = $"{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}";
|
||||
var latestInstallerFile = installerFile.Replace(Version, "latest");
|
||||
var latestInstallerFileBlob = $"{Channel}/Installers/Latest/{Path.GetFileName(latestInstallerFile)}";
|
||||
|
||||
PublishFileAzure(installerFileBlob, installerFile);
|
||||
PublishFileAzure(latestInstallerFileBlob, installerFile);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult PublishLatestVersionTextFile(BuildTargetContext c)
|
||||
{
|
||||
var osname = Monikers.GetOSShortName();
|
||||
var latestVersionBlob = $"{Channel}/dnvm/latest.{osname}.{CurrentArchitecture.Current}.version";
|
||||
var latestVersionFile = Path.Combine(Dirs.Stage2, ".version");
|
||||
|
||||
PublishFileAzure(latestVersionBlob, latestVersionFile);
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
private static BuildTargetResult PublishFile(BuildTargetContext c, string file)
|
||||
{
|
||||
var env = PackageTargets.GetCommonEnvVars(c);
|
||||
Cmd("powershell", "-NoProfile", "-NoLogo",
|
||||
Path.Combine(Dirs.RepoRoot, "scripts", "publish", "publish.ps1"), file)
|
||||
.Environment(env)
|
||||
.Execute()
|
||||
.EnsureSuccessful();
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
private static void PublishFileAzure(string blob, string file)
|
||||
{
|
||||
CloudBlockBlob blockBlob = BlobContainer.GetBlockBlobReference(blob);
|
||||
using (var fileStream = File.OpenRead(file))
|
||||
{
|
||||
blockBlob.UploadFromStreamAsync(fileStream).Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
{
|
||||
public static class Dirs
|
||||
{
|
||||
public static readonly string RepoRoot = Directory.GetCurrentDirectory();
|
||||
public static readonly string Output = Path.Combine(
|
||||
Directory.GetCurrentDirectory(),
|
||||
RepoRoot,
|
||||
"artifacts",
|
||||
PlatformServices.Default.Runtime.GetRuntimeIdentifier());
|
||||
public static readonly string Packages = Path.Combine(Output, "packages");
|
||||
|
|
35
scripts/dotnet-cli-build/Utils/Monikers.cs
Normal file
35
scripts/dotnet-cli-build/Utils/Monikers.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Build
|
||||
{
|
||||
public class Monikers
|
||||
{
|
||||
public static string GetProductMoniker(BuildTargetContext c)
|
||||
{
|
||||
string osname = GetOSShortName();
|
||||
var arch = CurrentArchitecture.Current.ToString();
|
||||
var version = c.BuildContext.Get<BuildVersion>("BuildVersion").SimpleVersion;
|
||||
return $"dotnet-{osname}-{arch}.{version}";
|
||||
}
|
||||
|
||||
public static string GetOSShortName()
|
||||
{
|
||||
string osname = "";
|
||||
switch (CurrentPlatform.Current)
|
||||
{
|
||||
case BuildPlatform.Windows:
|
||||
osname = "win";
|
||||
break;
|
||||
default:
|
||||
osname = CurrentPlatform.Current.ToString().ToLower();
|
||||
break;
|
||||
}
|
||||
|
||||
return osname;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,12 +9,13 @@
|
|||
"NETStandard.Library": "1.0.0-rc2-23901",
|
||||
"System.IO.Compression.ZipFile": "4.0.1-rc2-23901",
|
||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537",
|
||||
"Microsoft.DotNet.Cli.Build.Framework": "1.0.0-*"
|
||||
"Microsoft.DotNet.Cli.Build.Framework": "1.0.0-*",
|
||||
"WindowsAzure.Storage" : "6.2.2-preview"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandardapp1.5": {
|
||||
"imports": "dnxcore50"
|
||||
"imports": ["dnxcore50", "portable-net45+win8"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue