Skip to content

Commit

Permalink
[java] Reading m2 user & pass from env vars where available
Browse files Browse the repository at this point in the history
Like that, we can set the secret in GitHub actions and
push SNAPSHOTS automatically. Helps with #11355.
  • Loading branch information
diemol committed Jun 16, 2023
1 parent bf38914 commit 7b9cb37
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,18 @@ end

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

def read_user_pass_from_m2_settings
settings = File.read(ENV['HOME'] + '/.m2/settings.xml')
found_section = false
def read_m2_user_pass
# First check env vars, then the settings.xml config inside .m2
user = nil
pass = nil
if ENV['SEL_M2_USER'] && ENV['SEL_M2_PASS']
puts 'Fetching m2 user and pass from environment variables.'
user = ENV['SEL_M2_USER']
pass = ENV['SEL_M2_PASS']
return [user, pass]
end
settings = File.read(ENV['HOME'] + '/.m2/settings.xml')
found_section = false
settings.each_line do |line|
if !found_section
found_section = line.include? '<id>sonatype-nexus-staging</id>'
Expand All @@ -375,16 +382,20 @@ def read_user_pass_from_m2_settings
end

task 'publish-maven': JAVA_RELEASE_TARGETS do
creds = read_user_pass_from_m2_settings
creds = read_m2_user_pass
JAVA_RELEASE_TARGETS.each do |p|
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)
end
end

task 'publish-maven-snapshot': JAVA_RELEASE_TARGETS do
creds = read_user_pass_from_m2_settings
JAVA_RELEASE_TARGETS.each do |p|
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)
creds = read_m2_user_pass
if version.end_with?('-SNAPSHOT')
JAVA_RELEASE_TARGETS.each do |p|
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)
end
else
puts 'No SNAPSHOT version configured. Targets will not be pushed to the snapshot repo in SonaType.'
end
end

Expand Down

0 comments on commit 7b9cb37

Please sign in to comment.