Refactor PublishTargets.cs, add publishing of all installers and archives to azure, change all versions to nuget versions.
This commit is contained in:
parent
7486b45eeb
commit
f596b8ddce
5 changed files with 339 additions and 143 deletions
|
@ -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>("BuildVersion").SimpleVersion;
|
||||
NuGetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
||||
CliVersion = c.BuildContext.Get<BuildVersion>("BuildCliVersion").SimpleVersion;
|
||||
CliNuGetVersion = c.BuildContext.Get<BuildVersion>("BuildCliVersion").NuGetVersion;
|
||||
SharedFrameworkNugetVersion = c.BuildContext.Get<string>("SharedFrameworkNugetVersion");
|
||||
Channel = c.BuildContext.Get<string>("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<string>("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<string>("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<string>("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<string>("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<string>("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<string>("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<string>("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<string>("CombinedFrameworkSDKHostInstallerFile");
|
||||
|
||||
AzurePublisherTool.PublishInstallerFileAndLatest(installerFile, Channel, version);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult PublishCombinedHostFrameworkSdkArchiveToAzure(BuildTargetContext c)
|
||||
{
|
||||
var version = CliNuGetVersion;
|
||||
var archiveFile = c.BuildContext.Get<string>("CombinedFrameworkSDKHostCompressedFile");
|
||||
|
||||
AzurePublisherTool.PublishInstallerFileAndLatest(archiveFile, Channel, version);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
[Target]
|
||||
public static BuildTargetResult PublishCombinedHostFrameworkArchiveToAzure(BuildTargetContext c)
|
||||
{
|
||||
var version = SharedFrameworkNugetVersion;
|
||||
var archiveFile = c.BuildContext.Get<string>("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<string>("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<string>("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<string>("SharedHostInstallerFile");
|
||||
var version = CliNuGetVersion;
|
||||
|
||||
PublishDebFileToDebianRepo(packageName, installerFile);
|
||||
var packageName = Monikers.GetSdkDebianPackageName(c);
|
||||
var installerFile = c.BuildContext.Get<string>("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<string>("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<string>("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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue