2015-04-17 00:28:38 +00:00
|
|
|
require "bundler/gem_tasks"
|
2019-11-05 20:10:36 +00:00
|
|
|
require "json"
|
|
|
|
|
|
|
|
task :release_gem, :tag do |_t, args|
|
|
|
|
tag = args[:tag]
|
|
|
|
raise "You must provide a tag to release." if tag.nil?
|
|
|
|
|
|
|
|
# Verify the tag format "vVERSION"
|
|
|
|
m = tag.match(/v(?<version>\S*)/)
|
|
|
|
raise "Tag #{tag} does not match the expected format." if m.nil?
|
|
|
|
|
|
|
|
version = m[:version]
|
|
|
|
raise "You must provide a version." if version.nil?
|
|
|
|
|
|
|
|
api_token = ENV["RUBYGEMS_API_TOKEN"]
|
|
|
|
|
|
|
|
require "gems"
|
|
|
|
if api_token
|
|
|
|
::Gems.configure do |config|
|
|
|
|
config.key = api_token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Bundler.with_clean_env do
|
|
|
|
sh "rm -rf pkg"
|
|
|
|
sh "bundle update"
|
|
|
|
sh "bundle exec rake build"
|
|
|
|
end
|
|
|
|
|
|
|
|
path_to_be_pushed = "pkg/google-api-client-#{version}.gem"
|
|
|
|
gem_was_published = nil
|
|
|
|
if File.file? path_to_be_pushed
|
|
|
|
begin
|
|
|
|
response = ::Gems.push File.new(path_to_be_pushed)
|
|
|
|
puts response
|
|
|
|
raise unless response.include? "Successfully registered gem:"
|
|
|
|
gem_was_published = true
|
|
|
|
puts "Successfully built and pushed google-api-client for version #{version}"
|
|
|
|
rescue StandardError => e
|
|
|
|
gem_was_published = false
|
|
|
|
puts "Error while releasing google-api-client version #{version}: #{e.message}"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise "Cannot build google-api-client for version #{version}"
|
|
|
|
end
|
|
|
|
|
|
|
|
Rake::Task["kokoro:publish_docs"].invoke if gem_was_published
|
|
|
|
end
|
2010-07-28 19:30:56 +00:00
|
|
|
|
2016-08-18 07:04:17 +00:00
|
|
|
task default: :spec
|
2019-04-12 00:28:00 +00:00
|
|
|
|
|
|
|
namespace :kokoro do
|
|
|
|
task :load_env_vars do
|
|
|
|
service_account = "#{ENV['KOKORO_GFILE_DIR']}/service-account.json"
|
|
|
|
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = service_account
|
|
|
|
filename = "#{ENV['KOKORO_GFILE_DIR']}/env_vars.json"
|
|
|
|
env_vars = JSON.parse File.read(filename)
|
|
|
|
env_vars.each { |k, v| ENV[k] = v }
|
|
|
|
end
|
|
|
|
|
|
|
|
task :presubmit do
|
|
|
|
Rake::Task["spec"].invoke
|
|
|
|
end
|
|
|
|
|
|
|
|
task :continuous do
|
|
|
|
Rake::Task["spec"].invoke
|
|
|
|
end
|
|
|
|
|
|
|
|
task :nightly do
|
|
|
|
Rake::Task["spec"].invoke
|
|
|
|
end
|
2019-11-05 20:10:36 +00:00
|
|
|
|
|
|
|
task :post do
|
2019-11-07 02:46:59 +00:00
|
|
|
require_relative "rakelib/devsite/link_checker.rb"
|
2019-11-05 20:10:36 +00:00
|
|
|
|
|
|
|
link_checker = LinkChecker.new
|
|
|
|
link_checker.run
|
|
|
|
exit link_checker.exit_status
|
|
|
|
end
|
|
|
|
|
|
|
|
task :release do
|
2020-10-27 18:28:52 +00:00
|
|
|
Rake::Task["kokoro:publish_gem"].invoke
|
|
|
|
Rake::Task["kokoro:publish_docs"].invoke
|
|
|
|
end
|
|
|
|
|
|
|
|
task :publish_gem do
|
|
|
|
require "gems"
|
|
|
|
|
|
|
|
load_env_vars if ENV["KOKORO_GFILE_DIR"]
|
|
|
|
api_token = ENV["RUBYGEMS_API_TOKEN"]
|
|
|
|
if api_token
|
|
|
|
::Gems.configure do |config|
|
|
|
|
config.key = api_token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
rm_rf "pkg"
|
|
|
|
Rake::Task["build"].invoke
|
|
|
|
built_gem_path = Dir.glob("pkg/google-api-client-*.gem").last
|
2019-11-05 20:10:36 +00:00
|
|
|
|
2020-10-27 19:35:26 +00:00
|
|
|
response = ::Gems.push File.new built_gem_path
|
2020-10-27 18:28:52 +00:00
|
|
|
puts response
|
|
|
|
raise "Failed to release gem" unless response.include? "Successfully registered gem:"
|
2019-11-05 20:10:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Publish docs for the latest git tag"
|
|
|
|
task :publish_docs do
|
|
|
|
require_relative "rakelib/devsite/devsite_builder.rb"
|
|
|
|
|
|
|
|
DevsiteBuilder.new.publish ENV["DOCS_BUILD_TAG"]
|
|
|
|
end
|
2019-04-12 00:28:00 +00:00
|
|
|
end
|
|
|
|
|
2020-10-27 18:28:52 +00:00
|
|
|
def load_env_vars
|
|
|
|
service_account = "#{ENV['KOKORO_GFILE_DIR']}/service-account.json"
|
|
|
|
raise "#{service_account} is not a file" unless File.file? service_account
|
|
|
|
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = service_account
|
|
|
|
filename = "#{ENV['KOKORO_GFILE_DIR']}/ruby_env_vars.json"
|
|
|
|
raise "#{filename} is not a file" unless File.file? filename
|
|
|
|
env_vars = JSON.parse File.read(filename)
|
|
|
|
env_vars.each { |k, v| ENV[k] ||= v }
|
|
|
|
end
|
|
|
|
|
2019-04-12 00:28:00 +00:00
|
|
|
def header str, token = "#"
|
|
|
|
line_length = str.length + 8
|
2019-11-05 20:10:36 +00:00
|
|
|
puts
|
2019-04-12 00:28:00 +00:00
|
|
|
puts token * line_length
|
|
|
|
puts "#{token * 3} #{str} #{token * 3}"
|
|
|
|
puts token * line_length
|
2019-11-05 20:10:36 +00:00
|
|
|
puts
|
2019-04-12 00:28:00 +00:00
|
|
|
end
|