From f596b8ddce9875719316d8f5a6d636a947b58be5 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Wed, 23 Mar 2016 16:37:59 -0700 Subject: [PATCH 1/2] Refactor PublishTargets.cs, add publishing of all installers and archives to azure, change all versions to nuget versions. --- .../dotnet-sharedhost-debian_config.json | 5 + scripts/dotnet-cli-build/CompileTargets.cs | 5 + scripts/dotnet-cli-build/PublishTargets.cs | 322 ++++++++++-------- .../Publishing/AzurePublisher.cs | 96 ++++++ .../Publishing/DebRepoPublisher.cs | 54 +++ 5 files changed, 339 insertions(+), 143 deletions(-) create mode 100644 scripts/dotnet-cli-build/Publishing/AzurePublisher.cs create mode 100644 scripts/dotnet-cli-build/Publishing/DebRepoPublisher.cs diff --git a/packaging/host/debian/dotnet-sharedhost-debian_config.json b/packaging/host/debian/dotnet-sharedhost-debian_config.json index 9554560b0..d8f30dc2a 100644 --- a/packaging/host/debian/dotnet-sharedhost-debian_config.json +++ b/packaging/host/debian/dotnet-sharedhost-debian_config.json @@ -28,6 +28,11 @@ "full_text": "Copyright (c) 2015 Microsoft\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE." }, + "package_conflicts" : [ + "dotnet", + "dotnet-nightly" + ], + "symlinks": { "dotnet" : "/usr/bin/dotnet" } diff --git a/scripts/dotnet-cli-build/CompileTargets.cs b/scripts/dotnet-cli-build/CompileTargets.cs index b54da094f..993697f46 100644 --- a/scripts/dotnet-cli-build/CompileTargets.cs +++ b/scripts/dotnet-cli-build/CompileTargets.cs @@ -301,6 +301,11 @@ namespace Microsoft.DotNet.Cli.Build } CrossgenSharedFx(c, SharedFrameworkNameAndVersionRoot); + + // Generate .version file for sharedfx + var version = SharedFrameworkNugetVersion; + var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; + File.WriteAllText(Path.Combine(SharedFrameworkNameAndVersionRoot, ".version"), content); } private static BuildTargetResult CompileCliSdk(BuildTargetContext c, DotNetCli dotnet, string outputDir) diff --git a/scripts/dotnet-cli-build/PublishTargets.cs b/scripts/dotnet-cli-build/PublishTargets.cs index 2b9d5a3da..29fa8f6fe 100644 --- a/scripts/dotnet-cli-build/PublishTargets.cs +++ b/scripts/dotnet-cli-build/PublishTargets.cs @@ -12,32 +12,35 @@ namespace Microsoft.DotNet.Cli.Build { public static class PublishTargets { - private static CloudBlobContainer BlobContainer { get; set; } + private static AzurePublisher AzurePublisherTool { get; set; } + + private static DebRepoPublisher DebRepoPublisherTool { get; set; } private static string Channel { get; set; } - private static string Version { get; set; } + private static string CliVersion { get; set; } - private static string NuGetVersion { get; set; } + private static string CliNuGetVersion { get; set; } + private static string SharedFrameworkNugetVersion { 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"); + AzurePublisherTool = new AzurePublisher(); + DebRepoPublisherTool = new DebRepoPublisher(Dirs.Packages); - Version = c.BuildContext.Get("BuildVersion").SimpleVersion; - NuGetVersion = c.BuildContext.Get("BuildVersion").NuGetVersion; + CliVersion = c.BuildContext.Get("BuildCliVersion").SimpleVersion; + CliNuGetVersion = c.BuildContext.Get("BuildCliVersion").NuGetVersion; + SharedFrameworkNugetVersion = c.BuildContext.Get("SharedFrameworkNugetVersion"); Channel = c.BuildContext.Get("Channel"); + return c.Success(); } [Target(nameof(PrepareTargets.Init), nameof(PublishTargets.InitPublish), - nameof(PublishTargets.PublishArtifacts), - nameof(PublishTargets.TriggerDockerHubBuilds))] + nameof(PublishTargets.PublishArtifacts))] [Environment("PUBLISH_TO_AZURE_BLOB", "1", "true")] // This is set by CI systems public static BuildTargetResult Publish(BuildTargetContext c) { @@ -45,53 +48,26 @@ namespace Microsoft.DotNet.Cli.Build } [Target( - nameof(PublishTargets.PublishVersionBadge), - nameof(PublishTargets.PublishCombinedFrameworkSDKHostInstallerFile), + nameof(PublishTargets.PublishInstallerFilesToAzure), + nameof(PublishTargets.PublishArchivesToAzure), nameof(PublishTargets.PublishDebFilesToDebianRepo), - nameof(PublishTargets.PublishCombinedFrameworkSDKHostFile), - nameof(PublishTargets.PublishCombinedFrameworkHostFile), - nameof(PublishTargets.PublishLatestVersionTextFile))] - public static BuildTargetResult PublishArtifacts(BuildTargetContext c) - { - return c.Success(); - } + nameof(PublishTargets.PublishLatestCliVersionTextFile), + nameof(PublishTargets.PublishLatestSharedFrameworkVersionTextFile), + nameof(PublishTargets.PublishCliVersionBadge))] + public static BuildTargetResult PublishArtifacts(BuildTargetContext c) => c.Success(); - [Target] - public static BuildTargetResult PublishVersionBadge(BuildTargetContext c) - { - var versionBadge = c.BuildContext.Get("VersionBadge"); - var latestVersionBadgeBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(versionBadge)}"; - var versionBadgeBlob = $"{Channel}/Binaries/{Version}/{Path.GetFileName(versionBadge)}"; + [Target( + nameof(PublishTargets.PublishSharedHostInstallerFileToAzure), + nameof(PublishTargets.PublishSharedFrameworkInstallerFileToAzure), + nameof(PublishTargets.PublishSdkInstallerFileToAzure), + nameof(PublishTargets.PublishCombinedFrameworkSDKHostInstallerFileToAzure), + nameof(PublishTargets.PublishCombinedFrameworkHostInstallerFileToAzure))] + public static BuildTargetResult PublishInstallerFilesToAzure(BuildTargetContext c) => c.Success(); - PublishFileAzure(versionBadgeBlob, versionBadge); - PublishFileAzure(latestVersionBadgeBlob, versionBadge); - return c.Success(); - } - - [Target] - [BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX)] - public static BuildTargetResult PublishCombinedFrameworkSDKHostInstallerFile(BuildTargetContext c) - { - var installerFile = c.BuildContext.Get("CombinedFrameworkSDKHostInstallerFile"); - 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, "sdk", NuGetVersion, ".version"); - - PublishFileAzure(latestVersionBlob, latestVersionFile); - return c.Success(); - } + [Target( + nameof(PublishTargets.PublishCombinedHostFrameworkArchiveToAzure), + nameof(PublishTargets.PublishCombinedHostFrameworkSdkArchiveToAzure))] + public static BuildTargetResult PublishArchivesToAzure(BuildTargetContext c) => c.Success(); [Target( nameof(PublishSdkDebToDebianRepo), @@ -103,14 +79,144 @@ namespace Microsoft.DotNet.Cli.Build return c.Success(); } + [Target] + public static BuildTargetResult PublishCliVersionBadge(BuildTargetContext c) + { + var CliversionBadge = c.BuildContext.Get("CliVersionBadge"); + var latestCliVersionBadgeBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(CliversionBadge)}"; + var CliversionBadgeBlob = $"{Channel}/Binaries/{CliVersion}/{Path.GetFileName(CliversionBadge)}"; + + AzurePublisherTool.PublishFile(CliversionBadgeBlob, CliversionBadge); + AzurePublisherTool.PublishFile(latestCliVersionBadgeBlob, CliversionBadge); + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult PublishSharedHostInstallerFileToAzure(BuildTargetContext c) + { + var version = CliNuGetVersion; + var installerFile = c.BuildContext.Get("SharedHostInstallerFile"); + + AzurePublisherTool.PublishInstallerFileAndLatest(installerFile, Channel, version); + + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult PublishSharedFrameworkInstallerFileToAzure(BuildTargetContext c) + { + var version = SharedFrameworkNugetVersion; + var installerFile = c.BuildContext.Get("SharedFrameworkInstallerFile"); + + AzurePublisherTool.PublishInstallerFileAndLatest(installerFile, Channel, version); + + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Ubuntu)] + public static BuildTargetResult PublishSdkInstallerFileToAzure(BuildTargetContext c) + { + var version = CliNuGetVersion; + var installerFile = c.BuildContext.Get("SDKInstallerFile"); + + AzurePublisherTool.PublishInstallerFileAndLatest(installerFile, Channel, version); + + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX)] + public static BuildTargetResult PublishCombinedFrameworkHostInstallerFileToAzure(BuildTargetContext c) + { + var version = SharedFrameworkNugetVersion; + var installerFile = c.BuildContext.Get("CombinedFrameworkHostInstallerFile"); + + AzurePublisherTool.PublishInstallerFileAndLatest(installerFile, Channel, version); + + return c.Success(); + } + + [Target] + [BuildPlatforms(BuildPlatform.Windows, BuildPlatform.OSX)] + public static BuildTargetResult PublishCombinedFrameworkSDKHostInstallerFileToAzure(BuildTargetContext c) + { + var version = CliNuGetVersion; + var installerFile = c.BuildContext.Get("CombinedFrameworkSDKHostInstallerFile"); + + AzurePublisherTool.PublishInstallerFileAndLatest(installerFile, Channel, version); + + return c.Success(); + } + + [Target] + public static BuildTargetResult PublishCombinedHostFrameworkSdkArchiveToAzure(BuildTargetContext c) + { + var version = CliNuGetVersion; + var archiveFile = c.BuildContext.Get("CombinedFrameworkSDKHostCompressedFile"); + + AzurePublisherTool.PublishInstallerFileAndLatest(archiveFile, Channel, version); + + return c.Success(); + } + + [Target] + public static BuildTargetResult PublishCombinedHostFrameworkArchiveToAzure(BuildTargetContext c) + { + var version = SharedFrameworkNugetVersion; + var archiveFile = c.BuildContext.Get("CombinedFrameworkHostCompressedFile"); + + AzurePublisherTool.PublishInstallerFileAndLatest(archiveFile, Channel, version); + return c.Success(); + } + + [Target] + public static BuildTargetResult PublishLatestCliVersionTextFile(BuildTargetContext c) + { + var version = CliNuGetVersion; + + var osname = Monikers.GetOSShortName(); + var latestCliVersionBlob = $"{Channel}/dnvm/latest.{osname}.{CurrentArchitecture.Current}.version"; + var latestCliVersionFile = Path.Combine(Dirs.Stage2, "sdk", version, ".version"); + + AzurePublisherTool.PublishFile(latestCliVersionBlob, latestCliVersionFile); + return c.Success(); + } + + [Target] + public static BuildTargetResult PublishLatestSharedFrameworkVersionTextFile(BuildTargetContext c) + { + var version = SharedFrameworkNugetVersion; + + var osname = Monikers.GetOSShortName(); + var latestSharedFXVersionBlob = $"{Channel}/dnvm/latest.sharedfx.{osname}.{CurrentArchitecture.Current}.version"; + var latestSharedFXVersionFile = Path.Combine( + Dirs.Stage2, + "shared", + CompileTargets.SharedFrameworkName, + version, + ".version"); + + AzurePublisherTool.PublishFile(latestSharedFXVersionBlob, latestSharedFXVersionFile); + return c.Success(); + } + [Target] [BuildPlatforms(BuildPlatform.Ubuntu)] public static BuildTargetResult PublishSdkDebToDebianRepo(BuildTargetContext c) { + var version = CliNuGetVersion; + var packageName = Monikers.GetSdkDebianPackageName(c); var installerFile = c.BuildContext.Get("SdkInstallerFile"); + var uploadUrl = AzurePublisherTool.CalculateInstallerUploadUrl(installerFile, Channel, version); - PublishDebFileToDebianRepo(packageName, installerFile); + DebRepoPublisherTool.PublishDebFileToDebianRepo( + packageName, + version, + uploadUrl); return c.Success(); } @@ -119,10 +225,16 @@ namespace Microsoft.DotNet.Cli.Build [BuildPlatforms(BuildPlatform.Ubuntu)] public static BuildTargetResult PublishSharedFrameworkDebToDebianRepo(BuildTargetContext c) { - var packageName = Monikers.GetDebianSharedFrameworkPackageName(c); + var version = SharedFrameworkNugetVersion; + + var packageName = Monikers.GetSdkDebianPackageName(c); var installerFile = c.BuildContext.Get("SharedFrameworkInstallerFile"); - - PublishDebFileToDebianRepo(packageName, installerFile); + var uploadUrl = AzurePublisherTool.CalculateInstallerUploadUrl(installerFile, Channel, version); + + DebRepoPublisherTool.PublishDebFileToDebianRepo( + packageName, + version, + uploadUrl); return c.Success(); } @@ -131,10 +243,16 @@ namespace Microsoft.DotNet.Cli.Build [BuildPlatforms(BuildPlatform.Ubuntu)] public static BuildTargetResult PublishSharedHostDebToDebianRepo(BuildTargetContext c) { - var packageName = Monikers.GetDebianSharedHostPackageName(c); - var installerFile = c.BuildContext.Get("SharedHostInstallerFile"); + var version = CliNuGetVersion; - PublishDebFileToDebianRepo(packageName, installerFile); + var packageName = Monikers.GetSdkDebianPackageName(c); + var installerFile = c.BuildContext.Get("SharedHostInstallerFile"); + var uploadUrl = AzurePublisherTool.CalculateInstallerUploadUrl(installerFile, Channel, version); + + DebRepoPublisherTool.PublishDebFileToDebianRepo( + packageName, + version, + uploadUrl); return c.Success(); } @@ -177,87 +295,5 @@ namespace Microsoft.DotNet.Cli.Build } return c.Success(); } - - private static string GenerateUploadJsonFile(string packageName, string version, string uploadUrl) - { - var repoID = Environment.GetEnvironmentVariable("REPO_ID"); - var uploadJson = Path.Combine(Dirs.Packages, "package_upload.json"); - File.Delete(uploadJson); - - using (var fileStream = File.Create(uploadJson)) - { - using (StreamWriter sw = new StreamWriter(fileStream)) - { - sw.WriteLine("{"); - sw.WriteLine($" \"name\":\"{packageName}\","); - sw.WriteLine($" \"version\":\"{version}\","); - sw.WriteLine($" \"repositoryId\":\"{repoID}\","); - sw.WriteLine($" \"sourceUrl\":\"{uploadUrl}\""); - sw.WriteLine("}"); - } - } - - return uploadJson; - } - - [Target] - public static BuildTargetResult PublishCombinedFrameworkSDKHostFile(BuildTargetContext c) - { - var compressedFile = c.BuildContext.Get("CombinedFrameworkSDKHostCompressedFile"); - 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] - public static BuildTargetResult PublishCombinedFrameworkHostFile(BuildTargetContext c) - { - var compressedFile = c.BuildContext.Get("CombinedFrameworkHostCompressedFile"); - 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(); - } - - 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 PublishDebFileToDebianRepo(string packageName, string installerFile) - { - var uploadUrl = $"https://dotnetcli.blob.core.windows.net/dotnet/{Channel}/Installers/{Version}/{Path.GetFileName(installerFile)}"; - var uploadJson = GenerateUploadJsonFile(packageName, Version, uploadUrl); - - Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "publish", "repoapi_client.sh"), "-addpkg", uploadJson) - .Execute() - .EnsureSuccessful(); - } - - private static void PublishFileAzure(string blob, string file) - { - CloudBlockBlob blockBlob = BlobContainer.GetBlockBlobReference(blob); - blockBlob.UploadFromFileAsync(file, FileMode.Open).Wait(); - - if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".svg") - { - blockBlob.Properties.ContentType = "image/svg+xml"; - blockBlob.Properties.CacheControl = "no-cache"; - blockBlob.SetPropertiesAsync().Wait(); - } - } } } diff --git a/scripts/dotnet-cli-build/Publishing/AzurePublisher.cs b/scripts/dotnet-cli-build/Publishing/AzurePublisher.cs new file mode 100644 index 000000000..0ac9834d1 --- /dev/null +++ b/scripts/dotnet-cli-build/Publishing/AzurePublisher.cs @@ -0,0 +1,96 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Text; +using Microsoft.DotNet.Cli.Build.Framework; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Blob; + +using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; + +namespace Microsoft.DotNet.Cli.Build +{ + public class AzurePublisher + { + private static readonly string s_dotnetBlobRootUrl = "https://dotnetcli.blob.core.windows.net/dotnet/"; + private static readonly string s_dotnetBlobContainerName = "dotnet"; + + private string _connectionString { get; set; } + private CloudBlobContainer _blobContainer { get; set; } + + public AzurePublisher() + { + _connectionString = Environment.GetEnvironmentVariable("CONNECTION_STRING").Trim('"'); + + _blobContainer = GetDotnetBlobContainer(_connectionString); + } + + private CloudBlobContainer GetDotnetBlobContainer(string connectionString) + { + CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); + CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); + + return blobClient.GetContainerReference(s_dotnetBlobContainerName); + } + + public void PublishInstallerFileAndLatest(string installerFile, string channel, string version) + { + var installerFileBlob = CalculateInstallerBlob(installerFile, channel, version); + + var latestInstallerFileName = installerFile.Replace(version, "latest"); + var latestInstallerFileBlob = CalculateInstallerBlob(latestInstallerFileName, channel, "Latest"); + + PublishFile(installerFileBlob, installerFile); + PublishFile(latestInstallerFileBlob, installerFile); + } + + public void PublishArchiveAndLatest(string archiveFile, string channel, string version) + { + var archiveFileBlob = CalculateArchiveBlob(archiveFile, channel, version); + + var latestArchiveFileName = archiveFile.Replace(version, "latest"); + var latestArchiveFileBlob = CalculateArchiveBlob(latestArchiveFileName, channel, "Latest"); + + PublishFile(archiveFileBlob, archiveFile); + PublishFile(latestArchiveFileBlob, archiveFile); + } + + public void PublishFile(string blob, string file) + { + CloudBlockBlob blockBlob = _blobContainer.GetBlockBlobReference(blob); + blockBlob.UploadFromFileAsync(file, FileMode.Open).Wait(); + + SetBlobPropertiesBasedOnFileType(blockBlob); + } + + private void SetBlobPropertiesBasedOnFileType(CloudBlockBlob blockBlob) + { + if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".svg") + { + blockBlob.Properties.ContentType = "image/svg+xml"; + blockBlob.Properties.CacheControl = "no-cache"; + blockBlob.SetPropertiesAsync().Wait(); + } + } + + public string CalculateInstallerUploadUrl(string installerFile, string channel, string version) + { + return $"{s_dotnetBlobRootUrl}{CalculateInstallerBlob(installerFile, channel, version)}"; + } + + public string CalculateInstallerBlob(string installerFile, string channel, string version) + { + return $"{channel}/Installers/{version}/{Path.GetFileName(installerFile)}"; + } + + public string CalculateArchiveUploadUrl(string archiveFile, string channel, string version) + { + return $"{s_dotnetBlobRootUrl}{CalculateArchiveBlob(archiveFile, channel, version)}"; + } + + public string CalculateArchiveBlob(string archiveFile, string channel, string version) + { + return $"{channel}/Binaries/{version}/{Path.GetFileName(archiveFile)}"; + } + } +} diff --git a/scripts/dotnet-cli-build/Publishing/DebRepoPublisher.cs b/scripts/dotnet-cli-build/Publishing/DebRepoPublisher.cs new file mode 100644 index 000000000..722915dd3 --- /dev/null +++ b/scripts/dotnet-cli-build/Publishing/DebRepoPublisher.cs @@ -0,0 +1,54 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Text; +using Microsoft.DotNet.Cli.Build.Framework; +using Microsoft.WindowsAzure.Storage; +using Microsoft.WindowsAzure.Storage.Blob; + +using static Microsoft.DotNet.Cli.Build.Framework.BuildHelpers; + +namespace Microsoft.DotNet.Cli.Build +{ + public class DebRepoPublisher + { + private string _repoID; + private string _uploadJsonDirectory; + + public DebRepoPublisher(string uploadJsonDirectory) + { + _uploadJsonDirectory = uploadJsonDirectory; + _repoID = Environment.GetEnvironmentVariable("REPO_ID"); + } + + public void PublishDebFileToDebianRepo(string packageName, string packageVersion, string uploadUrl) + { + var uploadJson = GenerateUploadJsonFile(packageName, packageVersion, uploadUrl); + + Cmd(Path.Combine(Dirs.RepoRoot, "scripts", "publish", "repoapi_client.sh"), "-addpkg", uploadJson) + .Execute() + .EnsureSuccessful(); + } + + private string GenerateUploadJsonFile(string packageName, string packageVersion, string uploadUrl) + { + var uploadJson = Path.Combine(_uploadJsonDirectory, "package_upload.json"); + File.Delete(uploadJson); + + using (var fileStream = File.Create(uploadJson)) + { + using (StreamWriter sw = new StreamWriter(fileStream)) + { + sw.WriteLine("{"); + sw.WriteLine($" \"name\":\"{packageName}\","); + sw.WriteLine($" \"version\":\"{packageVersion}\","); + sw.WriteLine($" \"repositoryId\":\"{_repoID}\","); + sw.WriteLine($" \"sourceUrl\":\"{uploadUrl}\""); + sw.WriteLine("}"); + } + } + + return uploadJson; + } + } +} From 71b78a9c6829bfa89d338ebf448bfe10d7e35fd1 Mon Sep 17 00:00:00 2001 From: Bryan Thornbury Date: Wed, 23 Mar 2016 17:13:58 -0700 Subject: [PATCH 2/2] integrate @krwq 's moniker/compile version changes unset the hardcoded channel fix version badge version fix a capitalization fix the archives Update filenames of zip files to have the correct versions move version gen --- scripts/dotnet-cli-build/CompileTargets.cs | 2 +- scripts/dotnet-cli-build/PrepareTargets.cs | 23 ++++++++++++++-------- scripts/dotnet-cli-build/PublishTargets.cs | 20 +++++++++---------- scripts/dotnet-cli-build/Utils/Monikers.cs | 3 +-- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/scripts/dotnet-cli-build/CompileTargets.cs b/scripts/dotnet-cli-build/CompileTargets.cs index 993697f46..bd3e32265 100644 --- a/scripts/dotnet-cli-build/CompileTargets.cs +++ b/scripts/dotnet-cli-build/CompileTargets.cs @@ -375,7 +375,7 @@ namespace Microsoft.DotNet.Cli.Build } // Generate .version file - var version = buildVersion.SimpleVersion; + var version = buildVersion.NuGetVersion; var content = $@"{c.BuildContext["CommitHash"]}{Environment.NewLine}{version}{Environment.NewLine}"; File.WriteAllText(Path.Combine(outputDir, ".version"), content); diff --git a/scripts/dotnet-cli-build/PrepareTargets.cs b/scripts/dotnet-cli-build/PrepareTargets.cs index 0600bce7b..eea61e300 100644 --- a/scripts/dotnet-cli-build/PrepareTargets.cs +++ b/scripts/dotnet-cli-build/PrepareTargets.cs @@ -47,7 +47,6 @@ namespace Microsoft.DotNet.Cli.Build c.BuildContext["Configuration"] = configEnv; c.BuildContext["Channel"] = Environment.GetEnvironmentVariable("CHANNEL"); - c.BuildContext["SharedFrameworkNugetVersion"] = GetVersionFromProjectJson(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework", "project.json")); c.Info($"Building {c.BuildContext["Configuration"]} to: {Dirs.Output}"); c.Info("Build Environment:"); @@ -83,6 +82,7 @@ namespace Microsoft.DotNet.Cli.Build }; c.BuildContext["BuildVersion"] = buildVersion; c.BuildContext["CommitHash"] = commitHash; + c.BuildContext["SharedFrameworkNugetVersion"] = GetVersionFromProjectJson(Path.Combine(Dirs.RepoRoot, "src", "sharedframework", "framework", "project.json")); c.Info($"Building Version: {buildVersion.SimpleVersion} (NuGet Packages: {buildVersion.NuGetVersion})"); c.Info($"From Commit: {commitHash}"); @@ -122,11 +122,14 @@ namespace Microsoft.DotNet.Cli.Build var versionBadgeName = $"{CurrentPlatform.Current}_{CurrentArchitecture.Current}_{config}_version_badge.svg"; c.BuildContext["VersionBadge"] = Path.Combine(Dirs.Output, versionBadgeName); - AddInstallerArtifactToContext(c, "dotnet-sdk", "Sdk"); - AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost"); - AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework"); - AddInstallerArtifactToContext(c, "dotnet-dev", "CombinedFrameworkSDKHost"); - AddInstallerArtifactToContext(c, "dotnet", "CombinedFrameworkHost"); + var cliVersion = c.BuildContext.Get("BuildVersion").NuGetVersion; + var sharedFrameworkVersion = c.BuildContext.Get("SharedFrameworkNugetVersion"); + + AddInstallerArtifactToContext(c, "dotnet-sdk", "Sdk", cliVersion); + AddInstallerArtifactToContext(c, "dotnet-host", "SharedHost", cliVersion); + AddInstallerArtifactToContext(c, "dotnet-sharedframework", "SharedFramework", sharedFrameworkVersion); + AddInstallerArtifactToContext(c, "dotnet-dev", "CombinedFrameworkSDKHost", cliVersion); + AddInstallerArtifactToContext(c, "dotnet", "CombinedFrameworkHost", sharedFrameworkVersion); return c.Success(); } @@ -370,9 +373,13 @@ cmake is required to build the native host 'corehost'"; return dict; } - private static void AddInstallerArtifactToContext(BuildTargetContext c, string artifactPrefix, string contextPrefix) + private static void AddInstallerArtifactToContext( + BuildTargetContext c, + string artifactPrefix, + string contextPrefix, + string version) { - var productName = Monikers.GetProductMoniker(c, artifactPrefix); + var productName = Monikers.GetProductMoniker(c, artifactPrefix, version); var extension = CurrentPlatform.IsWindows ? ".zip" : ".tar.gz"; c.BuildContext[contextPrefix + "CompressedFile"] = Path.Combine(Dirs.Packages, productName + extension); diff --git a/scripts/dotnet-cli-build/PublishTargets.cs b/scripts/dotnet-cli-build/PublishTargets.cs index 29fa8f6fe..ad66db3f8 100644 --- a/scripts/dotnet-cli-build/PublishTargets.cs +++ b/scripts/dotnet-cli-build/PublishTargets.cs @@ -30,8 +30,8 @@ namespace Microsoft.DotNet.Cli.Build AzurePublisherTool = new AzurePublisher(); DebRepoPublisherTool = new DebRepoPublisher(Dirs.Packages); - CliVersion = c.BuildContext.Get("BuildCliVersion").SimpleVersion; - CliNuGetVersion = c.BuildContext.Get("BuildCliVersion").NuGetVersion; + CliVersion = c.BuildContext.Get("BuildVersion").SimpleVersion; + CliNuGetVersion = c.BuildContext.Get("BuildVersion").NuGetVersion; SharedFrameworkNugetVersion = c.BuildContext.Get("SharedFrameworkNugetVersion"); Channel = c.BuildContext.Get("Channel"); @@ -82,12 +82,12 @@ namespace Microsoft.DotNet.Cli.Build [Target] public static BuildTargetResult PublishCliVersionBadge(BuildTargetContext c) { - var CliversionBadge = c.BuildContext.Get("CliVersionBadge"); - var latestCliVersionBadgeBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(CliversionBadge)}"; - var CliversionBadgeBlob = $"{Channel}/Binaries/{CliVersion}/{Path.GetFileName(CliversionBadge)}"; + var versionBadge = c.BuildContext.Get("VersionBadge"); + var latestVersionBadgeBlob = $"{Channel}/Binaries/Latest/{Path.GetFileName(versionBadge)}"; + var versionBadgeBlob = $"{Channel}/Binaries/{CliNuGetVersion}/{Path.GetFileName(versionBadge)}"; - AzurePublisherTool.PublishFile(CliversionBadgeBlob, CliversionBadge); - AzurePublisherTool.PublishFile(latestCliVersionBadgeBlob, CliversionBadge); + AzurePublisherTool.PublishFile(versionBadgeBlob, versionBadge); + AzurePublisherTool.PublishFile(latestVersionBadgeBlob, versionBadge); return c.Success(); } @@ -120,7 +120,7 @@ namespace Microsoft.DotNet.Cli.Build public static BuildTargetResult PublishSdkInstallerFileToAzure(BuildTargetContext c) { var version = CliNuGetVersion; - var installerFile = c.BuildContext.Get("SDKInstallerFile"); + var installerFile = c.BuildContext.Get("SdkInstallerFile"); AzurePublisherTool.PublishInstallerFileAndLatest(installerFile, Channel, version); @@ -157,7 +157,7 @@ namespace Microsoft.DotNet.Cli.Build var version = CliNuGetVersion; var archiveFile = c.BuildContext.Get("CombinedFrameworkSDKHostCompressedFile"); - AzurePublisherTool.PublishInstallerFileAndLatest(archiveFile, Channel, version); + AzurePublisherTool.PublishArchiveAndLatest(archiveFile, Channel, version); return c.Success(); } @@ -168,7 +168,7 @@ namespace Microsoft.DotNet.Cli.Build var version = SharedFrameworkNugetVersion; var archiveFile = c.BuildContext.Get("CombinedFrameworkHostCompressedFile"); - AzurePublisherTool.PublishInstallerFileAndLatest(archiveFile, Channel, version); + AzurePublisherTool.PublishArchiveAndLatest(archiveFile, Channel, version); return c.Success(); } diff --git a/scripts/dotnet-cli-build/Utils/Monikers.cs b/scripts/dotnet-cli-build/Utils/Monikers.cs index 231b09a8d..bbe881aef 100644 --- a/scripts/dotnet-cli-build/Utils/Monikers.cs +++ b/scripts/dotnet-cli-build/Utils/Monikers.cs @@ -10,11 +10,10 @@ namespace Microsoft.DotNet.Cli.Build { public const string SharedFrameworkName = "Microsoft.NETCore.App"; - public static string GetProductMoniker(BuildTargetContext c, string artifactPrefix) + public static string GetProductMoniker(BuildTargetContext c, string artifactPrefix, string version) { string osname = GetOSShortName(); var arch = CurrentArchitecture.Current.ToString(); - var version = c.BuildContext.Get("BuildVersion").SimpleVersion; return $"{artifactPrefix}-{osname}-{arch}.{version}"; }