Skip to content

Commit

Permalink
Paket init downloads stable version of bootstraper - fixes #1040
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 29, 2015
1 parent b10ddff commit d1ce647
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### 2.19.0-alpha001 - 29.10.2015
#### 2.19.0-alpha002 - 29.10.2015
* Resolver changed to breadth first search to escape more quickly from conflict situations - https://github.com/fsprojects/Paket/issues/1174
* Paket init downloads stable version of bootstraper - https://github.com/fsprojects/Paket/issues/1040

#### 2.18.0 - 28.10.2015
* Use branch and bound strategy to escape quickly from conflict situations - https://github.com/fsprojects/Paket/issues/1169
Expand Down
4 changes: 2 additions & 2 deletions integrationtests/Paket.IntegrationTests/InitSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ open System.Diagnostics
[<Test>]
let ``#1040 init should download release version of bootstrapper``() =
paket "init" "i001040-init-downloads-bootstrapper"
let bootstrapperpath = Path.Combine(scenarioTempPath "i001040-init-downloads-bootstrapper",".paket","paket.bootstrapper.exe")
let bootstrapperPath = Path.Combine(scenarioTempPath "i001040-init-downloads-bootstrapper",".paket","paket.bootstrapper.exe")

let productVersion = FileVersionInfo.GetVersionInfo(bootstrapperpath).ToString()
let productVersion = FileVersionInfo.GetVersionInfo(bootstrapperPath).ProductVersion
String.IsNullOrWhiteSpace productVersion |> shouldEqual false
productVersion.Contains("-") |> shouldEqual false
4 changes: 2 additions & 2 deletions src/Paket.Core/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ open System.IO
open Paket.Domain

[<Literal>]
let GithubUrl = "https://github.com"
let GitHubUrl = "https://github.com"

[<Literal>]
let DefaultNugetStream = "https://nuget.org/api/v2"

[<Literal>]
let GithubReleasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"
let GitHubReleasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"

[<Literal>]
let GithubReleaseDownloadUrl = "https://github.com/fsprojects/Paket/releases/download"
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PublicAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ type Dependencies(dependenciesFileName: string) =
member this.DownloadLatestBootstrapper() : unit =
Utils.RunInLockedAccessMode(
this.RootPath,
fun () -> Releases.downloadLatestBootstrapper |> this.Process)
fun () -> Releases.downloadLatestBootstrapperAndTargets |> this.Process)

/// Pulls new paket.targets and bootstrapper and puts them into .paket folder.
member this.TurnOnAutoRestore(): unit =
Expand Down
21 changes: 12 additions & 9 deletions src/Paket.Core/Releases.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ open System
open Chessie.ErrorHandling
open Paket.Domain

let private getLatestVersionFromJson (data : string) =
let rec private getLatestVersionFromJson (data : string, startPos: int) =
try
let start = data.IndexOf("tag_name") + 11
let start = data.IndexOf("tag_name", startPos) + 11
let end' = data.IndexOf("\"", start)
(data.Substring(start, end' - start)) |> SemVer.Parse |> ok
let v = (data.Substring(start, end' - start)) |> SemVer.Parse
match v.PreRelease with
| None -> ok v
| _ -> getLatestVersionFromJson (data, start)
with _ ->
fail ReleasesJsonParseError

Expand All @@ -28,17 +31,17 @@ let private download version (file:FileInfo) client =
let private doesNotExistsOrIsNewer (file : FileInfo) latest =
if not file.Exists then true else
let verInfo = FileVersionInfo.GetVersionInfo file.FullName
if verInfo = null || verInfo.FileVersion = null then false else
if isNull verInfo || isNull verInfo.FileVersion then false else
let currentVersion = SemVer.Parse verInfo.FileVersion
currentVersion < latest

/// Downloads the latest version of the given files to the destination dir
let private downloadLatestVersionOf files destDir =
use client = createWebClient(Constants.GithubUrl, None)
use client = createWebClient(Constants.GitHubUrl, None)

trial {
let! data = client |> downloadStringSync Constants.GithubReleasesUrl
let! latestVersion = getLatestVersionFromJson data
let! data = client |> downloadStringSync Constants.GitHubReleasesUrl
let! latestVersion = getLatestVersionFromJson(data,0)

let files =
files
Expand All @@ -57,13 +60,13 @@ let private downloadLatestVersionOf files destDir =
}

/// Downloads the latest version of the paket.bootstrapper to the .paket dir
let downloadLatestBootstrapper environment =
let downloadLatestBootstrapper environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, Constants.PaketFolderName)

downloadLatestVersionOf [Constants.BootstrapperFileName] exeDir

/// Downloads the latest version of the paket.bootstrapper and paket.targets to the .paket dir
let downloadLatestBootstrapperAndTargets environment =
let downloadLatestBootstrapperAndTargets environment =
let exeDir = Path.Combine(environment.RootDirectory.FullName, Constants.PaketFolderName)

downloadLatestVersionOf [Constants.TargetsFileName; Constants.BootstrapperFileName] exeDir

0 comments on commit d1ce647

Please sign in to comment.