@@ -354,11 +354,18 @@ end
354354
355355task '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
375382end
376383
377384task '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
382389end
383390
384391task '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
389400end
390401
0 commit comments