Skip to content

Commit bebf8df

Browse files
titusfortnersandeepsuryaprasad
authored andcommitted
[build] minimize rebuilding during maven deployment process
using --define to pass in arguments should cause rebuilding where using env variables should not calling build on all the release targets without specifying stamp should cause rebuilding
1 parent 894207d commit bebf8df

File tree

1 file changed

+20
-62
lines changed

1 file changed

+20
-62
lines changed

Rakefile

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -336,69 +336,35 @@ end
336336

337337
task 'release-java': %i[java-release-zip publish-maven]
338338

339-
# TODO: just set the environment variables that maven is asking for
340339
def read_m2_user_pass
341-
user = ENV.fetch('SEL_M2_USER', nil)
342-
pass = ENV.fetch('SEL_M2_PASS', nil)
343-
if user && pass
344-
puts 'Fetching m2 user and pass from environment variables.'
345-
return [user, pass]
346-
end
340+
ENV['MAVEN_USER'] ||= ENV.fetch('SEL_M2_USER', nil)
341+
ENV['MAVEN_PASSWORD'] ||= ENV.fetch('SEL_M2_PASS', nil)
342+
343+
return if ENV['MAVEN_PASSWORD'] && ENV['MAVEN_USER']
347344

348-
puts 'Fetching m2 user and pass from /.m2/settings.xml.'
345+
puts 'Maven environment variables not set, inspecting /.m2/settings.xml.'
349346
settings = File.read("#{Dir.home}/.m2/settings.xml")
350347
found_section = false
351348
settings.each_line do |line|
352349
if !found_section
353350
found_section = line.include? '<id>sonatype-nexus-staging</id>'
354351
elsif line.include?('<username>')
355-
user = line[%r{<username>(.*?)</username>}, 1]
352+
ENV['MAVEN_USER'] = line[%r{<username>(.*?)</username>}, 1]
356353
elsif line.include?('<password>')
357-
pass = line[%r{<password>(.*?)</password>}, 1]
354+
ENV['MAVEN_PASSWORD'] = line[%r{<password>(.*?)</password>}, 1]
358355
end
359-
break if user && pass
356+
break if ENV['MAVEN_PASSWORD'] && ENV['MAVEN_USER']
360357
end
361-
[user, pass]
362358
end
363359

364360
desc 'Publish all Java jars to Maven as stable release'
365-
task 'publish-maven': JAVA_RELEASE_TARGETS do
366-
creds = read_m2_user_pass
367-
JAVA_RELEASE_TARGETS.each do |p|
368-
Bazel.execute('run',
369-
['--stamp',
370-
'--define',
371-
'maven_repo=https://oss.sonatype.org/service/local/staging/deploy/maven2',
372-
'--define',
373-
"maven_user=#{creds[0]}",
374-
'--define',
375-
"maven_password=#{creds[1]}",
376-
'--define',
377-
'gpg_sign=true'],
378-
p)
379-
end
361+
task 'publish-maven' do
362+
Rake::Task['java:release'].invoke
380363
end
381364

382365
desc 'Publish all Java jars to Maven as nightly release'
383-
task 'publish-maven-snapshot': JAVA_RELEASE_TARGETS do
384-
creds = read_m2_user_pass
385-
if java_version.end_with?('-SNAPSHOT')
386-
JAVA_RELEASE_TARGETS.each do |p|
387-
Bazel.execute('run',
388-
['--stamp',
389-
'--define',
390-
'maven_repo=https://oss.sonatype.org/content/repositories/snapshots',
391-
'--define',
392-
"maven_user=#{creds[0]}",
393-
'--define',
394-
"maven_password=#{creds[1]}",
395-
'--define',
396-
'gpg_sign=false'],
397-
p)
398-
end
399-
else
400-
puts 'No SNAPSHOT version configured. Targets will not be pushed to the snapshot repo in SonaType.'
401-
end
366+
task 'publish-maven-snapshot' do
367+
Rake::Task['java:release'].invoke('nightly')
402368
end
403369

404370
desc 'Install jars to local m2 directory'
@@ -803,10 +769,9 @@ namespace :dotnet do
803769
Rake::Task['dotnet:version'].invoke('nightly') if nightly
804770
Rake::Task['dotnet:package'].invoke('--stamp')
805771

806-
release_version = dotnet_version
807772
api_key = ENV.fetch('NUGET_API_KEY', nil)
808773
push_destination = 'https://api.nuget.org/v3/index.json'
809-
if release_version.include?('-nightly')
774+
if nightly
810775
# Nightly builds are pushed to GitHub NuGet repository
811776
# This commands will run in GitHub Actions
812777
api_key = ENV.fetch('GITHUB_TOKEN', nil)
@@ -883,10 +848,10 @@ namespace :java do
883848
JAVA_RELEASE_TARGETS.each { |target| Bazel.execute('build', args, target) }
884849
end
885850

886-
desc 'Build Grid Jar'
851+
desc 'Build Grid Server'
887852
task :grid do |_task, arguments|
888853
args = arguments.to_a.compact
889-
Bazel.execute('build', args, '//java/src/org/openqa/selenium/grid:grid')
854+
Bazel.execute('build', args, '//java/src/org/openqa/selenium/grid:executable-grid')
890855
end
891856

892857
desc 'Package Java bindings and grid into releasable packages and stage for release'
@@ -914,23 +879,16 @@ namespace :java do
914879
task :release do |_task, arguments|
915880
args = arguments.to_a.compact
916881
nightly = args.delete('nightly')
917-
user, password = read_m2_user_pass
882+
883+
read_m2_user_pass
918884
repo = nightly ? 'content/repositories/snapshots' : 'service/local/staging/deploy/maven2'
919-
gpg = nightly ? 'false' : 'true'
885+
ENV['MAVEN_REPO'] = "https://oss.sonatype.org/#{repo}"
886+
ENV['GPG_SIGN'] = (!nightly).to_s
920887

921888
Rake::Task['java:version'].invoke if nightly
922889
Rake::Task['java:package'].invoke('--stamp')
923890
Rake::Task['java:build'].invoke('--stamp')
924-
release_args = ['--stamp',
925-
'--define',
926-
"maven_repo=https://oss.sonatype.org/#{repo}",
927-
'--define',
928-
"maven_user=#{user}",
929-
'--define',
930-
"maven_password=#{password}",
931-
'--define',
932-
"gpg_sign=#{gpg}"]
933-
JAVA_RELEASE_TARGETS.each { |target| Bazel.execute('run', release_args, target) }
891+
JAVA_RELEASE_TARGETS.each { |target| Bazel.execute('run', ['--stamp'], target) }
934892
end
935893

936894
desc 'Install jars to local m2 directory'

0 commit comments

Comments
 (0)