-
Notifications
You must be signed in to change notification settings - Fork 527
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 paket exe to cwd on init #853
Changes from 5 commits
05cc6b6
bfde173
9e6990b
ad6442b
4c1ae17
366c211
2265282
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module Paket.Releases | ||
|
||
open System.IO | ||
open System.Diagnostics | ||
open Logging | ||
open System | ||
open Chessie.ErrorHandling | ||
open Paket.Domain | ||
|
||
let private getLatestVersionFromJson (data : string) = | ||
try | ||
let start = data.IndexOf("tag_name") + 11 | ||
let end' = data.IndexOf("\"", start) | ||
(data.Substring(start, end' - start)) |> SemVer.Parse |> ok | ||
with _ -> | ||
fail ReleasesJsonParseError | ||
|
||
let private download version (file:FileInfo) client = | ||
trial { | ||
tracen (sprintf "%A" file) | ||
|
||
do! createDir(file.DirectoryName) | ||
let url = sprintf "https://github.com/fsprojects/Paket/releases/download/%s/%s" (string version) file.Name | ||
|
||
do! downloadFileSync url file.FullName client | ||
} | ||
|
||
let private existsNotOrIsNewer (file:FileInfo) latest = | ||
if (not <| file.Exists) then true | ||
else | ||
let verInfo = FileVersionInfo.GetVersionInfo file.FullName | ||
let currentVersion = SemVer.Parse verInfo.FileVersion | ||
currentVersion < latest | ||
|
||
let downloadLatestVersionOf files destDir = | ||
let releasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please move this into the Constants module |
||
use client = createWebClient("https://github.com",None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also Constants |
||
|
||
trial { | ||
let! data = client |> downloadStringSync releasesUrl | ||
let! latestVersion = getLatestVersionFromJson data | ||
|
||
let! downloads = | ||
files | ||
|> List.map (fun file -> FileInfo(Path.Combine(destDir, file))) | ||
|> List.filter (fun file -> existsNotOrIsNewer file latestVersion) | ||
|> List.map (fun file -> download latestVersion file client) | ||
|> collect | ||
|
||
ignore downloads | ||
} | ||
|
||
let downloadLatestBootstrapper environment = | ||
let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket") | ||
|
||
downloadLatestVersionOf ["paket.bootstrapper.exe"] exeDir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is all refactored from existing code, but please put all these constants into the Constants module |
||
|
||
let downloadLatestBootstrapperAndTargets environment = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather inline this and above functions - they seem pretty straightforward |
||
let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket") | ||
|
||
downloadLatestVersionOf ["paket.targets"; "paket.bootstrapper.exe"] exeDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesNotExist
?