Skip to content

Commit

Permalink
lots of improvements that I never checked in
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmjr committed Oct 8, 2024
1 parent a599016 commit ccbbf75
Show file tree
Hide file tree
Showing 13 changed files with 26,559 additions and 256 deletions.
795 changes: 600 additions & 195 deletions .gitignore

Large diffs are not rendered by default.

25,898 changes: 25,898 additions & 0 deletions NuGetPush.Preprocessed.csproj

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions NuGetPush.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* License: MIT (https://opensource.org/licenses/MIT)
-->

<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Dgmjr.NET.Sdk">
<Import Project="./Sdk/Sdk.props" />
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down Expand Up @@ -74,8 +74,8 @@
<Target Name="CleanJSOutput" AfterTargets="Clean">
<Delete Files="$(MSBuildThisFileDirectory)Scripts/js/*" />
</Target>
<Target Name="TestNuGetPush" AfterTargets="AfterBuild">
<!-- <Target Name="TestNuGetPush" AfterTargets="AfterBuild">
<MSBuild Projects="./TestTasks.csproj" />
</Target>
</Target> -->
<Import Project="./Sdk/Sdk.targets" />
</Project>
2 changes: 2 additions & 0 deletions Tasks/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace NuGetPush.Tasks;
public static class Constants
{
public const string DefaultDynamicTargetsFilePath = "NuGet.Dynamic.targets";
public const string NupkgRegexString =
@"^(?:.*/)?(?<PackageId>.+)\.(?<Version>(?<Major>\d+)\.(?<Minor>\d+)\.(?<Build>\d+)(?:-(?<Prerelease>[\w.-]+))?)\.nupkg$";

public static class MetadataNames
{
Expand Down
35 changes: 17 additions & 18 deletions Tasks/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace NuGetPush.Tasks;

public class DeletePackage : NuGetPackageTaskBase
public class DeletePackage(ResourceManager taskResources, string? helpKeywordPrefix = default) : NuGetPackageTaskBase(taskResources, helpKeywordPrefix)
{
public DeletePackage(ResourceManager taskResources, string helpKeywordPrefix)
: base(taskResources, helpKeywordPrefix) { }

public DeletePackage()
: base() { }
public DeletePackage() : this(new ResourceManager("NuGetPush.Tasks", typeof(DeletePackage).Assembly)) { }

[Required]
public string PackageId { get; set; }
Expand All @@ -24,18 +20,21 @@ public override bool Execute()
}

Logger.LogWarning($"Deleting {PackageId} version {PackageVersion} from source {Source}...");
DeleteRunner.Run(
Settings,
PackageSourceProvider,
PackageId,
PackageVersion,
Source,
ApiKey,
true,
false,
_ => true,
Logger
);
var psi = new ProcessStartInfo("dotnet", ["nuget", "delete", PackageId, PackageVersion, "-s", Source, "-k", ApiKey]);
var p = Process.Start(psi);
p.WaitForExit();
// DeleteRunner.Run(
// Settings,
// PackageSourceProvider,
// PackageId,
// PackageVersion,
// Source,
// ApiKey,
// true,
// false,
// _ => true,
// Logger
// );
Logger.LogWarning("Done.");
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions Tasks/DeleteAndPush.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace NuGetPush.Tasks;

using System.Configuration;

public class DeleteAndPush : NuGetPackageTaskBase
{
[Required]
Expand All @@ -26,6 +28,7 @@ public override bool Execute()
determineIfPackageExists.Execute();
if (determineIfPackageExists.PackageExists)
{
Log.LogWarning($"Package {PackageId} already exists in source {Source}. Deleting it.");
new DeletePackage(TaskResources, HelpKeywordPrefix)
{
Source = Source,
Expand Down
1 change: 1 addition & 0 deletions Tasks/DetermineIfPackageExists.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public virtual bool DoesPackageExist()
{
try
{
List<string> args = ["nuget", "push", PackagePath, "-s", Source];
var psi = new ProcessStartInfo("nuget", ["search", "-s", Source, PackageId, "-PreRelease"])
{
RedirectStandardOutput = true
Expand Down
21 changes: 12 additions & 9 deletions Tasks/GenerateDynamicTargets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public string PackageId
private string _packageVersion;
public string PackageVersion
{
get => _packageVersion ??= PackagePath.GetPackageId();
get => _packageVersion ??= PackagePath.GetPackageVersion();
set => _packageVersion = value;
}

Expand Down Expand Up @@ -73,20 +73,23 @@ public override bool Execute()

var dynamicTargetsSource = $"""
<Project>
{Join("\n", packageSources.Select(source =>
{Join(
"""
<!-- ******************* -->
""", packageSources.Select(source =>
$"""
<PropertyGroup>
<Push{SanitizeName(source.Name)}IsEnabled Condition="'$(Push{SanitizeName(source.Name)}IsEnabled)' == ''">false</Push{SanitizeName(source.Name)}IsEnabled>
</PropertyGroup>
<Target Name="Push{SanitizeName(source.Name)}" AfterTargets="Pack" Condition="'$(GeneratePackageOnBuild)' == 'true' And '$(Push{SanitizeName(source.Name)}IsEnabled)' == 'true'">
<!--<DetermineIfPackageExists PackagePath="{PackagePath}" ProjectFile="{ProjectFile}" Source="{source.Source}">
<Target Name="Push{SanitizeName(source.Name)}" AfterTargets="Pack" DependsOnTargets="Pack" Condition="'$(GeneratePackageOnBuild)' == 'true' And '$(Push{SanitizeName(source.Name)}IsEnabled)' == 'true'">
<DetermineIfPackageExists PackagePath="{PackagePath}" ProjectFile="{ProjectFile}" Source="{source.Source}">
<Output TaskParameter="PackageExists" PropertyName="PackageExists" />
</DetermineIfPackageExists>-->
<Exec Command="nuget search -s {source.Name} {PackageId} -PreRelease | grep {PackageId}" ConsoleToMsBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" ItemName="ConsoleOutput"/>
</Exec>
</DetermineIfPackageExists>
<PropertyGroup>
<PackageExists>false</PackageExists> <!-- default it to false -->
Expand Down
4 changes: 2 additions & 2 deletions Tasks/NuGetPackageTaskBase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace NuGetPush.Tasks;

using System;

using NuGet.Protocol.Core.Types;

namespace NuGetPush.Tasks;

public abstract class NuGetPackageTaskBase() : NuGetTaskBase
{
protected NuGetPackageTaskBase(ResourceManager taskResources)
Expand Down
3 changes: 3 additions & 0 deletions Tasks/NuGetTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ namespace NuGetPush.Tasks;

public abstract class NuGetTaskBase() : MSBTask
{
protected static readonly ResourceManager DefaultResourceManager =
new("NuGetPush.Tasks", typeof(NuGetTaskBase).Assembly);

protected NuGetTaskBase(ResourceManager taskResources)
: this()
{
Expand Down
16 changes: 15 additions & 1 deletion Tasks/Push.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
using NuGetPush.Tasks.Extensions;

namespace NuGetPush.Tasks;

public class PushPackage : NuGetPackageTaskBase
{
public PushPackage(ResourceManager taskResources, string helpKeywordPrefix) : base(taskResources, helpKeywordPrefix) { }
public PushPackage() : base() { }

public string PackageId => PackagePath.GetPackageId();

public string PackageVersion => PackagePath.GetPackageVersion();

[Required]
public string PackagePath { get; set; }
public override bool Execute()
Expand All @@ -14,7 +20,15 @@ public override bool Execute()
return false;
}

PushRunner.Run(Settings, PackageSourceProvider, [PackagePath], Source, ApiKey, null, null, 10, false, true, false, true, Logger);
Logger.LogWarning($"Pushing {PackageId} version {PackageVersion} to source {Source}...");
// PushRunner.Run(Settings, PackageSourceProvider, [PackagePath], Source, ApiKey, null, null, 10, false, true, false, true, Logger);
List<string> args = ["nuget", "push", PackagePath, "-s", Source];
if(!IsNullOrEmpty(ApiKey))
{
args.AddRange(["-k", ApiKey]);
}
var psi = new ProcessStartInfo("dotnet", args);
Process.Start(psi).WaitForExit();
return true;
}

Expand Down
7 changes: 3 additions & 4 deletions Tasks/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
namespace NuGetPush.Tasks.Extensions;

using static Constants;

public static partial class NuGetStringExtensions
{
public const string NupkgRegexString =
@"^(?:.*/)?(?<PackageId>.+)\.(?<Version>(?<Major>\d+)\.(?<Minor>\d+)\.(?<Build>\d+)(?:-(?<Prerelease>[\w.-]+))?)\.nupkg$";

[GeneratedRegex(NupkgRegexString)]
private static partial Regex NupkgRegex();
private static partial Regx NupkgRegex();

public static string GetPackageId(this string packagePath) =>
NupkgRegex().IsMatch(packagePath)
Expand Down
24 changes: 0 additions & 24 deletions TestTasks.csproj

This file was deleted.

0 comments on commit ccbbf75

Please sign in to comment.