Skip to content

Commit 7b9cb37

Browse files
committed
[java] Reading m2 user & pass from env vars where available
Like that, we can set the secret in GitHub actions and push SNAPSHOTS automatically. Helps with #11355.
1 parent bf38914 commit 7b9cb37

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

Rakefile

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,18 @@ end
354354

355355
task 'release-java': %i[prep-release-zip publish-maven]
356356

357-
def read_user_pass_from_m2_settings
358-
settings = File.read(ENV['HOME'] + '/.m2/settings.xml')
359-
found_section = false
357+
def read_m2_user_pass
358+
# First check env vars, then the settings.xml config inside .m2
360359
user = nil
361360
pass = nil
361+
if ENV['SEL_M2_USER'] && ENV['SEL_M2_PASS']
362+
puts 'Fetching m2 user and pass from environment variables.'
363+
user = ENV['SEL_M2_USER']
364+
pass = ENV['SEL_M2_PASS']
365+
return [user, pass]
366+
end
367+
settings = File.read(ENV['HOME'] + '/.m2/settings.xml')
368+
found_section = false
362369
settings.each_line do |line|
363370
if !found_section
364371
found_section = line.include? '<id>sonatype-nexus-staging</id>'
@@ -375,16 +382,20 @@ def read_user_pass_from_m2_settings
375382
end
376383

377384
task 'publish-maven': JAVA_RELEASE_TARGETS do
378-
creds = read_user_pass_from_m2_settings
385+
creds = read_m2_user_pass
379386
JAVA_RELEASE_TARGETS.each do |p|
380387
Bazel::execute('run', ['--stamp', '--define', 'maven_repo=https://oss.sonatype.org/service/local/staging/deploy/maven2', '--define', "maven_user=#{creds[0]}", '--define', "maven_password=#{creds[1]}", '--define', 'gpg_sign=true'], p)
381388
end
382389
end
383390

384391
task 'publish-maven-snapshot': JAVA_RELEASE_TARGETS do
385-
creds = read_user_pass_from_m2_settings
386-
JAVA_RELEASE_TARGETS.each do |p|
387-
Bazel::execute('run', ['--stamp', '--define', 'maven_repo=https://oss.sonatype.org/content/repositories/snapshots', '--define', "maven_user=#{creds[0]}", '--define', "maven_password=#{creds[1]}", '--define', 'gpg_sign=true'], p)
392+
creds = read_m2_user_pass
393+
if version.end_with?('-SNAPSHOT')
394+
JAVA_RELEASE_TARGETS.each do |p|
395+
Bazel::execute('run', ['--stamp', '--define', 'maven_repo=https://oss.sonatype.org/content/repositories/snapshots', '--define', "maven_user=#{creds[0]}", '--define', "maven_password=#{creds[1]}", '--define', 'gpg_sign=false'], p)
396+
end
397+
else
398+
puts 'No SNAPSHOT version configured. Targets will not be pushed to the snapshot repo in SonaType.'
388399
end
389400
end
390401

0 commit comments

Comments
 (0)