chore: publish to googleapis.dev on release (#242)

This commit is contained in:
Graham Paye 2019-10-11 10:56:55 -07:00 committed by GitHub
parent 6be995d29a
commit a6082d158b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 128 additions and 4 deletions

View File

@ -60,7 +60,7 @@ build_file: "google-auth-library-ruby/.kokoro/trampoline.sh"
# Configure the docker image for kokoro-trampoline. # Configure the docker image for kokoro-trampoline.
env_vars: { env_vars: {
key: "TRAMPOLINE_IMAGE" key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/google-cloud-ruby/ruby-release" value: "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/release"
} }
env_vars: { env_vars: {

5
.repo-metadata.json Normal file
View File

@ -0,0 +1,5 @@
{
"name": "googleauth",
"language": "ruby",
"distribution-name": "googleauth"
}

View File

@ -5,6 +5,7 @@ AllCops:
Exclude: Exclude:
- "spec/**/*" - "spec/**/*"
- "Rakefile" - "Rakefile"
- "rakelib/**/*"
Metrics/ClassLength: Metrics/ClassLength:
Max: 110 Max: 110
Exclude: Exclude:

View File

@ -13,7 +13,7 @@ task :release_gem, :tag do |_t, args|
raise "You must provide a tag to release." if tag.nil? raise "You must provide a tag to release." if tag.nil?
# Verify the tag format "vVERSION" # Verify the tag format "vVERSION"
m = tag.match(/google-auth-library-ruby\/v(?<version>\S*)/) m = tag.match /v(?<version>\S*)/
raise "Tag #{tag} does not match the expected format." if m.nil? raise "Tag #{tag} does not match the expected format." if m.nil?
version = m[:version] version = m[:version]
@ -35,16 +35,23 @@ task :release_gem, :tag do |_t, args|
end end
path_to_be_pushed = "pkg/googleauth-#{version}.gem" path_to_be_pushed = "pkg/googleauth-#{version}.gem"
gem_was_published = nil
if File.file? path_to_be_pushed if File.file? path_to_be_pushed
begin begin
::Gems.push File.new(path_to_be_pushed) 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 googleauth for version #{version}" puts "Successfully built and pushed googleauth for version #{version}"
rescue StandardError => e rescue StandardError => e
gem_was_published = false
puts "Error while releasing googleauth version #{version}: #{e.message}" puts "Error while releasing googleauth version #{version}: #{e.message}"
end end
else else
raise "Cannot build googleauth for version #{version}" raise "Cannot build googleauth for version #{version}"
end end
Rake::Task["kokoro:publish_docs"].invoke if gem_was_published
end end
namespace :kokoro do namespace :kokoro do
@ -76,7 +83,13 @@ namespace :kokoro do
.first.split("(").last.split(")").first || "0.1.0" .first.split("(").last.split(")").first || "0.1.0"
end end
Rake::Task["kokoro:load_env_vars"].invoke Rake::Task["kokoro:load_env_vars"].invoke
Rake::Task["release_gem"].invoke "google-auth-library-ruby/v#{version}" Rake::Task["release_gem"].invoke "v#{version}"
end
task :publish_docs do
require_relative "rakelib/devsite_builder.rb"
DevsiteBuilder.new(__dir__).publish
end end
end end

View File

@ -33,4 +33,5 @@ Gem::Specification.new do |gem|
gem.add_dependency "multi_json", "~> 1.11" gem.add_dependency "multi_json", "~> 1.11"
gem.add_dependency "os", ">= 0.9", "< 2.0" gem.add_dependency "os", ">= 0.9", "< 2.0"
gem.add_dependency "signet", "~> 0.12" gem.add_dependency "signet", "~> 0.12"
gem.add_development_dependency "yard", "~> 0.9"
end end

View File

@ -0,0 +1,45 @@
require "pathname"
require_relative "repo_metadata.rb"
class DevsiteBuilder
def initialize master_dir = "."
@master_dir = Pathname.new master_dir
@output_dir = "doc"
@metadata = RepoMetadata.from_source "#{master_dir}/.repo-metadata.json"
end
def build
FileUtils.remove_dir @output_dir if Dir.exist? @output_dir
markup = "--markup markdown"
Dir.chdir @master_dir do
cmds = ["-o #{@output_dir}", markup]
cmd "yard --verbose #{cmds.join ' '}"
end
@metadata.build @master_dir + @output_dir
end
def upload
Dir.chdir @output_dir do
opts = [
"--credentials=#{ENV['KOKORO_KEYSTORE_DIR']}/73713_docuploader_service_account",
"--staging-bucket=#{ENV.fetch 'STAGING_BUCKET', 'docs-staging'}",
"--metadata-file=./docs.metadata"
]
cmd "python3 -m docuploader upload . #{opts.join ' '}"
end
end
def publish
build
upload
end
def cmd line
puts line
output = `#{line}`
puts output
output
end
end

59
rakelib/repo_metadata.rb Normal file
View File

@ -0,0 +1,59 @@
require "json"
class RepoMetadata
attr_reader :data
def initialize data
@data = data
normalize_data!
end
def allowed_fields
[
"name", "version", "language", "distribution-name",
"product-page", "github-repository", "issue-tracker"
]
end
def build output_directory
fields = @data.to_a.map { |kv| "--#{kv[0]} #{kv[1]}" }
Dir.chdir output_directory do
cmd "python3 -m docuploader create-metadata #{fields.join ' '}"
end
end
def normalize_data!
require_relative "../lib/googleauth/version.rb"
@data.delete_if { |k, _| !allowed_fields.include?(k) }
@data["version"] = Google::Auth::VERSION
end
def [] key
data[key]
end
def []= key, value
@data[key] = value
end
def cmd line
puts line
output = `#{line}`
puts output
output
end
def self.from_source source
if source.is_a? RepoMetadata
data = source.data
elsif source.is_a? Hash
data = source
elsif File.file? source
data = JSON.parse File.read(source)
else
raise "Source must be a path, hash, or RepoMetadata instance"
end
RepoMetadata.new data
end
end