Skip to content
This repository has been archived by the owner on Jun 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #244 from yageek/feature/testfairy
Browse files Browse the repository at this point in the history
Add test fairy distribution
  • Loading branch information
mattt committed Apr 17, 2015
2 parents e15c3f0 + 8b7c58c commit e8d3625
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -9,6 +9,7 @@ Create `.ipa` files and distribute them from the command line, using any of the
- [Fly It Remotely (FIR.im)](http://fir.im)
- [蒲公英 (PGYER)](http://www.pgyer.com)
- [Amazon S3](http://aws.amazon.com/s3/)
- [TestFairy](https://www.testfairy.com/)
- FTP / SFTP

Less cumbersome than clicking around in Xcode, and less hassle than rolling your own build script, Shenzhen radically improves the process of getting new builds out to testers and enterprises.
Expand Down Expand Up @@ -55,6 +56,7 @@ Build and distribute iOS apps (.ipa files)
distribute:pgyer Distribute an .ipa file over Pgyer
distribute:ftp Distribute an .ipa file over FTP
distribute:s3 Distribute an .ipa file over Amazon S3
distribute:testfairy Distribute an .ipa file over TestFairy
info Show mobile provisioning information about an .ipa file
help Display global or [command] help documentation.
Expand All @@ -80,6 +82,14 @@ $ ipa distribute:hockeyapp -a API_TOKEN

> Shenzhen will load credentials from the environment variable `HOCKEYAPP_API_TOKEN` unless otherwise specified.
#### TestFairy Distribution

```
$ ipa distribute:testfairy -a API_KEY
```

> Shenzhen will load credentials from the environment variable `TESTFAIRY_API_KEY` unless otherwise specified.
#### Crashlytics Beta Distribution

```
Expand Down
1 change: 1 addition & 0 deletions lib/shenzhen/commands.rb
@@ -1,6 +1,7 @@
$:.push File.expand_path('../', __FILE__)

require 'plugins/hockeyapp'
require 'plugins/testfairy'
require 'plugins/deploygate'
require 'plugins/itunesconnect'
require 'plugins/ftp'
Expand Down
99 changes: 99 additions & 0 deletions lib/shenzhen/plugins/testfairy.rb
@@ -0,0 +1,99 @@
require 'json'
require 'openssl'
require 'faraday'
require 'faraday_middleware'

module Shenzhen::Plugins
module TestFairy
class Client
HOSTNAME = 'app.testfairy.com'

def initialize(api_key)
@api_key = api_key
@connection = Faraday.new(:url => "https://#{HOSTNAME}") do |builder|
builder.request :multipart
builder.request :url_encoded
builder.response :json, :content_type => /\bjson$/
builder.use FaradayMiddleware::FollowRedirects
builder.adapter :net_http
end
end

def upload_build(ipa, options)
options[:file] = Faraday::UploadIO.new(ipa, 'application/octet-stream') if ipa and File.exist?(ipa)

if symbols_file = options.delete(:symbols_file)
options[:symbols_file] = Faraday::UploadIO.new(symbols_file, 'application/octet-stream')
end

@connection.post do |req|
req.url("/api/upload/")
req.body = options
end.on_complete do |env|
yield env[:status], env[:body] if block_given?
end
end
end
end
end

command :'distribute:testfairy' do |c|
c.syntax = "ipa distribute:testfairy [options]"
c.summary = "Distribute an .ipa file over TestFairy"
c.description = ""
c.option '-f', '--file FILE', ".ipa file for the build"
c.option '-d', '--dsym FILE', "zipped .dsym package for the build"
c.option '-a', '--key KEY', "API Key. Available at https://app.testfairy.com/settings for details."
c.option '-c', '--comment COMMENT', "Comment for the build"
c.option '--tester-groups GROUPS', 'Comma-separated list of tester groups to be notified on the new build. Or "all" to notify all testers.'
c.option '--metrics METRICS', "Comma-separated list of metrics to record"
c.option '--max-duration DURATION', 'Maximum session recording length, eg 20m or 1h. Default is "10m". Maximum 24h.'
c.option '--video ACTIVE', 'Video recording settings "on", "off" or "wifi" for recording video only when wifi is available. Default is "on".'
c.option '--video-quality QUALITY', 'Video quality settings, "high", "medium" or "low". Default is "high".'
c.option '--video-rate RATE', 'Video rate recording in frames per second, default is "1.0".'
c.option '--icon-watermark ADD', 'Add a small watermark to app icon. Default is "off".'

c.action do |args, options|
determine_file! unless @file = options.file
say_warning "Missing or unspecified .ipa file" unless @file and File.exist?(@file)

determine_dsym! unless @dsym = options.dsym
say_warning "Specified dSYM.zip file doesn't exist" if @dsym and !File.exist?(@dsym)

determine_testfairy_api_key! unless @api_key = options.key || ENV['TESTFAIRY_API_KEY']
say_error "Missing API Key" and abort unless @api_key

determine_notes! unless @comment = options.comment
say_error "Missing release comment" and abort unless @comment

parameters = {}
# Required
parameters[:api_key] = @api_key
# Optional
parameters[:comment] = @comment
parameters[:symbols_file] = @dsym if @dsym
parameters[:testers_groups] = options.testers_groups if options.testers_groups
parameters[:'max-duration'] = options.max_duration if options.max_duration
parameters[:video] = options.video if options.video
parameters[:'video-quality'] = options.video_quality if options.video_quality
parameters[:'video-rate'] = options.video_rate if options.video_rate
parameters[:'icon-watermark'] = options.icon_watermark if options.icon_watermark
parameters[:metrics] = options.metrics if options.metrics


client = Shenzhen::Plugins::TestFairy::Client.new(@api_key)
response = client.upload_build(@file, parameters)
case response.status
when 200...300
say_ok "Build successfully uploaded to TestFairy"
else
say_error "Error uploading to TestFairy: #{response.body}"
end
end

private

def determine_testfairy_api_key!
@api_key ||= ask "API Key:"
end
end

0 comments on commit e8d3625

Please sign in to comment.