-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy
More file actions
executable file
·109 lines (81 loc) · 2.82 KB
/
deploy
File metadata and controls
executable file
·109 lines (81 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env ruby
require "rubygems"
require "json"
require 'uri'
require 'net/http'
require 'net/https'
def die_with msg
puts msg; exit
end
def hc_notify config, msg
hc_room_id, hc_api_key = config["hc_room_id"], config["hc_api_key"]
args = {
:auth_token => hc_api_key,
:format => "format",
:room_id=> hc_room_id,
:from => "fika-deployer",
:color => "green",
:message => msg
}
uri = URI.parse("https://api.hipchat.com/v1/rooms/message")
uri.query = URI.encode_www_form(args)
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = https.request(request)
JSON.parse(response.body)
end
def hockey_upload config, package, os, details={}
hockeyapp_token = config["hockeyapp_token"]
sha = last_sha.strip
request = %x( curl -s -F "status=2" \
-F "notify=1" \
-F "notes=#{details['release_notes'].strip}" \
-F "notes_type=0" \
-F "release_type=0" \
-F "tags=#{details['tags'].strip}" \
-F "commit_sha=#{sha}" \
-F "ipa=@#{package}" \
-H "X-HockeyAppToken: #{hockeyapp_token}" \
https://rink.hockeyapp.net/api/2/apps/upload
).strip
if not(request.nil?)
return JSON.parse(request) rescue nil
end
nil
end
def last_sha
%x( git rev-list --max-count=1 HEAD ).strip
end
# Make sure that packages are valid
package = ARGV.first
die_with("Only *.apk or *.ipa are allowed package.") unless package =~ /apk|ipa/
# Determine OS
os = {'apk' => "android", 'ipa' => "ios"}[Regexp.last_match.to_s]
die_with("Only android or ios packages accepted") if os.nil?
# Determine version
version = ARGV[1].match(/\d+\.\d+\.\d+/).to_a.first rescue nil
die_with("Version must be in format number.number.number") if version.nil?
# Load configuration
file_path = "#{ENV['HOME']}/.fika_developer"
die_with("Missing .fika_developer configuration.") unless File.exists?(file_path)
file = File.new file_path,"r"
raw_string = ""
file.each { |line| raw_string += line; }
file.close
config = JSON.load(raw_string) rescue nil
die_with("JSON parsing failed") if config.nil?
release_notes = ARGV[2] rescue nil
die_with("3rd parameter must be release note!") if release_notes.nil?
tags = ARGV[3] rescue nil
die_with("4th parameter must have tags!") if tags.nil?
upload = hockey_upload config, package, os, { "tags" => tags, "release_notes" => release_notes }
die_with("Upload to HockeyApp failed!") if upload.nil?
config_url = upload["config_url"]
icon = {
"android"=>"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/android.png",
"ios"=>"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/beer.png"}[os.to_s]
hc_notify config, "New version for <img src=\"#{icon}\"/> was deployed. Version: #{version} Tags: #{tags}
\n URL: <a href=\"#{config_url}\">#{config_url}</a>"
puts "Done."