Port https://github.com/dotnet/core-setup/pull/168 to CLI.
This commit is contained in:
parent
4f1d9c4e23
commit
80332c8fc3
2 changed files with 36 additions and 7 deletions
|
@ -15,6 +15,8 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
|
|
||||||
private static string Channel { get; set; }
|
private static string Channel { get; set; }
|
||||||
|
|
||||||
|
private static string CommitHash { get; set; }
|
||||||
|
|
||||||
private static string CliNuGetVersion { get; set; }
|
private static string CliNuGetVersion { get; set; }
|
||||||
|
|
||||||
private static string SharedFrameworkNugetVersion { get; set; }
|
private static string SharedFrameworkNugetVersion { get; set; }
|
||||||
|
@ -28,6 +30,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
CliNuGetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
CliNuGetVersion = c.BuildContext.Get<BuildVersion>("BuildVersion").NuGetVersion;
|
||||||
SharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion;
|
SharedFrameworkNugetVersion = CliDependencyVersions.SharedFrameworkVersion;
|
||||||
Channel = c.BuildContext.Get<string>("Channel");
|
Channel = c.BuildContext.Get<string>("Channel");
|
||||||
|
CommitHash = c.BuildContext.Get<string>("CommitHash");
|
||||||
|
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
@ -49,7 +52,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
if (CheckIfAllBuildsHavePublished())
|
if (CheckIfAllBuildsHavePublished())
|
||||||
{
|
{
|
||||||
string targetContainer = $"{AzurePublisher.Product.Sdk}/{Channel}/";
|
string targetContainer = $"{AzurePublisher.Product.Sdk}/{Channel}/";
|
||||||
string targetVersionFile = $"{targetContainer}{CliNuGetVersion}";
|
string targetVersionFile = $"{targetContainer}{CommitHash}";
|
||||||
string semaphoreBlob = $"{targetContainer}/publishSemaphore";
|
string semaphoreBlob = $"{targetContainer}/publishSemaphore";
|
||||||
AzurePublisherTool.CreateBlobIfNotExists(semaphoreBlob);
|
AzurePublisherTool.CreateBlobIfNotExists(semaphoreBlob);
|
||||||
string leaseId = AzurePublisherTool.AcquireLeaseOnBlob(semaphoreBlob);
|
string leaseId = AzurePublisherTool.AcquireLeaseOnBlob(semaphoreBlob);
|
||||||
|
@ -64,7 +67,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Regex versionFileRegex = new Regex(@"(?<version>\d\.\d\.\d)-(?<release>.*)?");
|
Regex versionFileRegex = new Regex(@"(?<CommitHash>[\w\d]{40})");
|
||||||
|
|
||||||
// Delete old version files
|
// Delete old version files
|
||||||
AzurePublisherTool.ListBlobs(targetContainer)
|
AzurePublisherTool.ListBlobs(targetContainer)
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.WindowsAzure.Storage;
|
using Microsoft.WindowsAzure.Storage;
|
||||||
using Microsoft.WindowsAzure.Storage.Blob;
|
using Microsoft.WindowsAzure.Storage.Blob;
|
||||||
|
@ -102,12 +104,36 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
return blobFiles.Results.Select(bf => bf.Uri.PathAndQuery.Replace($"/{s_dotnetBlobContainerName}/", string.Empty));
|
return blobFiles.Results.Select(bf => bf.Uri.PathAndQuery.Replace($"/{s_dotnetBlobContainerName}/", string.Empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string AcquireLeaseOnBlob(string blob)
|
public string AcquireLeaseOnBlob(
|
||||||
|
string blob,
|
||||||
|
TimeSpan? maxWaitDefault = null,
|
||||||
|
TimeSpan? delayDefault = null)
|
||||||
{
|
{
|
||||||
CloudBlockBlob cloudBlob = _blobContainer.GetBlockBlobReference(blob);
|
TimeSpan maxWait = maxWaitDefault ?? TimeSpan.FromSeconds(120);
|
||||||
Task<string> task = cloudBlob.AcquireLeaseAsync(TimeSpan.FromMinutes(1), null);
|
TimeSpan delay = delayDefault ?? TimeSpan.FromMilliseconds(500);
|
||||||
task.Wait();
|
|
||||||
return task.Result;
|
Stopwatch stopWatch = new Stopwatch();
|
||||||
|
stopWatch.Start();
|
||||||
|
|
||||||
|
// This will throw an exception with HTTP code 409 when we cannot acquire the lease
|
||||||
|
// But we should block until we can get this lease, with a timeout (maxWaitSeconds)
|
||||||
|
while (stopWatch.ElapsedMilliseconds < maxWait.TotalMilliseconds)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CloudBlockBlob cloudBlob = _blobContainer.GetBlockBlobReference(blob);
|
||||||
|
Task<string> task = cloudBlob.AcquireLeaseAsync(TimeSpan.FromMinutes(1), null);
|
||||||
|
task.Wait();
|
||||||
|
return task.Result;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Retrying lease acquisition on {blob}, {e.Message}");
|
||||||
|
Thread.Sleep(delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception($"Unable to acquire lease on {blob}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReleaseLeaseOnBlob(string blob, string leaseId)
|
public void ReleaseLeaseOnBlob(string blob, string leaseId)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue