Skip to content

Commit

Permalink
Merge pull request #656 from ololabs/hockey
Browse files Browse the repository at this point in the history
Create a helper for uploading mobile apps to HockeyApp.
  • Loading branch information
forki committed Feb 19, 2015
2 parents 412ed0d + a838693 commit f5ca507
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 6 deletions.
3 changes: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ nuget FsCheck.Xunit
nuget Machine.Specifications.Should
nuget Machine.Specifications.Runner.Console
nuget Nancy.Testing
nuget xunit.extensions
nuget xunit.extensions
nuget Newtonsoft.Json
73 changes: 69 additions & 4 deletions src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{13d56521-772a-41db-9772-1da1a4aa8e3a}</ProjectGuid>
<ProjectGuid>{13D56521-772A-41DB-9772-1DA1A4AA8E3A}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>FakeLib</RootNamespace>
<AssemblyName>FakeLib</AssemblyName>
Expand All @@ -23,7 +21,8 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>
</DocumentationFile>
<OtherFlags />
<OtherFlags>
</OtherFlags>
<StartWorkingDirectory>
</StartWorkingDirectory>
</PropertyGroup>
Expand Down Expand Up @@ -149,6 +148,7 @@
<Compile Include="XDTHelper.fs" />
<Compile Include="AzureWebJobs.fs" />
<None Include="app.config" />
<Compile Include="HockeyAppHelper.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib">
Expand Down Expand Up @@ -363,6 +363,71 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETCore'">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json\lib\netcore45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v3.5'">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v2.0' Or $(TargetFrameworkVersion) == 'v3.0')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json\lib\net20\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="($(TargetFrameworkIdentifier) == 'Silverlight' And $(TargetFrameworkVersion) == 'v5.0') Or ($(TargetFrameworkProfile) == 'Profile5') Or ($(TargetFrameworkProfile) == 'Profile6') Or ($(TargetFrameworkProfile) == 'Profile14') Or ($(TargetFrameworkProfile) == 'Profile19') Or ($(TargetFrameworkProfile) == 'Profile24') Or ($(TargetFrameworkProfile) == 'Profile37') Or ($(TargetFrameworkProfile) == 'Profile42') Or ($(TargetFrameworkProfile) == 'Profile47') Or ($(TargetFrameworkProfile) == 'Profile92') Or ($(TargetFrameworkProfile) == 'Profile102') Or ($(TargetFrameworkProfile) == 'Profile136') Or ($(TargetFrameworkProfile) == 'Profile147') Or ($(TargetFrameworkProfile) == 'Profile158') Or ($(TargetFrameworkProfile) == 'Profile225') Or ($(TargetFrameworkProfile) == 'Profile240') Or ($(TargetFrameworkProfile) == 'Profile255') Or ($(TargetFrameworkProfile) == 'Profile328') Or ($(TargetFrameworkProfile) == 'Profile336') Or ($(TargetFrameworkProfile) == 'Profile344')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
<When Condition="($(TargetFrameworkIdentifier) == 'WindowsPhoneApp') Or ($(TargetFrameworkIdentifier) == 'WindowsPhone' And ($(TargetFrameworkVersion) == 'v8.0' Or $(TargetFrameworkVersion) == 'v8.1')) Or ($(TargetFrameworkProfile) == 'Profile7') Or ($(TargetFrameworkProfile) == 'Profile31') Or ($(TargetFrameworkProfile) == 'Profile32') Or ($(TargetFrameworkProfile) == 'Profile44') Or ($(TargetFrameworkProfile) == 'Profile49') Or ($(TargetFrameworkProfile) == 'Profile78') Or ($(TargetFrameworkProfile) == 'Profile84') Or ($(TargetFrameworkProfile) == 'Profile111') Or ($(TargetFrameworkProfile) == 'Profile151') Or ($(TargetFrameworkProfile) == 'Profile157') Or ($(TargetFrameworkProfile) == 'Profile259')">
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\packages\Newtonsoft.Json\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch')">
<ItemGroup>
Expand Down
101 changes: 101 additions & 0 deletions src/app/FakeLib/HockeyAppHelper.fs
Original file line number Diff line number Diff line change
@@ -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

[<JsonProperty("Bundle_Identifier")>]
BundleIdentifier: string

[<JsonProperty("Public_Identifier")>]
PublicIdentifier: string

[<JsonProperty("Device_Family")>]
DeviceFamily: string

[<JsonProperty("Minimum_OS_Version")>]
MinimumOSVersion: string

[<JsonProperty("Release_Type")>]
ReleaseType : ReleaseType

Platform : string

Status : int

[<JsonProperty("Config_Url")>]
ConfigUrl : string

[<JsonProperty("Public_Url")>]
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<HockeyResponse>(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)
3 changes: 2 additions & 1 deletion src/app/FakeLib/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ FSharp.Core
FSharp.Compiler.Service
Mono.Web.Xdt
Mono.Cecil
Nuget.Core
Nuget.Core
Newtonsoft.Json

0 comments on commit f5ca507

Please sign in to comment.