zotplus-rakehelper 0.0.122 → 0.0.123

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9f2d86e1e5b55e44fd951fe1f8bdda1108087be
4
- data.tar.gz: f451f0c2abcc6fd95f41b36d01494986319c4b3f
3
+ metadata.gz: d79a10b7ceca2fcbedb79a6364e2834590453137
4
+ data.tar.gz: a80d8118d6acc6c67ae4011a1fb25391b8b1260e
5
5
  SHA512:
6
- metadata.gz: a50573aa51df43ab69cc136c95589f4d72eeb0ba2882e236e6b7af4fe30425362366a13950411b638cd8a0ab6f5eec8cbcca0e1bb198db167af5559206562826
7
- data.tar.gz: c1ca65e02e44b338b4e79a69c21f622d3fbe20986ea15739de42a6669c81aed74aa81a435ad393ac5d0459c0cb754602d8c91fa1cda12bb29bb1dc7741cd1dc5
6
+ metadata.gz: f21019349c558b9b71027a6c84a0250f640129d5d0c2e62f4932b8b7d42875378286c78c826359b23fb6818db693a25baa522c14497105dbc71330cca65a4489
7
+ data.tar.gz: 4c5165a59f052f829ea1d16f54148e064a25e0ed592ae129a5ce1125e9be6d33e2a7723301b20303ed7f07558fba05a01ac12ea32b4aa7979fc7470e28a17b65
@@ -1,5 +1,5 @@
1
1
  module ZotPlus
2
2
  class RakeHelper
3
- VERSION = "0.0.122"
3
+ VERSION = "0.0.123"
4
4
  end
5
5
  end
@@ -105,7 +105,64 @@ file GR do
105
105
  sh "tar xjf #{tmp} -C bin --strip-components 3"
106
106
  end
107
107
 
108
- task :deploy => [XPI, GR] do
108
+ file SIGNED => XPI do
109
+ token = lambda {
110
+ payload = {
111
+ jti: SecureRandom.base64,
112
+ iss: ENV['MOZJWTissuer'],
113
+ iat: Time.now.utc.to_i,
114
+ exp: Time.now.utc.to_i + 60,
115
+ }
116
+ return JWT.encode(payload, ENV['MOZJWTsecret'], 'HS256')
117
+ }
118
+
119
+ duration = lambda{|secs|
120
+ secs = secs.to_i
121
+ mins = secs / 60
122
+ hours = mins / 60
123
+ days = hours / 24
124
+
125
+ if days > 0
126
+ "#{days} days and #{hours % 24} hours"
127
+ elsif hours > 0
128
+ "#{hours} hours and #{mins % 60} minutes"
129
+ elsif mins > 0
130
+ "#{mins} minutes and #{secs % 60} seconds"
131
+ elsif secs >= 0
132
+ "#{secs} seconds"
133
+ end
134
+ }
135
+
136
+ url = "https://addons.mozilla.org/api/v3/addons/#{ID}/versions/#{RELEASE}/"
137
+
138
+ begin
139
+ puts "Submit #{XPI} to #{url} for signing"
140
+ RestClient.put(url, {upload: File.new(XPI)}, { 'Authorization' => "JWT #{token.call}", 'Content-Type' => 'multipart/form-data' })
141
+ rescue => RestClient::Conflict
142
+ puts "#{XPI} already signed"
143
+ end
144
+
145
+ status = {}
146
+ wait = Time.now.to_i
147
+ (1..100).each{|attempt|
148
+ sleep 10
149
+ status = JSON.parse(RestClient.get(url, { 'Authorization' => "JWT #{token.call}"} ).to_s)
150
+ files = (status['files'] || []).length
151
+ signed = (files > 0 ? status['files'][0]['signed'] : false)
152
+ puts "attempt #{attempt} after #{duration.call(Time.now.to_i - wait)}, #{files} files, signed: #{signed}"
153
+ break if signed
154
+ }
155
+
156
+ raise "Unexpected response: #{status['files'].inspect}" if !status['files'] || status['files'].length != 1 || !status['files'][0]['download_url']
157
+ raise "Not signed: #{status['files'][0].inspect}" unless status['files'][0]['signed']
158
+
159
+ puts "\ngetting signed XPI from #{status['files'][0]['download_url']}"
160
+ File.open(SIGNED, 'wb'){|f|
161
+ f.write(RestClient.get(status['files'][0]['download_url'], { 'Authorization' => "JWT #{token.call}"} ).body)
162
+ }
163
+ end
164
+
165
+ task :deploy => [SIGNED, GR] do
109
166
  throw "GITHUB_TOKEN not set" unless ENV['GITHUB_TOKEN']
110
167
  checkin = `git log -n 1 --pretty=oneline`.strip
111
168
 
@@ -113,8 +170,6 @@ task :deploy => [XPI, GR] do
113
170
  sha1 = keys.detect{|key| key != ''}
114
171
  throw "No SHA1 found in #{keys.inspect}" unless sha1
115
172
 
116
- xpi = File.exists?(SIGNED) ? SIGNED : XPI
117
-
118
173
  release = "#{sha1} release: #{XPI}"
119
174
  STDERR.puts "#{RELEASE}"
120
175
  STDERR.puts " checkin=#{checkin}"
@@ -123,7 +178,7 @@ task :deploy => [XPI, GR] do
123
178
  STDERR.puts "Deploying #{RELEASE} (#{sha1})"
124
179
 
125
180
  sh "#{GR} release --user ZotPlus --repo zotero-#{EXTENSION} --tag #{RELEASE} --name 'v#{RELEASE}'"
126
- sh "#{GR} upload --user ZotPlus --repo zotero-#{EXTENSION} --tag #{RELEASE} --name '#{XPI}' --file '#{xpi}'"
181
+ sh "#{GR} upload --user ZotPlus --repo zotero-#{EXTENSION} --tag #{RELEASE} --name '#{XPI}' --file '#{SIGNED}'"
127
182
 
128
183
  open("www/_includes/#{EXTENSION}-version.html", 'w'){|f| f.write(RELEASE) }
129
184
  Dir.chdir('www'){
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zotplus-rakehelper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.122
4
+ version: 0.0.123
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emiliano Heyns