From a838693c9b50a47a64b63b8a7b7314410b56fb83 Mon Sep 17 00:00:00 2001 From: Bret Koppel Date: Mon, 26 Jan 2015 13:41:46 -0500 Subject: [PATCH] Create a helper for uploading mobile apps to HockeyApp. --- paket.dependencies | 3 +- src/app/FakeLib/FakeLib.fsproj | 73 +++++++++++++++++++-- src/app/FakeLib/HockeyAppHelper.fs | 101 +++++++++++++++++++++++++++++ src/app/FakeLib/paket.references | 3 +- 4 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 src/app/FakeLib/HockeyAppHelper.fs diff --git a/paket.dependencies b/paket.dependencies index 7961699d98c..bbe7f03225c 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -31,4 +31,5 @@ nuget FsCheck.Xunit nuget Machine.Specifications.Should nuget Machine.Specifications.Runner.Console nuget Nancy.Testing -nuget xunit.extensions \ No newline at end of file +nuget xunit.extensions +nuget Newtonsoft.Json \ No newline at end of file diff --git a/src/app/FakeLib/FakeLib.fsproj b/src/app/FakeLib/FakeLib.fsproj index c74b9f8a1d0..6199bd6b5a9 100644 --- a/src/app/FakeLib/FakeLib.fsproj +++ b/src/app/FakeLib/FakeLib.fsproj @@ -4,9 +4,7 @@ Debug AnyCPU - 8.0.30703 - 2.0 - {13d56521-772a-41db-9772-1da1a4aa8e3a} + {13D56521-772A-41DB-9772-1DA1A4AA8E3A} Library FakeLib FakeLib @@ -23,7 +21,8 @@ 3 - + + @@ -149,6 +148,7 @@ + @@ -363,6 +363,71 @@ + + + + + ..\..\..\packages\Newtonsoft.Json\lib\netcore45\Newtonsoft.Json.dll + True + True + + + + + + + ..\..\..\packages\Newtonsoft.Json\lib\net35\Newtonsoft.Json.dll + True + True + + + + + + + ..\..\..\packages\Newtonsoft.Json\lib\net20\Newtonsoft.Json.dll + True + True + + + + + + + ..\..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll + True + True + + + + + + + ..\..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll + True + True + + + + + + + ..\..\..\packages\Newtonsoft.Json\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll + True + True + + + + + + + ..\..\..\packages\Newtonsoft.Json\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Newtonsoft.Json.dll + True + True + + + + diff --git a/src/app/FakeLib/HockeyAppHelper.fs b/src/app/FakeLib/HockeyAppHelper.fs new file mode 100644 index 00000000000..0251ba23623 --- /dev/null +++ b/src/app/FakeLib/HockeyAppHelper.fs @@ -0,0 +1,101 @@ +/// Contains tasks to interact with [HockeyApp](http://hockeyapp.com) +module Fake.HockeyAppHelper + +open Microsoft.FSharp.Core +open System +open System.Collections.Generic +open System.IO +open System.Net +open System.Text +open Fake +open Newtonsoft.Json + +type ReleaseType = Beta = 0 | Store = 1 | Alpha = 2 | Enterprise = 3 + +type HockeyResponse = { + Title : string + + [] + BundleIdentifier: string + + [] + PublicIdentifier: string + + [] + DeviceFamily: string + + [] + MinimumOSVersion: string + + [] + ReleaseType : ReleaseType + + Platform : string + + Status : int + + [] + ConfigUrl : string + + [] + PublicUrl : string +} + +/// The HockeyApp parameter type +type HockeyAppUploadParams = { + /// (Required) API token + ApiToken: string + + /// (Required) file data for the build (.ipa or .apk) + File: string + + /// Release notes for the build + Notes: string + + /// set the release type of the app + ReleaseType: ReleaseType +} + +/// The default HockeyApp parameters +let HockeyAppUploadDefaults = { + ApiToken = String.Empty + File = String.Empty + Notes = String.Empty + ReleaseType = ReleaseType.Beta +} + +/// [omit] +let validateParams param = + if param.ApiToken = "" then failwith "You must provide your API token" + if param.File = "" then failwith "You must provide an app file to upload" + if not <| File.Exists param.File then + failwithf "No such file: %s" param.File + + param + +/// [omit] +let private toCurlArgs param = seq { + yield sprintf "-H \"X-HockeyAppToken:%s\"" param.ApiToken + yield sprintf "-F \"ipa=@%s\"" param.File + yield sprintf "-F \"notes=%s\"" param.Notes + yield sprintf "-F \"release_type=%i\"" (int param.ReleaseType) + yield "https://rink.hockeyapp.net/api/2/apps/upload" +} + +/// Uploads an app to HockeyApp +/// ## Parameters +/// - `setParams` - Function used to override the default parameters +let HockeyApp (setParams: HockeyAppUploadParams -> HockeyAppUploadParams) = + HockeyAppUploadDefaults + |> setParams + |> validateParams + |> toCurlArgs + |> fun args -> + ExecProcessAndReturnMessages (fun p -> + p.FileName <- "curl" + p.Arguments <- (String.concat " " args) + ) (TimeSpan.FromMinutes 2.) + |> fun response -> + match response.ExitCode with + | 0 -> JsonConvert.DeserializeObject(response.Messages.[0]) + | _ -> failwithf "Error while posting to HockeyApp.\r\nMessages: %s\r\nErrors: %s\r\n" (String.concat "; " response.Messages) (String.concat "; " response.Errors) \ No newline at end of file diff --git a/src/app/FakeLib/paket.references b/src/app/FakeLib/paket.references index dde140dbbd3..9a7ac9c8044 100644 --- a/src/app/FakeLib/paket.references +++ b/src/app/FakeLib/paket.references @@ -2,4 +2,5 @@ FSharp.Core FSharp.Compiler.Service Mono.Web.Xdt Mono.Cecil -Nuget.Core \ No newline at end of file +Nuget.Core +Newtonsoft.Json \ No newline at end of file