Skip to content

Fix bug with Publish-PSResource not properly adding tags to nuspec #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/code/PublishPSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ protected override void ProcessRecord()
{
nuspec = CreateNuspec(outputDir, moduleFileInfo, out dependencies, parsedMetadataHash);
}
catch {
var message = "Nuspec creation failed.";
catch (Exception e) {
var message = string.Format("Nuspec creation failed: {0}", e.Message);
var ex = new ArgumentException(message);
var nuspecCreationFailed = new ErrorRecord(ex, "NuspecCreationFailed", ErrorCategory.ObjectNotFound, null);
WriteError(nuspecCreationFailed);
Expand Down Expand Up @@ -451,7 +451,8 @@ private string CreateNuspec(
}
else
{
var data = ast.Find(a => a is HashtableAst, false);
// Must search nested script blocks because 'Tags' are located under 'PrivateData' > 'PSData'
var data = ast.Find(a => a is HashtableAst, true);
if (data != null)
{
parsedMetadataHash = (Hashtable) data.SafeGetValue();
Expand Down Expand Up @@ -506,18 +507,26 @@ private string CreateNuspec(
return string.Empty;
}

// Look for Prerelease tag
// Look for Prerelease tag and then process any Tags in PrivateData > PSData
if (parsedMetadataHash.ContainsKey("PrivateData"))
{
if (parsedMetadataHash["PrivateData"] is Hashtable privateData &&
privateData.ContainsKey("PSData"))
{
if (privateData["PSData"] is Hashtable psData &&
psData.ContainsKey("Prerelease"))
if (privateData["PSData"] is Hashtable psData)
{
if (psData["Prerelease"] is string preReleaseVersion)
if (psData.ContainsKey("Prerelease") && psData["Prerelease"] is string preReleaseVersion)
{
version = string.Format(@"{0}-{1}", version, preReleaseVersion);
}
if (psData.ContainsKey("Tags") && psData["Tags"] is Array manifestTags)
{
version = string.Format(@"{0}-{1}", version, preReleaseVersion);
var tagArr = new List<string>();
foreach (string tag in manifestTags)
{
tagArr.Add(tag);
}
parsedMetadataHash["tags"] = string.Join(" ", tagArr.ToArray());
}
}
}
Expand Down