Skip to content
This repository
Browse code

Fix testflight

  • Loading branch information...
commit 5b3c3868d4edd499f13281feb50ff4ed1bbc936b 1 parent e63526e
Ray Yamamoto Hilton authored
2  lib/xcode/builder.rb
... ... @@ -1,7 +1,7 @@
1 1 require 'xcode/shell'
2 2 require 'xcode/provisioning_profile'
3 3 require 'xcode/test/parsers/ocunit_parser.rb'
4   -require 'xcode/testflight'
  4 +require 'xcode/deploy/testflight'
5 5 require 'xcode/builder/base_builder.rb'
6 6 require 'xcode/builder/project_target_config_builder.rb'
7 7 require 'xcode/builder/scheme_builder.rb'
12 lib/xcode/builder/base_builder.rb
@@ -78,11 +78,19 @@ def test(options = {:sdk => 'iphonesimulator'}) #, :parser => :OCUnit })
78 78 report
79 79 end
80 80
  81 + #
  82 + # Upload to testflight
  83 + #
  84 + # The testflight object is yielded so further configuration can be performed before uploading
  85 + #
  86 + # @param api_token the API token for your testflight account
  87 + # @param team_token the token for the team you want to deploy to
  88 + #
81 89 def testflight(api_token, team_token)
82 90 raise "Can't find #{ipa_path}, do you need to call builder.package?" unless File.exists? ipa_path
83   - raise "Can't fins #{dsym_zip_path}, do you need to call builder.package?" unless File.exists? dsym_zip_path
  91 + raise "Can't find #{dsym_zip_path}, do you need to call builder.package?" unless File.exists? dsym_zip_path
84 92
85   - testflight = Xcode::Testflight.new(api_token, team_token)
  93 + testflight = Xcode::Deploy::Testflight.new(api_token, team_token)
86 94 yield(testflight) if block_given?
87 95 testflight.upload(ipa_path, dsym_zip_path)
88 96 end
60 lib/xcode/deploy/testflight.rb
... ... @@ -0,0 +1,60 @@
  1 +require 'rest-client'
  2 +require 'json'
  3 +
  4 +module Xcode
  5 + module Deploy
  6 + class Testflight
  7 + attr_accessor :api_token, :team_token, :notify, :proxy, :notes, :lists
  8 +
  9 + def initialize(api_token, team_token)
  10 + @api_token = api_token
  11 + @team_token = team_token
  12 + @notify = true
  13 + @notes = nil
  14 + @lists = []
  15 + @proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
  16 + end
  17 +
  18 + def upload(ipa_path, dsymzip_path=nil)
  19 + puts "Uploading to Testflight..."
  20 +
  21 + # RestClient.proxy = @proxy || ENV['http_proxy'] || ENV['HTTP_PROXY']
  22 + # RestClient.log = '/tmp/restclient.log'
  23 + #
  24 + # response = RestClient.post('http://testflightapp.com/api/builds.json',
  25 + # :file => File.new(ipa_path),
  26 + # :dsym => File.new(dsymzip_path),
  27 + # :api_token => @api_token,
  28 + # :team_token => @team_token,
  29 + # :notes => @notes,
  30 + # :notify => @notify ? 'True' : 'False',
  31 + # :distribution_lists => @lists.join(',')
  32 + # )
  33 + #
  34 + # json = JSON.parse(response)
  35 + # puts " + Done, got: #{json.inspect}"
  36 + # json
  37 +
  38 + cmd = Xcode::Shell::Command.new 'curl'
  39 + cmd << "--proxy #{@proxy}" unless @proxy.nil? or @proxy==''
  40 + cmd << "-X POST http://testflightapp.com/api/builds.json"
  41 + cmd << "-F file=@\"#{ipa_path}\""
  42 + cmd << "-F dsym=@\"#{dsymzip_path}\"" unless dsymzip_path.nil?
  43 + cmd << "-F api_token='#{@api_token}'"
  44 + cmd << "-F team_token='#{@team_token}'"
  45 + cmd << "-F notes=\"#{@notes}\"" unless @notes.nil?
  46 + cmd << "-F notify=#{@notify ? 'True' : 'False'}"
  47 + cmd << "-F distribution_lists='#{@lists.join(',')}'" unless @lists.count==0
  48 +
  49 + response = Xcode::Shell.execute(cmd)
  50 +
  51 + json = JSON.parse(response.join(''))
  52 + puts " + Done, got: #{json.inspect}"
  53 +
  54 + yield(json) if block_given?
  55 +
  56 + json
  57 + end
  58 + end
  59 + end
  60 +end
4 lib/xcode/shell.rb
@@ -5,9 +5,9 @@ module Shell
5 5
6 6 class ExecutionError < StandardError; end
7 7
8   - def self.execute(bits, show_output=true)
  8 + def self.execute(cmd, show_output=true)
9 9 out = []
10   - cmd = bits.is_a?(Xcode::Shell::Command) ? bits.to_s : bits
  10 + cmd = cmd.to_s
11 11
12 12 puts "EXECUTE: #{cmd}"
13 13 IO.popen (cmd) do |f|
2  lib/xcode/shell/command.rb
@@ -3,7 +3,7 @@
3 3 module Xcode
4 4 module Shell
5 5 class Command
6   - attr_accessor :env
  6 + attr_accessor :env, :cmd, :args
7 7
8 8 def initialize(cmd, environment={})
9 9 @cmd = cmd
59 lib/xcode/testflight.rb
... ... @@ -1,59 +0,0 @@
1   -require 'rest-client'
2   -require 'json'
3   -
4   -module Xcode
5   - class Testflight
6   - attr_accessor :api_token, :team_token, :notify, :proxy, :notes, :lists
7   -
8   - def initialize(api_token, team_token)
9   - @api_token = api_token
10   - @team_token = team_token
11   - @notify = true
12   - @notes = nil
13   - @lists = []
14   - @proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
15   - end
16   -
17   - def upload(ipa_path, dsymzip_path=nil)
18   - puts "Uploading to Testflight..."
19   -
20   - # RestClient.proxy = @proxy || ENV['http_proxy'] || ENV['HTTP_PROXY']
21   - # RestClient.log = '/tmp/restclient.log'
22   - #
23   - # response = RestClient.post('http://testflightapp.com/api/builds.json',
24   - # :file => File.new(ipa_path),
25   - # :dsym => File.new(dsymzip_path),
26   - # :api_token => @api_token,
27   - # :team_token => @team_token,
28   - # :notes => @notes,
29   - # :notify => @notify ? 'True' : 'False',
30   - # :distribution_lists => @lists.join(',')
31   - # )
32   - #
33   - # json = JSON.parse(response)
34   - # puts " + Done, got: #{json.inspect}"
35   - # json
36   -
37   - cmd = []
38   - cmd << 'curl'
39   - cmd << "--proxy #{@proxy}" unless @proxy.nil? or @proxy==''
40   - cmd << "-X POST http://testflightapp.com/api/builds.json"
41   - cmd << "-F file=@\"#{ipa_path}\""
42   - cmd << "-F dsym=@\"#{dsymzip_path}\"" unless dsymzip_path.nil?
43   - cmd << "-F api_token='#{@api_token}'"
44   - cmd << "-F team_token='#{@team_token}'"
45   - cmd << "-F notes=\"#{@notes}\"" unless @notes.nil?
46   - cmd << "-F notify=#{@notify ? 'True' : 'False'}"
47   - cmd << "-F distribution_lists='#{@lists.join(',')}'" unless @lists.count==0
48   -
49   - response = Xcode::Shell.execute(cmd)
50   -
51   - json = JSON.parse(response.join(''))
52   - puts " + Done, got: #{json.inspect}"
53   -
54   - yield(json) if block_given?
55   -
56   - json
57   - end
58   - end
59   -end
29 spec/builder_spec.rb
@@ -46,30 +46,31 @@
46 46
47 47 describe "#testflight" do
48 48
49   - let(:testflight_parameters) do
50   - ['curl',
51   - "--proxy http://proxyhost:8080",
52   - "-X POST http://testflightapp.com/api/builds.json",
53   - "-F file=@\"#{subject.ipa_path}\"",
54   - "-F dsym=@\"#{subject.dsym_zip_path}\"",
55   - "-F api_token='api_token'",
56   - "-F team_token='team_token'",
57   - "-F notes=\"some notes\"",
58   - "-F notify=True",
59   - "-F distribution_lists='List1,List2'"]
60   - end
  49 + # let(:testflight_parameters) do
  50 + # ['curl',
  51 + # "--proxy http://proxyhost:8080",
  52 + # "-X POST http://testflightapp.com/api/builds.json",
  53 + # "-F file=@\"#{subject.ipa_path}\"",
  54 + # "-F dsym=@\"#{subject.dsym_zip_path}\"",
  55 + # "-F api_token='api_token'",
  56 + # "-F team_token='team_token'",
  57 + # "-F notes=\"some notes\"",
  58 + # "-F notify=True",
  59 + # "-F distribution_lists='List1,List2'"]
  60 + # end
61 61
62 62 it "should upload ipa and dsym to testflight" do
63 63 subject.build.package
64 64
65   - Xcode::Shell.should_receive(:execute).with(testflight_parameters).and_return(['{}'])
66   - subject.testflight("api_token", "team_token") do |tf|
  65 + result = subject.testflight("api_token", "team_token") do |tf|
  66 + tf.should_receive(:upload).with(subject.ipa_path, subject.dsym_zip_path).and_return('result')
67 67 tf.proxy = "http://proxyhost:8080"
68 68 tf.notes = "some notes"
69 69 tf.lists << "List1"
70 70 tf.lists << "List2"
71 71 end
72 72
  73 + result.should == 'result'
73 74 end
74 75 end
75 76
27 spec/deploy_testflight_spec.rb
... ... @@ -0,0 +1,27 @@
  1 +require_relative 'spec_helper'
  2 +
  3 +describe Xcode::Deploy::Testflight do
  4 +
  5 + let(:testflight) { Xcode::Deploy::Testflight.new 'api token', 'team token' }
  6 +
  7 + it "should be configured with api and team token" do
  8 + testflight.api_token.should == 'api token'
  9 + testflight.team_token.should == 'team token'
  10 + end
  11 +
  12 + it "should call curl with correct bulld paths" do
  13 + Xcode::Shell.should_receive(:execute) do |arg|
  14 + arg.is_a? Xcode::Shell::Command
  15 + arg.cmd.should == 'curl'
  16 + arg.args.should include('-F file=@"ipa path"')
  17 + arg.args.should include('-F dsym=@"dsym path"')
  18 + arg.args.should include("-F api_token='api token'")
  19 + arg.args.should include("-F team_token='team token'")
  20 +
  21 + ['{"response":"ok"}']
  22 + end
  23 + response = testflight.upload('ipa path', 'dsym path')
  24 + response['response'].should == 'ok'
  25 + end
  26 +
  27 +end

0 comments on commit 5b3c386

Please sign in to comment.
Something went wrong with that request. Please try again.