Adding a task to set the blob properties correctly based on type.
This commit is contained in:
parent
6d7f110122
commit
03a17a9b76
4 changed files with 75 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
<UsingTask TaskName="UploadToAzure" AssemblyFile="$(BuildToolsTaskDir)/Microsoft.DotNet.Build.CloudTestTasks.dll"/>
|
<UsingTask TaskName="UploadToAzure" AssemblyFile="$(BuildToolsTaskDir)/Microsoft.DotNet.Build.CloudTestTasks.dll"/>
|
||||||
<UsingTask TaskName="FinalizeBuildTask" AssemblyFile="$(CLIBuildDll)" />
|
<UsingTask TaskName="FinalizeBuildTask" AssemblyFile="$(CLIBuildDll)" />
|
||||||
|
<UsingTask TaskName="SetBlobPropertiesBasedOnFileTypeTask" AssemblyFile="$(CLIBuildDll)" />
|
||||||
|
|
||||||
<!-- PUBLISH_TO_AZURE_BLOB env variable set by CI -->
|
<!-- PUBLISH_TO_AZURE_BLOB env variable set by CI -->
|
||||||
<Target Name="Publish"
|
<Target Name="Publish"
|
||||||
|
@ -97,5 +98,10 @@
|
||||||
AccountName="$(CloudDropAccountName)"
|
AccountName="$(CloudDropAccountName)"
|
||||||
ContainerName="$(ContainerName)"
|
ContainerName="$(ContainerName)"
|
||||||
Items="@(CliVersionBadgeToUpload)" />
|
Items="@(CliVersionBadgeToUpload)" />
|
||||||
|
|
||||||
|
<SetBlobPropertiesBasedOnFileTypeTask
|
||||||
|
AccountKey="$(CloudDropAccessToken)"
|
||||||
|
AccountName="$(CloudDropAccountName)"
|
||||||
|
Items="@(CliVersionBadgeToUpload)" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
|
@ -30,7 +30,8 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[Required]
|
[Required]
|
||||||
public string BranchName { get; set; }
|
public string BranchName { get; set; }
|
||||||
|
|
||||||
private AzurePublisher AzurePublisherTool {
|
private AzurePublisher AzurePublisherTool
|
||||||
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if(_azurePublisher == null)
|
if(_azurePublisher == null)
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Microsoft.Build.Framework;
|
||||||
|
using Microsoft.Build.Utilities;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
|
{
|
||||||
|
public class SetBlobPropertiesBasedOnFileTypeTask : Task
|
||||||
|
{
|
||||||
|
private AzurePublisher _azurePublisher;
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string AccountName { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string AccountKey { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public ITaskItem[] Items { get; set; }
|
||||||
|
|
||||||
|
private AzurePublisher AzurePublisherTool
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(_azurePublisher == null)
|
||||||
|
{
|
||||||
|
_azurePublisher = new AzurePublisher(AccountName, AccountKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _azurePublisher;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Execute()
|
||||||
|
{
|
||||||
|
if (Items.Length == 0)
|
||||||
|
{
|
||||||
|
Log.LogError("No items were provided for upload.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach(var item in Items)
|
||||||
|
{
|
||||||
|
string relativeBlobPath = item.GetMetadata("RelativeBlobPath");
|
||||||
|
if (string.IsNullOrEmpty(relativeBlobPath))
|
||||||
|
{
|
||||||
|
throw new Exception(string.Format(
|
||||||
|
"Metadata 'RelativeBlobPath' is missing for item '{0}'.",
|
||||||
|
item.ItemSpec));
|
||||||
|
}
|
||||||
|
|
||||||
|
AzurePublisherTool.SetBlobPropertiesBasedOnFileType(relativeBlobPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -92,6 +92,12 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
target.StartCopyAsync(source).Wait();
|
target.StartCopyAsync(source).Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetBlobPropertiesBasedOnFileType(string path)
|
||||||
|
{
|
||||||
|
CloudBlockBlob blob = _blobContainer.GetBlockBlobReference(path);
|
||||||
|
SetBlobPropertiesBasedOnFileType(blob);
|
||||||
|
}
|
||||||
|
|
||||||
private void SetBlobPropertiesBasedOnFileType(CloudBlockBlob blockBlob)
|
private void SetBlobPropertiesBasedOnFileType(CloudBlockBlob blockBlob)
|
||||||
{
|
{
|
||||||
if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".svg")
|
if (Path.GetExtension(blockBlob.Uri.AbsolutePath.ToLower()) == ".svg")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue