Skip to content

Commit

Permalink
Added the analyzer to the build project and allowed a no-unlist
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Jan 31, 2023
1 parent 6a98f68 commit 5196b2c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
34 changes: 23 additions & 11 deletions tools/build/BuildDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,24 @@ public static SuccessfulAotTests AotTest(Options options, SuccessfulBuild _)
return default;
}

public static NuGetPackage Pack(Options options, GitVersion version, SuccessfulUnitTests _, SuccessfulAotTests __)
public static List<NuGetPackage> Pack(Options options, GitVersion version, SuccessfulUnitTests _, SuccessfulAotTests __)
{
var result = new List<NuGetPackage>();
var verbosity = options.Verbose ? "detailed" : "minimal";
var buildDir = Path.Combine(BasePath, "YamlDotNet");
Run("nuget", $"pack YamlDotNet.nuspec -Version {version.NuGetVersion} -OutputDirectory bin", buildDir);

var packagePath = Path.Combine(buildDir, "bin", $"YamlDotNet.{version.NuGetVersion}.nupkg");
return new NuGetPackage(packagePath);
result.Add(new NuGetPackage(packagePath, "YamlDotNet"));

buildDir = Path.Combine(BasePath, "YamlDotNet.Analyzers.StaticGenerator");
Run("nuget", $"pack YamlDotNet.Analyzers.StaticGenerator.nuspec -Version {version.NuGetVersion} -OutputDirectory bin", buildDir);
packagePath = Path.Combine(buildDir, "bin", $"YamlDotNet.Analyzers.StaticGenerator.{version.NuGetVersion}.nupkg");
result.Add(new NuGetPackage(packagePath, "YamlDotNet.Analyzers.StaticGenerator"));

return result;
}

public static void Publish(Options options, GitVersion version, NuGetPackage package)
public static void Publish(Options options, GitVersion version, List<NuGetPackage> packages)
{
var apiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY");
if (string.IsNullOrEmpty(apiKey))
Expand All @@ -186,13 +193,16 @@ public static void Publish(Options options, GitVersion version, NuGetPackage pac
}
else
{
Console.WriteLine($"nuget push {package.Path} -ApiKey *** -Source https://api.nuget.org/v3/index.json");
Run("nuget", $"push {package.Path} -ApiKey {apiKey} -Source https://api.nuget.org/v3/index.json", noEcho: true);

if (version.IsPreRelease)
foreach (var package in packages)
{
Console.WriteLine($"nuget delete YamlDotNet {version.NuGetVersion} -NonInteractive -ApiKey *** -Source https://api.nuget.org/v3/index.json");
Run("nuget", $"delete YamlDotNet {version.NuGetVersion} -NonInteractive -ApiKey {apiKey} -Source https://api.nuget.org/v3/index.json", noEcho: true);
Console.WriteLine($"nuget push {package.Path} -ApiKey *** -Source https://api.nuget.org/v3/index.json");
Run("nuget", $"push {package.Path} -ApiKey {apiKey} -Source https://api.nuget.org/v3/index.json", noEcho: true);

if (version.IsPreRelease && UnlistPackage)
{
Console.WriteLine($"nuget delete {package.Name} {version.NuGetVersion} -NonInteractive -ApiKey *** -Source https://api.nuget.org/v3/index.json");
Run("nuget", $"delete {package.Name} {version.NuGetVersion} -NonInteractive -ApiKey {apiKey} -Source https://api.nuget.org/v3/index.json", noEcho: true);
}
}
}
}
Expand Down Expand Up @@ -564,12 +574,14 @@ public PreviousReleases(IEnumerable<Version> versions)

public class NuGetPackage
{
public NuGetPackage(string path)
public NuGetPackage(string path, string name)
{
Path = path;
Name = name;
}

public string Path { get; }
public string Name { get; }
}

internal class LoggerHttpHandler : HttpClientHandler
Expand Down
8 changes: 8 additions & 0 deletions tools/build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Program
private static bool verbose;
public static Host Host { get; private set; }
private static readonly Dictionary<Type, object> state = new Dictionary<Type, object>();
public static bool UnlistPackage { get; private set; } = true;

private static T GetState<T>() where T : notnull
{
Expand Down Expand Up @@ -130,6 +131,12 @@ static async Task<int> Main(string[] args)
return false;
}

if (a == "--no-unlist")
{
UnlistPackage = false;
return false;
}

return true;
})
.ToList();
Expand Down Expand Up @@ -213,6 +220,7 @@ static async Task<int> Main(string[] args)
Console.WriteLine($"{palette.Default}Additional options:");
Console.WriteLine($" {palette.Option}--no-prerelease {palette.Default}Force the current version to be considered final{palette.Reset}");
Console.WriteLine($" {palette.Option}--version=<version> {palette.Default}Force the current version to equal to the specified value{palette.Reset}");
Console.WriteLine($" {palette.Option}--no-unlist {palette.Default}Don't unlist the pushed NuGet package{palette.Reset}");
}

return exitCode;
Expand Down

0 comments on commit 5196b2c

Please sign in to comment.