Skip to content

Commit

Permalink
using publish task to publish nugets. (Azure#3498)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahabhijeet authored Jul 19, 2017
1 parent 3cd3bc6 commit d6ad1e2
Show file tree
Hide file tree
Showing 12 changed files with 840 additions and 43 deletions.
8 changes: 4 additions & 4 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<Import Project="Directory.Build.props" />
<Import Project="test.props" />
<Import Project="AzSdk.props" />
<Import Project="Directory.Build.targets" />
<Import Project="Directory.Build.targets" />

<Target Name="Clean" DependsOnTargets="$(CleanTraversedProjectsDependsOn)" />
<Target Name="Restore" DependsOnTargets="$(RestoreTraversedProjectsDependsOn)" />
<Target Name="Build" DependsOnTargets="$(BuildTraversedProjectsDependsOn)" />
<Target Name="Rebuild" DependsOnTargets="Clean;Build" />
<Target Name="PublishNuget" DependsOnTargets="$(PublishNugetDependsOn)" />
<Target Name="CreateNugetPackage" DependsOnTargets="$(PackageNugetDependsOn)" />
<Target Name="CreateNugetPackage" DependsOnTargets="$(PackageNugetDependsOn)" />
<Target Name="RunTests" DependsOnTargets="$(RunTestProjectsDependsOn)" />
<Target Name="SignNuget" DependsOnTargets="$(SignNugetDependsOn)" />
<Target Name="Help" DependsOnTargets="$(HelpDependsOn)" />
<Target Name="SignNuget" DependsOnTargets="$(SignNugetDependsOn)" />
<Target Name="Help" DependsOnTargets="$(HelpDependsOn)" />
</Project>
1 change: 0 additions & 1 deletion src/SDKs/Billing/Billing.Tests/Billing.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.ResourceManager" Version="1.1.0-preview" />
<ProjectReference Include="..\Management.Billing\Microsoft.Azure.Management.Billing.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<TargetFramework>net46</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageOutputPath>$(OutputPath)</PackageOutputPath>
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
using Microsoft.WindowsAzure.Build.Tasks;
using Microsoft.WindowsAzure.Build.Tasks.ExecProcess;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Build.Tasks.Tests.PublishNugetTests
{

public class PublishTests
{
const string NUGET_PKG_NAME = "Build.Tasks.Tests";

string _nugetPkgBuiltDir;
string _publishToDir;

public string NugetPkgBuiltDir
{
get
{
if(string.IsNullOrEmpty(_nugetPkgBuiltDir))
{
string codeBasePath = Assembly.GetExecutingAssembly().CodeBase;
var uri = new UriBuilder(codeBasePath);
string path = Uri.UnescapeDataString(uri.Path);
path = Path.GetDirectoryName(path);

_nugetPkgBuiltDir = Directory.GetParent(path).FullName;
}

return _nugetPkgBuiltDir;
}
}

public string PublishToDir
{
get
{
return _publishToDir;
}
}

public PublishTests()
{
if(Directory.Exists(NugetPkgBuiltDir))
{
string pubDir = Path.Combine(NugetPkgBuiltDir, "testPublish");
if(!Directory.Exists(pubDir))
{
Directory.CreateDirectory(pubDir);
}

_publishToDir = pubDir;
}
}


[Fact]
public void PublishSingleNuget()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.PackageOutputPath = NugetPkgBuiltDir;
pubNug.NugetPackageName = NUGET_PKG_NAME;
pubNug.PublishNugetToPath = PublishToDir;

pubNug.Execute();

List<NugetPublishStatus> statusList = pubNug.NugetPublishStatus;

foreach(NugetPublishStatus status in statusList)
{
Assert.Equal(0, status.NugetPublishExitCode);
}
}

[Fact]
public void NonExistentPublishLocation()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.PackageOutputPath = NugetPkgBuiltDir;
pubNug.NugetPackageName = NUGET_PKG_NAME;
pubNug.PublishNugetToPath = "http://somelocation";
pubNug.SkipSymbolPublishing = true;
pubNug.ApiKey = "1234";

Assert.ThrowsAny<Exception>(() => pubNug.Execute());
}

[Fact]
public void SkipPublishingSymbols()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.PackageOutputPath = NugetPkgBuiltDir;
pubNug.NugetPackageName = NUGET_PKG_NAME;
pubNug.PublishNugetToPath = PublishToDir;
pubNug.SkipSymbolPublishing = true;

pubNug.Execute();

List<NugetPublishStatus> statusList = pubNug.NugetPublishStatus;

Assert.Equal(1, statusList?.Count);

foreach (NugetPublishStatus status in statusList)
{
Assert.Equal(0, status.NugetPublishExitCode);
}
}

#region Error Tests

[Fact]
public void PublishWithUnAuthenticatedKey()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.PackageOutputPath = NugetPkgBuiltDir;
pubNug.NugetPackageName = NUGET_PKG_NAME;
pubNug.PublishNugetToPath = "https://www.nuget.org/api/v2/package/";
pubNug.SkipSymbolPublishing = true;
pubNug.ApiKey = "1234";

try
{
pubNug.Execute();
}
catch(Exception ex)
{
if(!ex.Message.Contains("The specified API key is invalid"))
{
Assert.Equal("The specified API key is invalid", ex.Message);
}
}
}

[Fact]
public void IncorrectNugetExePath()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.PackageOutputPath = NugetPkgBuiltDir;
pubNug.NugetPackageName = NUGET_PKG_NAME;
pubNug.PublishNugetToPath = PublishToDir;
pubNug.SkipSymbolPublishing = true;
pubNug.NugetExePath = @"C:\Foo\NoExistantPath\nuget.exe";
Assert.ThrowsAny<Exception>(() => pubNug.Execute());
}

[Fact]
public void MissingNugetPackageName()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.PackageOutputPath = NugetPkgBuiltDir;
pubNug.PublishNugetToPath = PublishToDir;
pubNug.SkipSymbolPublishing = true;
Assert.ThrowsAny<NullReferenceException>(() => pubNug.Execute());
}

[Fact]
public void PublishAllNugetUnderScope()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.publishAllNugetsUnderScope = true;
Assert.Throws<NotSupportedException>(() => pubNug.Execute());
}

[Fact]
public void MissingRequiredProperties()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
Assert.ThrowsAny<NullReferenceException>(() => pubNug.Execute());
}

[Fact]
public void SkipPublishingCompletely()
{
PublishSDKNuget pubNug = new PublishSDKNuget();
pubNug.PackageOutputPath = NugetPkgBuiltDir;
pubNug.NugetPackageName = NUGET_PKG_NAME;
pubNug.PublishNugetToPath = PublishToDir;
pubNug.SkipSymbolPublishing = true;
pubNug.SkipNugetPublishing = true;
Assert.Throws<ApplicationException>(() => pubNug.Execute());
}

#endregion
}
}
Loading

0 comments on commit d6ad1e2

Please sign in to comment.