-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for overriding nuspec repository url and version before p…
…ushing nupkg to GPR. Fixes #48 Update error message. Remove dead code because there are no "xmlns" attributes to remove when instantiating a new XElement. Rename file. Refactor: Owner property is no longer required. Address feedback regarding --repository option that should be in the following format: owner/repository. This makes it trivial to change repository url in a github actions scenario: gpr push your.nupkg --repository ${{ github.repository }} -k ${{ secrets.GITHUB_TOKEN }}. I have added additional test cases that verifies that we only rewrite nuspec if repository url, repository type or version has been changed. /cc @jcansdale Bugfix: Dispose nuspec context property. Only attempt to parse version if repository option has been set. Bugfix: Remove "_gpr.nupkg" prefix if nupkg is rewritten before uploading nupkg to GPR.
- Loading branch information
Showing
6 changed files
with
458 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace GprTool | ||
{ | ||
public static class IoExtensions | ||
{ | ||
public static FileStream OpenReadShared(this string filename) | ||
{ | ||
return File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read); | ||
} | ||
|
||
public static MemoryStream ReadSharedToStream(this string filename) | ||
{ | ||
using var fileStream = filename.OpenReadShared(); | ||
var outputStream = new MemoryStream(); | ||
fileStream.CopyTo(outputStream); | ||
outputStream.Seek(0, SeekOrigin.Begin); | ||
return outputStream; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Xml.Linq; | ||
|
||
namespace GprTool | ||
{ | ||
public static class NugetExtensions | ||
{ | ||
public static XElement Single([NotNull] this XDocument xDocument, [NotNull] XName name, bool ignoreCase = true, bool ignoreNamespace = true) | ||
{ | ||
if (xDocument == null) throw new ArgumentNullException(nameof(xDocument)); | ||
if (name == null) throw new ArgumentNullException(nameof(name)); | ||
return xDocument.Descendants().SingleOrDefault(name, ignoreCase, ignoreNamespace, true); | ||
} | ||
|
||
public static XElement Single([NotNull] this XElement xElement, [NotNull] XName name, bool ignoreCase = true, bool ignoreNamespace = true) | ||
{ | ||
if (xElement == null) throw new ArgumentNullException(nameof(xElement)); | ||
if (name == null) throw new ArgumentNullException(nameof(name)); | ||
return xElement.Descendants().SingleOrDefault(name, ignoreCase, ignoreNamespace, true); | ||
} | ||
|
||
[SuppressMessage("ReSharper", "UnusedMember.Global")] | ||
public static XElement SingleOrDefault([NotNull] this XDocument xDocument, [NotNull] XName name, bool ignoreCase = true, bool ignoreNamespace = true) | ||
{ | ||
if (xDocument == null) throw new ArgumentNullException(nameof(xDocument)); | ||
if (name == null) throw new ArgumentNullException(nameof(name)); | ||
return xDocument.Descendants().SingleOrDefault(name, ignoreCase, ignoreNamespace); | ||
} | ||
|
||
public static XElement SingleOrDefault([NotNull] this XElement xElement, [NotNull] XName name, bool ignoreCase = true, bool ignoreNamespace = true) | ||
{ | ||
if (xElement == null) throw new ArgumentNullException(nameof(xElement)); | ||
if (name == null) throw new ArgumentNullException(nameof(name)); | ||
return xElement.Descendants().SingleOrDefault(name, ignoreCase, ignoreNamespace); | ||
} | ||
|
||
public static XElement SingleOrDefault([NotNull] this IEnumerable<XElement> xElements, [NotNull] XName name, bool ignoreCase = true, bool ignoreNamespace = true, bool throwifNotFound = false) | ||
{ | ||
if (xElements == null) throw new ArgumentNullException(nameof(xElements)); | ||
if (name == null) throw new ArgumentNullException(nameof(name)); | ||
foreach (var node in xElements) | ||
{ | ||
var comperator = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; | ||
if (!string.Equals(node.Name.LocalName, name.LocalName, comperator)) | ||
{ | ||
continue; | ||
} | ||
|
||
if (!ignoreNamespace && !string.Equals(node.Name.NamespaceName, name.NamespaceName, comperator)) | ||
{ | ||
continue; | ||
} | ||
|
||
return node; | ||
} | ||
|
||
if (throwifNotFound) | ||
{ | ||
throw new Exception($"The required element '{name}' is missing"); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.