Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ jobs:
SEL_M2_USER: ${{ secrets.SEL_M2_USER }}
SEL_M2_PASS: ${{ secrets.SEL_M2_PASS }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
Expand Down
73 changes: 58 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,6 @@ RELEASE_CREDENTIALS = {
file: -> { File.exist?("#{Dir.home}/.m2/settings.xml") && File.read("#{Dir.home}/.m2/settings.xml").include?('<id>central</id>') }
},
java_gpg: {cmd: 'gpg'},
python: {
env: [%w[TWINE_USERNAME], %w[TWINE_PASSWORD]],
file: -> { File.exist?("#{Dir.home}/.pypirc") }
},
ruby: {
env: [%w[GEM_HOST_API_KEY]],
file: -> { File.exist?("#{Dir.home}/.gem/credentials") }
},
node: {
env: [%w[NODE_AUTH_TOKEN]],
file: -> { File.exist?("#{Dir.home}/.npmrc") && File.read("#{Dir.home}/.npmrc").include?('//registry.npmjs.org/:_authToken') }
},
dotnet: {env: [%w[NUGET_API_KEY]]},
dotnet_nightly: {env: [%w[GITHUB_TOKEN]]}
}.freeze
Expand All @@ -415,6 +403,61 @@ def credential_valid?(cred)
has_env || has_file || has_cmd
end

def setup_npm_auth
npmrc = File.join(Dir.home, '.npmrc')
return if File.exist?(npmrc) && File.read(npmrc).include?('//registry.npmjs.org/:_authToken=')

token = ENV.fetch('NODE_AUTH_TOKEN', nil)
raise 'Missing npm credentials: set NODE_AUTH_TOKEN or configure ~/.npmrc' if token.nil? || token.empty?

auth_line = "//registry.npmjs.org/:_authToken=#{token}"
if File.exist?(npmrc)
File.open(npmrc, 'a') { |f| f.puts(auth_line) }
else
File.write(npmrc, "#{auth_line}\n")
end
Comment thread
titusfortner marked this conversation as resolved.
Resolved
end

def setup_gem_credentials
gem_dir = File.join(Dir.home, '.gem')
credentials = File.join(gem_dir, 'credentials')
return if File.exist?(credentials) && File.read(credentials).include?(':rubygems_api_key:')

token = ENV.fetch('GEM_HOST_API_KEY', nil)
if token.nil? || token.empty?
raise 'Missing RubyGems credentials: set GEM_HOST_API_KEY or configure ~/.gem/credentials'
end

FileUtils.mkdir_p(gem_dir)
if File.exist?(credentials)
File.open(credentials, 'a') { |f| f.puts(":rubygems_api_key: #{token}") }
else
File.write(credentials, ":rubygems_api_key: #{token}\n")
end
File.chmod(0o600, credentials)
end

def setup_pypirc
pypirc = File.join(Dir.home, '.pypirc')
return if File.exist?(pypirc) && File.read(pypirc).match?(/^\[pypi\]/m)

token = ENV.fetch('TWINE_PASSWORD', nil)
raise 'Missing PyPI credentials: set TWINE_PASSWORD or configure ~/.pypirc' if token.nil? || token.empty?

pypi_section = <<~PYPIRC
[pypi]
username = __token__
password = #{token}
PYPIRC

if File.exist?(pypirc)
File.open(pypirc, 'a') { |f| f.puts("\n#{pypi_section}") }
else
File.write(pypirc, pypi_section)
end
File.chmod(0o600, pypirc)
end

def check_credentials(langs)
missing = langs.select { |lang| RELEASE_CREDENTIALS[lang] && !credential_valid?(RELEASE_CREDENTIALS[lang]) }
raise "Missing credentials: #{missing.join(', ')}" if missing.any?
Expand Down Expand Up @@ -533,7 +576,7 @@ namespace :node do
desc 'Release Node npm package'
task :release do |_task, arguments|
nightly = arguments.to_a.include?('nightly')
check_credentials(%i[node]) unless nightly
setup_npm_auth unless nightly

if nightly
puts 'Updating Node version to nightly...'
Expand Down Expand Up @@ -597,7 +640,7 @@ namespace :py do
desc 'Release Python wheel and sdist to pypi'
task :release do |_task, arguments|
nightly = arguments.to_a.include?('nightly')
check_credentials(%i[python]) unless nightly
setup_pypirc unless nightly

if nightly
puts 'Updating Python version to nightly...'
Expand Down Expand Up @@ -802,7 +845,7 @@ namespace :rb do
puts 'Releasing nightly WebDriver gem...'
Bazel.execute('run', ['--config=release'], '//rb:selenium-webdriver-release-nightly')
else
check_credentials(%i[ruby])
setup_gem_credentials
patch_release = ruby_version.split('.').fetch(2, '0').to_i.positive?

puts 'Releasing Ruby gems...'
Expand Down