@@ -354,11 +354,18 @@ end
354
354
355
355
task 'release-java' : %i[ prep-release-zip publish-maven ]
356
356
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
360
359
user = nil
361
360
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
362
369
settings . each_line do |line |
363
370
if !found_section
364
371
found_section = line . include? '<id>sonatype-nexus-staging</id>'
@@ -375,16 +382,20 @@ def read_user_pass_from_m2_settings
375
382
end
376
383
377
384
task 'publish-maven' : JAVA_RELEASE_TARGETS do
378
- creds = read_user_pass_from_m2_settings
385
+ creds = read_m2_user_pass
379
386
JAVA_RELEASE_TARGETS . each do |p |
380
387
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 )
381
388
end
382
389
end
383
390
384
391
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.'
388
399
end
389
400
end
390
401
0 commit comments