Skip to content

Commit

Permalink
Copy missing changes from legacy NuGet helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
zvirja committed Jun 15, 2017
1 parent 574f625 commit 475bf3d
Showing 1 changed file with 34 additions and 17 deletions.
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

/// 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

0 comments on commit 475bf3d

Please sign in to comment.