Skip to content
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

Add support for custom NuGet symbol feed during push #1549

Merged
merged 1 commit into from
May 10, 2017
Merged
Show file tree
Hide file tree
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
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 = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should change this default or do it like nuget and throw an error? (I know its unrelated to this PR, but it might make sense to fix that as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a separate issue about defaults and I'd prefer to fix it via separate PR.

do it like nuget and throw an error

It's a dangerous change, because previous versions of Nuget worked fine without source specified. If we start to require the source now, it would be a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yes you are right :)

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