2016-10-12 14:25:06 -05:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Build.Framework ;
using Microsoft.Build.Utilities ;
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
namespace Microsoft.DotNet.Cli.Build
{
public class CheckIfAllBuildsHavePublished : Task
{
private AzurePublisher _azurePublisher ;
[Required]
public string AccountName { get ; set ; }
[Required]
public string AccountKey { get ; set ; }
[Required]
public string ContainerName { get ; set ; }
[Required]
public string NugetVersion { get ; set ; }
2017-03-01 15:12:16 -06:00
[Required]
public string VersionBadgeMoniker { get ; set ; }
2016-10-12 14:25:06 -05:00
[Output]
public string HaveAllBuildsPublished { get ; set ; }
private AzurePublisher AzurePublisherTool
{
get
{
if ( _azurePublisher = = null )
{
_azurePublisher = new AzurePublisher ( AccountName , AccountKey , ContainerName ) ;
}
return _azurePublisher ;
}
}
public override bool Execute ( )
{
var badges = new Dictionary < string , bool > ( )
{
2017-03-01 11:46:53 -08:00
{ "win_x86" , false } ,
{ "win_x64" , false } ,
{ "ubuntu_x64" , false } ,
{ "ubuntu_16_04_x64" , false } ,
2017-03-08 20:03:46 -08:00
{ "ubuntu_16_10_x64" , false } ,
2017-03-01 11:46:53 -08:00
{ "rhel_x64" , false } ,
{ "osx_x64" , false } ,
{ "debian_x64" , false } ,
{ "centos_x64" , false } ,
2017-03-09 07:08:49 -10:00
{ "linux_x64" , false } ,
2017-03-08 20:03:46 -08:00
{ "fedora_24_x64" , false } ,
{ "opensuse_42_1_x64" , false }
2016-10-12 14:25:06 -05:00
} ;
2017-03-01 15:12:16 -06:00
if ( ! badges . ContainsKey ( VersionBadgeMoniker ) )
2016-10-12 14:25:06 -05:00
{
2017-03-01 15:12:16 -06:00
throw new ArgumentException ( $"A new OS build '{VersionBadgeMoniker}' was added without adding the moniker to the {nameof(badges)} lookup" ) ;
2016-10-12 14:25:06 -05:00
}
IEnumerable < string > blobs = AzurePublisherTool . ListBlobs ( AzurePublisher . Product . Sdk , NugetVersion ) ;
foreach ( string file in blobs )
{
string name = Path . GetFileName ( file ) ;
foreach ( string img in badges . Keys )
{
if ( ( name . StartsWith ( $"{img}" ) ) & & ( name . EndsWith ( ".svg" ) ) )
{
badges [ img ] = true ;
break ;
}
}
}
HaveAllBuildsPublished = badges . Values . All ( v = > v ) . ToString ( ) ;
return true ;
}
}
}