Skip to content
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

Create a helper for uploading mobile apps to HockeyApp. #656

Merged
merged 1 commit into from
Feb 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was so happy that I got rid of NewtonSoft.Json ;-)

Seems it coming back over and over again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we have to fix the NuGet task in FAKE's build.fsx to include the dll.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, we asked whether you wanted a different serializer up front! Keeping Json.Net makes sense, though, given that it's included elsewhere. =)

I'm actually able to build from both mac and windows without any additional modifications. This might be a side effect of NewtonSoft.Json being included in the Deploy and Deploy.Lib projects... Or I might be totally misunderstanding your comment!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I forgot about that ;-)
All is well.

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