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

Copy missing changes from legacy NuGet helpers #1596

Merged
merged 1 commit into from
Jun 16, 2017
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
51 changes: 34 additions & 17 deletions src/app/Fake.DotNet.NuGet/NuGet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type NuGetParams =
OutputPath : string
PublishUrl : string
AccessKey : string
SymbolPublishUrl: string
SymbolAccessKey: string
NoDefaultExcludes : bool
NoPackageAnalysis : bool
ProjectFile : string
Expand Down Expand Up @@ -99,8 +101,10 @@ let NuGetDefaults() =
IncludeReferencedProjects = false
OutputPath = "./NuGet"
WorkingDir = "./NuGet"
PublishUrl = null
PublishUrl = "https://www.nuget.org/api/v2/package"
AccessKey = null
SymbolPublishUrl = null
SymbolAccessKey = null
NoDefaultExcludes = false
NoPackageAnalysis = false
PublishTrials = 5
Expand Down Expand Up @@ -141,9 +145,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 @@ -301,14 +308,19 @@ let private pack parameters nuspecFile =

/// push package (and try again if something fails)
let rec private publish parameters =
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
Trace.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
Trace.tracefn "%s %s in WorkingDir: %s Trials left: %d" parameters.ToolPath (replaceAccessKeys parameters args)
(FullName parameters.WorkingDir) parameters.PublishTrials
try
let result =
let tracing = shouldEnableProcessTracing()
Expand All @@ -330,7 +342,7 @@ let rec private publishSymbols parameters =
let args =
sprintf "push -source %s \"%s\" %s" parameters.PublishUrl (packageFileName parameters) parameters.AccessKey

Trace.tracefn "%s %s in WorkingDir: %s Trials left: %d" parameters.ToolPath (replaceAccessKey parameters.AccessKey args)
Trace.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 @@ -361,7 +373,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 @@ -382,7 +394,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 @@ -392,7 +404,12 @@ let NuGetPack setParams nuspecOrProjectFile =
let NuGetPublish setParams =
let parameters = NuGetDefaults() |> setParams
use __ = Trace.traceTask "NuGet-Push" (packageFileName parameters)
publish parameters
try
publish parameters
with exn ->
if exn.InnerException <> null then exn.Message + "\r\n" + exn.InnerException.Message else exn.Message
|> replaceAccessKeys parameters
|> failwith
Copy link
Member

Choose a reason for hiding this comment

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

Since fsprojects/Paket#2423 I'm no longer a huge fan of failwith in a general with clause.
But it's not clear how we can remove the access keys in a secure way. They probably shouldn't be part of the error message in the first place if possible :/

Copy link
Contributor Author

@zvirja zvirja Jun 16, 2017

Choose a reason for hiding this comment

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

Yep, probably we should find more graceful solution as I also don't like those e. Message + e.InnerException.Message. However, currently I'd prefer to make this PR simple and just copy the missing changes.


/// Creates a new NuGet package, and optionally publishes it.
/// Template parameter substitution is performed when passing a .nuspec
Expand All @@ -416,7 +433,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