2015-02-12 03:23:34 +00:00
|
|
|
# -*- ruby -*-
|
2019-03-15 19:34:54 +00:00
|
|
|
require "bundler/gem_tasks"
|
2015-02-12 03:23:34 +00:00
|
|
|
|
2019-03-22 19:37:06 +00:00
|
|
|
task :ci do
|
|
|
|
header "Using Ruby - #{RUBY_VERSION}"
|
|
|
|
sh "bundle exec rubocop"
|
|
|
|
sh "bundle exec rspec"
|
|
|
|
end
|
2019-02-22 18:38:05 +00:00
|
|
|
|
2019-03-15 19:34:54 +00:00
|
|
|
task :release, :tag do |_t, args|
|
2019-02-22 18:38:05 +00:00
|
|
|
tag = args[:tag]
|
|
|
|
raise "You must provide a tag to release." if tag.nil?
|
|
|
|
|
2019-03-22 19:37:06 +00:00
|
|
|
# Verify the tag format "vVERSION"
|
2019-02-22 18:38:05 +00:00
|
|
|
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"
|
2019-03-15 19:34:54 +00:00
|
|
|
if api_token
|
|
|
|
::Gems.configure do |config|
|
|
|
|
config.key = api_token
|
|
|
|
end
|
|
|
|
end
|
2019-02-22 18:38:05 +00:00
|
|
|
|
|
|
|
Bundler.with_clean_env do
|
|
|
|
sh "rm -rf pkg"
|
|
|
|
sh "bundle update"
|
|
|
|
sh "bundle exec rake build"
|
|
|
|
end
|
|
|
|
|
|
|
|
path_to_be_pushed = "pkg/#{version}.gem"
|
|
|
|
if File.file? path_to_be_pushed
|
|
|
|
begin
|
2019-03-15 19:34:54 +00:00
|
|
|
::Gems.push File.new(path_to_be_pushed)
|
2019-02-22 18:38:05 +00:00
|
|
|
puts "Successfully built and pushed googleauth for version #{version}"
|
2019-03-15 19:34:54 +00:00
|
|
|
rescue StandardError => e
|
2019-02-22 18:38:05 +00:00
|
|
|
puts "Error while releasing googleauth version #{version}: #{e.message}"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
raise "Cannot build googleauth for version #{version}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :kokoro do
|
|
|
|
task :load_env_vars do
|
2019-03-15 19:34:54 +00:00
|
|
|
service_account = "#{ENV['KOKORO_GFILE_DIR']}/service-account.json"
|
2019-02-22 18:38:05 +00:00
|
|
|
ENV["GOOGLE_APPLICATION_CREDENTIALS"] = service_account
|
2019-03-15 19:34:54 +00:00
|
|
|
filename = "#{ENV['KOKORO_GFILE_DIR']}/env_vars.json"
|
|
|
|
env_vars = JSON.parse File.read(filename)
|
2019-02-22 18:38:05 +00:00
|
|
|
env_vars.each { |k, v| ENV[k] = v }
|
|
|
|
end
|
|
|
|
|
2019-03-22 19:37:06 +00:00
|
|
|
task :presubmit do
|
|
|
|
Rake::Task["ci"].invoke
|
|
|
|
end
|
|
|
|
|
|
|
|
task :continuous do
|
|
|
|
Rake::Task["ci"].invoke
|
|
|
|
end
|
|
|
|
|
|
|
|
task :nightly do
|
|
|
|
Rake::Task["ci"].invoke
|
|
|
|
end
|
|
|
|
|
2019-02-22 18:38:05 +00:00
|
|
|
task :release do
|
|
|
|
version = "0.1.0"
|
|
|
|
Bundler.with_clean_env do
|
|
|
|
version = `bundle exec gem list`
|
2019-03-15 19:34:54 +00:00
|
|
|
.split("\n").select { |line| line.include? "googleauth" }
|
|
|
|
.first.split("(").last.split(")").first || "0.1.0"
|
2019-02-22 18:38:05 +00:00
|
|
|
end
|
|
|
|
Rake::Task["kokoro:load_env_vars"].invoke
|
|
|
|
Rake::Task["release"].invoke "v/#{version}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def header str, token = "#"
|
|
|
|
line_length = str.length + 8
|
|
|
|
puts ""
|
|
|
|
puts token * line_length
|
|
|
|
puts "#{token * 3} #{str} #{token * 3}"
|
|
|
|
puts token * line_length
|
|
|
|
puts ""
|
2019-03-15 19:34:54 +00:00
|
|
|
end
|