realityforge-buildr 1.5.11 → 1.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c0826c776391d6468649d0f23a920dcc9d8d30e7b3c4f5974f94129f466da59
4
- data.tar.gz: 755b410efcd9a99af87cf734c3acbfd8ec7dcab1234cb11ab43b65aef27df6a7
3
+ metadata.gz: 3774de57cc666c2148d221a1511f0a6ffa4ebbe1567443e121bc900e5e8ee4fb
4
+ data.tar.gz: 5d691cfc07a1ceafb83b750158314a51cbb1a810e9566434c1f9a85037f36296
5
5
  SHA512:
6
- metadata.gz: 8f511c67d096605305c86991a25b8e26ab92566e9a7ca0a12ac33fc4a98f36ac8a52d379ad4e264242714b528e93508bbe0b5763b174fb75955d147a842adf5f
7
- data.tar.gz: 9f1ce6d3788b0daae9d15b264a0f2a4c1ce7bd51c26d8630aaa53d9a24a1455708a05056eb3611f7269b1735c43abcd2b8f7a126a40ece2f497a40de8ee46de0
6
+ metadata.gz: fb053f6f9851fad7ffe939ad731da43883effac9be2ab8a53da8803e28c0946f104b4cf8d67dca17aef58f04c6da5465f4422927e0198fe5e88f92b9fcfbc6cf
7
+ data.tar.gz: 9031da8968321ec54d7acc645cb9f42693b255e9ffe143e07dfdc925e34e1c057e505178e7881316c89df9c718f9253fed85800cfd992a135c4e4bc634d79221
data/lib/buildr.rb CHANGED
@@ -50,6 +50,7 @@ require 'buildr/core/test'
50
50
  require 'buildr/java/commands'
51
51
  require 'buildr/core/transports'
52
52
  require 'buildr/java/pom'
53
+ require 'buildr/java/publish'
53
54
  require 'buildr/core/doc'
54
55
  require 'buildr/packaging/version_requirement'
55
56
  require 'buildr/packaging/artifact_namespace'
@@ -0,0 +1,262 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ require 'net/http'
16
+ require 'net/https'
17
+ require 'json'
18
+
19
+ module Buildr
20
+ class MavenCentral
21
+ class << self
22
+ def define_publish_tasks(options = {})
23
+ candidate_branches = options[:branches] || %w(master)
24
+ desc 'Publish release on maven central'
25
+ task 'mcrt:publish' do
26
+ project = options[:project] || Buildr.projects[0].root_project
27
+ profile_name = options[:profile_name] || (raise ':profile_name not specified when defining tasks')
28
+ username = options[:username] || (raise ':username name not specified when defining tasks')
29
+ password = options[:password] || ENV['MAVEN_CENTRAL_PASSWORD'] || (raise "Unable to locate environment variable with name 'MAVEN_CENTRAL_PASSWORD'")
30
+ MavenCentral.buildr_release(project, profile_name, username, password)
31
+ end
32
+
33
+ desc 'Publish release to maven central iff current HEAD is a tag'
34
+ task 'mcrt:publish_if_tagged' do
35
+ tag = MavenCentral.get_head_tag_if_any
36
+ if tag.nil?
37
+ puts 'Current HEAD is not a tag. Skipping publish step.'
38
+ else
39
+ puts "Current HEAD is a tag: #{tag}"
40
+ if MavenCentral.is_tag_on_candidate_branches?(tag, candidate_branches)
41
+ task('mcrt:publish').invoke
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def get_head_tag_if_any
48
+ version = `git describe --exact-match --tags 2>&1`
49
+ if 0 == $?.exitstatus && version =~ /^v[0-9]/ && (ENV['TRAVIS_BUILD_ID'].nil? || ENV['TRAVIS_TAG'].to_s != '')
50
+ version.strip
51
+ else
52
+ nil
53
+ end
54
+ end
55
+
56
+ def is_tag_on_branch?(tag, branch)
57
+ output = `git tag --merged #{branch} 2>&1`
58
+ tags = output.split
59
+ tags.include?(tag)
60
+ end
61
+
62
+ def is_tag_on_candidate_branches?(tag, branches)
63
+ sh 'git fetch origin'
64
+ branches.each do |branch|
65
+ if is_tag_on_branch?(tag, branch)
66
+ puts "Tag #{tag} is on branch: #{branch}"
67
+ return true
68
+ elsif is_tag_on_branch?(tag, "origin/#{branch}")
69
+ puts "Tag #{tag} is on branch: origin/#{branch}"
70
+ return true
71
+ else
72
+ puts "Tag #{tag} is not on branches: #{branch} or origin/#{branch}"
73
+ end
74
+ end
75
+ false
76
+ end
77
+
78
+ def buildr_release(project, profile_name, username, password)
79
+ release_to_url = Buildr.repositories.release_to[:url]
80
+ release_to_username = Buildr.repositories.release_to[:username]
81
+ release_to_password = Buildr.repositories.release_to[:password]
82
+
83
+ begin
84
+ Buildr.repositories.release_to[:url] = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
85
+ Buildr.repositories.release_to[:username] = username
86
+ Buildr.repositories.release_to[:password] = password
87
+
88
+ project.task(':package').invoke
89
+
90
+ r = MavenCentral.new
91
+ r.username = username
92
+ r.password = password
93
+ r.user_agent = "Buildr-#{Buildr::VERSION}"
94
+ while r.get_staging_repositories(profile_name, false).size != 0
95
+ puts 'Another project currently staging. Waiting for other repository to complete. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories to view the other staging attempts.'
96
+ sleep 1
97
+ end
98
+ puts "Beginning upload to staging repository #{profile_name}"
99
+
100
+ project.task(':upload').invoke
101
+
102
+ r.release_sole_auto_staging(profile_name)
103
+ ensure
104
+ Buildr.repositories.release_to[:url] = release_to_url
105
+ Buildr.repositories.release_to[:username] = release_to_username
106
+ Buildr.repositories.release_to[:password] = release_to_password
107
+ end
108
+ end
109
+ end
110
+
111
+ attr_writer :username
112
+
113
+ def username
114
+ @username || (raise 'Username not yet specified')
115
+ end
116
+
117
+ attr_writer :password
118
+
119
+ def password
120
+ @password || (raise 'Password not yet specified')
121
+ end
122
+
123
+ attr_writer :user_agent
124
+
125
+ def user_agent
126
+ @user_agent || "Ruby-#{RUBY_VERSION}"
127
+ end
128
+
129
+ def get_staging_repositories(profile_name, ignore_transitioning_repositories = true)
130
+ result = get_request('https://oss.sonatype.org/service/local/staging/profile_repositories')
131
+ result = JSON.parse(result)
132
+ result['data'].select do |repo|
133
+ repo['profileName'] == profile_name &&
134
+ repo['userId'] == self.username &&
135
+ repo['userAgent'] == self.user_agent &&
136
+ (!ignore_transitioning_repositories || !repo['transitioning']) &&
137
+ get_my_ip_addresses.any? { |a| a == repo['ipAddress'] }
138
+ end
139
+ end
140
+
141
+ def get_my_ip_addresses
142
+ addresses = Socket.ip_address_list.collect { |a| a.ip_address.to_s }
143
+ commands = [
144
+ "dig +short myip.opendns.com @resolver1.opendns.com",
145
+ "curl ifconfig.me",
146
+ "curl icanhazip.com",
147
+ "curl ipecho.net/plain",
148
+ "curl ifconfig.co",
149
+ "dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{ print $2 }'"
150
+ ]
151
+ commands.each do |cmd|
152
+ begin
153
+ addresses << `#{cmd}`.strip
154
+ rescue Exception
155
+ # ignored
156
+ end
157
+ end
158
+ urls = %w[http://www.myexternalip.com/raw https://diagnostic.opendns.com/myip]
159
+ urls.each do |url|
160
+ begin
161
+ addresses << Net::HTTP.get(URI(url)).strip
162
+ rescue Exception
163
+ # ignored
164
+ end
165
+ end
166
+ begin
167
+ addresses << JSON.parse(Net::HTTP.get(URI('https://api.ipify.org?format=json')))['ip']
168
+ rescue Exception
169
+ # ignored
170
+ end
171
+ addresses.sort.uniq
172
+ end
173
+
174
+ def close_repository(repository_id, description)
175
+ post_request('https://oss.sonatype.org/service/local/staging/bulk/close',
176
+ JSON.pretty_generate('data' => { 'description' => description, 'stagedRepositoryIds' => [repository_id] }))
177
+ end
178
+
179
+ def promote_repository(repository_id, description)
180
+ post_request('https://oss.sonatype.org/service/local/staging/bulk/promote',
181
+ JSON.pretty_generate('data' => { 'autoDropAfterRelease' => true,
182
+ 'description' => description,
183
+ 'stagedRepositoryIds' => [repository_id] }))
184
+ end
185
+
186
+ def drop_repository(repository_id, description)
187
+ post_request('https://oss.sonatype.org/service/local/staging/bulk/drop',
188
+ JSON.pretty_generate('data' => { 'description' => description, 'stagedRepositoryIds' => [repository_id] }))
189
+ end
190
+
191
+ def release_sole_auto_staging(profile_name)
192
+ candidates = get_staging_repositories(profile_name)
193
+ if candidates.empty?
194
+ raise 'Release process unable to find any staging repositories.'
195
+ elsif 1 != candidates.size
196
+ raise 'Release process found multiple staging repositories that could be the release just uploaded. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories and manually complete the release.'
197
+ else
198
+ candidate = candidates[0]
199
+ puts "Requesting close of staging repository #{profile_name}:#{candidate['repositoryId']}"
200
+ begin
201
+ close_repository(candidate['repositoryId'], "Closing repository for #{profile_name}")
202
+ rescue Exception => e
203
+ puts "#{e.class.name}: #{e.message}"
204
+ puts e.backtrace.join("\n")
205
+ raise 'Failed to close repository. It is likely that the release does not conform to Maven Central release requirements. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories and manually complete the release.'
206
+ end
207
+ while get_staging_repositories(profile_name).size == 0
208
+ puts 'Waiting for repository to close...'
209
+ sleep 1
210
+ end
211
+ puts "Requesting promotion of staging repository #{profile_name}:#{candidate['repositoryId']}"
212
+ begin
213
+ promote_repository(candidate['repositoryId'], "Promoting repository for #{profile_name}")
214
+ rescue Exception => e
215
+ puts "#{e.class.name}: #{e.message}"
216
+ puts e.backtrace.join("\n")
217
+ raise 'Failed to promote repository. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories and manually complete the release.'
218
+ end
219
+ repositories = get_staging_repositories(profile_name, false)
220
+ while repositories.size == 1
221
+ puts 'Waiting for repository to be promoted...'
222
+ sleep 1
223
+ if repositories[0]['notifications'] != 0
224
+ raise 'Failed to promote repository. Please visit the website https://oss.sonatype.org/index.html#stagingRepositories and manually complete the release.'
225
+ end
226
+ repositories = get_staging_repositories(profile_name, false)
227
+ end
228
+ end
229
+ end
230
+
231
+ private
232
+
233
+ def create_http(uri)
234
+ http = Net::HTTP.new(uri.host, uri.port)
235
+ http.use_ssl = true
236
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
237
+ http
238
+ end
239
+
240
+ def setup_standard_request(request)
241
+ request['Accept'] = 'application/json,application/vnd.siesta-error-v1+json,application/vnd.siesta-validation-errors-v1+json'
242
+ request.basic_auth(self.username, self.password)
243
+ request.add_field('User-Agent', self.user_agent)
244
+ end
245
+
246
+ def get_request(url)
247
+ uri = URI.parse(url)
248
+ request = Net::HTTP::Get.new(uri.request_uri)
249
+ setup_standard_request(request)
250
+ create_http(uri).request(request).body
251
+ end
252
+
253
+ def post_request(url, content)
254
+ uri = URI.parse(url)
255
+ request = Net::HTTP::Post.new(uri.request_uri)
256
+ setup_standard_request(request)
257
+ request.add_field('Content-Type', 'application/json')
258
+ request.body = content
259
+ create_http(uri).request(request).body
260
+ end
261
+ end
262
+ end
@@ -14,5 +14,5 @@
14
14
  # the License.
15
15
 
16
16
  module Buildr #:nodoc:
17
- VERSION = '1.5.11'.freeze
17
+ VERSION = '1.5.12'.freeze
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: realityforge-buildr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.11
4
+ version: 1.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Apache Buildr
@@ -220,6 +220,7 @@ files:
220
220
  - lib/buildr/java/doc.rb
221
221
  - lib/buildr/java/packaging.rb
222
222
  - lib/buildr/java/pom.rb
223
+ - lib/buildr/java/publish.rb
223
224
  - lib/buildr/java/test_result.rb
224
225
  - lib/buildr/java/tests.rb
225
226
  - lib/buildr/packaging/archive.rb