Skip to content

Commit

Permalink
Merge pull request #1549 from zvirja/support-nuget-symbols-upload
Browse files Browse the repository at this point in the history
Add support for custom NuGet symbol feed during push
  • Loading branch information
matthid authored May 10, 2017
2 parents e9bffb2 + b1d3916 commit 0a08458
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/app/FakeLib/NuGet/NugetHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type NuGetParams =
OutputPath : string
PublishUrl : string
AccessKey : string
SymbolPublishUrl: string
SymbolAccessKey: string
NoDefaultExcludes : bool
NoPackageAnalysis : bool
ProjectFile : string
Expand Down Expand Up @@ -91,6 +93,8 @@ let NuGetDefaults() =
WorkingDir = "./NuGet"
PublishUrl = "https://www.nuget.org/api/v2/package"
AccessKey = null
SymbolPublishUrl = null
SymbolAccessKey = null
NoDefaultExcludes = false
NoPackageAnalysis = false
PublishTrials = 5
Expand Down Expand Up @@ -129,9 +133,12 @@ let GetPackageVersion deploymentsDir package =
with
| exn -> new Exception("Could not detect package version for " + package, exn) |> raise

let private replaceAccessKey key (text : string) =
if isNullOrEmpty key then text
else text.Replace(key, "PRIVATEKEY")
let private replaceAccessKeys parameters (text:string) =
let replaceKey key (str:string) =
if isNullOrEmpty key then str
else str.Replace(key, "PRIVATEKEY")

text |> (replaceKey parameters.AccessKey >> replaceKey parameters.SymbolAccessKey)

let private createNuSpecFromTemplate parameters (templateNuSpec:FileInfo) =
let specFile = parameters.WorkingDir @@ (templateNuSpec.Name.Replace("nuspec", "") + parameters.Version + ".nuspec")
Expand Down Expand Up @@ -292,14 +299,20 @@ let private pack parameters nuspecFile =
let rec private publish parameters =
let tracing = enableProcessTracing
enableProcessTracing <- false
let source =
if isNullOrEmpty parameters.PublishUrl then ""
else sprintf "-source %s" parameters.PublishUrl

let args = sprintf "push \"%s\" %s %s" (parameters.OutputPath @@ packageFileName parameters
|> FullName) parameters.AccessKey source
tracefn "%s %s in WorkingDir: %s Trials left: %d" parameters.ToolPath (replaceAccessKey parameters.AccessKey args)
(FullName parameters.WorkingDir) parameters.PublishTrials

// Newer NuGet requires source to be always specified, so if PublishUrl is empty,
// ignore symbol source - the produced source is broken anyway.
let normalize str = if isNullOrEmpty str then None else Some str
let source = match parameters.PublishUrl |> normalize, parameters.SymbolPublishUrl |> normalize with
| None, _ -> ""
| Some source, None -> sprintf "-source %s" source
| Some source, Some symSource -> sprintf "-source %s -SymbolSource %s -SymbolApiKey %s"
source symSource parameters.SymbolAccessKey

let args = sprintf "push \"%s\" %s %s" (parameters.OutputPath @@ packageFileName parameters |> FullName)
parameters.AccessKey source
tracefn "%s %s in WorkingDir: %s Trials left: %d" parameters.ToolPath (replaceAccessKeys parameters args)
(FullName parameters.WorkingDir) parameters.PublishTrials
try
let result =
ExecProcess (fun info ->
Expand All @@ -319,7 +332,7 @@ let rec private publishSymbols parameters =
let args =
sprintf "push -source %s \"%s\" %s" parameters.PublishUrl (packageFileName parameters) parameters.AccessKey

tracefn "%s %s in WorkingDir: %s Trials left: %d" parameters.ToolPath (replaceAccessKey parameters.AccessKey args)
tracefn "%s %s in WorkingDir: %s Trials left: %d" parameters.ToolPath (replaceAccessKeys parameters args)
(FullName parameters.WorkingDir) parameters.PublishTrials
try
let result =
Expand Down Expand Up @@ -347,7 +360,7 @@ let NuGetPackDirectly setParams nuspecOrProjectFile =
with exn ->
(if exn.InnerException <> null then exn.Message + "\r\n" + exn.InnerException.Message
else exn.Message)
|> replaceAccessKey parameters.AccessKey
|> replaceAccessKeys parameters
|> failwith

/// Creates a new NuGet package based on the given .nuspec or project file.
Expand All @@ -368,7 +381,7 @@ let NuGetPack setParams nuspecOrProjectFile =
with exn ->
(if exn.InnerException <> null then exn.Message + "\r\n" + exn.InnerException.Message
else exn.Message)
|> replaceAccessKey parameters.AccessKey
|> replaceAccessKeys parameters
|> failwith

/// Publishes a NuGet package to the nuget server.
Expand All @@ -383,7 +396,7 @@ let NuGetPublish setParams =
with exn ->
(if exn.InnerException <> null then exn.Message + "\r\n" + exn.InnerException.Message
else exn.Message)
|> replaceAccessKey parameters.AccessKey
|> replaceAccessKeys parameters
|> failwith

/// Creates a new NuGet package, and optionally publishes it.
Expand All @@ -408,7 +421,7 @@ let NuGet setParams nuspecOrProjectFile =
with exn ->
(if exn.InnerException <> null then exn.Message + "\r\n" + exn.InnerException.Message
else exn.Message)
|> replaceAccessKey parameters.AccessKey
|> replaceAccessKeys parameters
|> failwith

/// NuSpec metadata type
Expand Down
6 changes: 6 additions & 0 deletions src/test/Test.FAKECore/PackageMgt/NugetSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class when_packing_with_nuspec_template
files: ListModule.OfSeq(new [] { new Tuple<string, FSharpOption<string>, FSharpOption<string>>("*.*", FSharpOption<string>.None, FSharpOption<string>.None) }),

accessKey: p.AccessKey,
symbolAccessKey: p.SymbolAccessKey,
copyright: p.Copyright,
dependencies: p.Dependencies,
dependenciesByFramework: p.DependenciesByFramework,
Expand All @@ -45,6 +46,7 @@ public class when_packing_with_nuspec_template
publish: p.Publish,
publishTrials: p.PublishTrials,
publishUrl: p.PublishUrl,
symbolPublishUrl: p.SymbolPublishUrl,
references: p.References,
referencesByFramework: p.ReferencesByFramework,
frameworkAssemblies: p.FrameworkAssemblies,
Expand Down Expand Up @@ -90,6 +92,7 @@ public class when_packing_with_csproj_and_complete_nuspec_alongside
files: ListModule.OfSeq(new[] { new Tuple<string, FSharpOption<string>, FSharpOption<string>>("*.*", FSharpOption<string>.None, FSharpOption<string>.None) }),

accessKey: p.AccessKey,
symbolAccessKey: p.SymbolAccessKey,
copyright: p.Copyright,
dependencies: p.Dependencies,
dependenciesByFramework: p.DependenciesByFramework,
Expand All @@ -101,6 +104,7 @@ public class when_packing_with_csproj_and_complete_nuspec_alongside
publish: p.Publish,
publishTrials: p.PublishTrials,
publishUrl: p.PublishUrl,
symbolPublishUrl: p.SymbolPublishUrl,
references: p.References,
referencesByFramework: p.ReferencesByFramework,
frameworkAssemblies: p.FrameworkAssemblies,
Expand Down Expand Up @@ -158,6 +162,7 @@ public class when_packing_with_a_complete_nuspec_file
files: ListModule.OfSeq(new [] { new Tuple<string, FSharpOption<string>, FSharpOption<string>>("*.*", FSharpOption<string>.None, FSharpOption<string>.None) }),

accessKey: p.AccessKey,
symbolAccessKey: p.SymbolAccessKey,
copyright: p.Copyright,
dependencies: p.Dependencies,
dependenciesByFramework: p.DependenciesByFramework,
Expand All @@ -169,6 +174,7 @@ public class when_packing_with_a_complete_nuspec_file
publish: p.Publish,
publishTrials: p.PublishTrials,
publishUrl: p.PublishUrl,
symbolPublishUrl: p.SymbolPublishUrl,
references: p.References,
referencesByFramework: p.ReferencesByFramework,
frameworkAssemblies: p.FrameworkAssemblies,
Expand Down

0 comments on commit 0a08458

Please sign in to comment.