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 } ,
{ "osx_x64" , false } ,
2017-09-14 21:21:54 -07:00
{ "linux_x64" , false } ,
2017-09-28 11:19:49 -07:00
{ "rhel.6_x64" , false } ,
2018-04-19 16:16:12 -07:00
{ "linux_musl_x64" , false } ,
2018-04-11 12:09:16 -07:00
{ "all_linux_distros_native_installer" , false } ,
{ "linux_arm" , false } ,
{ "linux_arm64" , 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 )
{
2018-04-11 12:09:16 -07:00
if ( ( name . StartsWith ( $"{img}_" ) ) & & ( name . EndsWith ( ".svg" ) ) )
2016-10-12 14:25:06 -05:00
{
badges [ img ] = true ;
break ;
}
}
}
HaveAllBuildsPublished = badges . Values . All ( v = > v ) . ToString ( ) ;
return true ;
}
}
}