diff --git a/.kokoro/build.bat b/.kokoro/build.bat new file mode 100644 index 00000000..5ff89c88 --- /dev/null +++ b/.kokoro/build.bat @@ -0,0 +1,16 @@ +REM This file runs tests for merges, PRs, and nightlies. +REM There are a few rules for what tests are run: +REM * PRs run all non-acceptance tests for every library. +REM * Merges run all non-acceptance tests for every library, and acceptance tests for all altered libraries. +REM * Nightlies run all acceptance tests for every library. +REM Currently only runs tests on 2.5.1 + +SET url="https://raw.githubusercontent.com/googleapis/google-cloud-ruby/master/.kokoro/build.bat" + +SET "download=powershell -C Invoke-WebRequest -Uri %url% -OutFile master-build.bat" + +SET EXIT_STATUS=1 + +%download% && master-build.bat && SET EXIT_STATUS=0 + +EXIT %EXIT_STATUS% diff --git a/.kokoro/build.sh b/.kokoro/build.sh new file mode 100755 index 00000000..7f4e00fb --- /dev/null +++ b/.kokoro/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +script_url="https://raw.githubusercontent.com/googleapis/google-cloud-ruby/master/.kokoro/build.sh" +curl -o master-build.sh $script_url && source master-build.sh diff --git a/.kokoro/continuous/common.cfg b/.kokoro/continuous/common.cfg new file mode 100644 index 00000000..0dd62354 --- /dev/null +++ b/.kokoro/continuous/common.cfg @@ -0,0 +1,24 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Download resources for system tests (service account key, etc.) +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-ruby" + +env_vars: { + key: "JOB_TYPE" + value: "continuous" +} + +env_vars: { + key: "REPO_DIR" + value: "github/getting-started-ruby" +} diff --git a/.kokoro/continuous/linux.cfg b/.kokoro/continuous/linux.cfg new file mode 100644 index 00000000..08fc7b71 --- /dev/null +++ b/.kokoro/continuous/linux.cfg @@ -0,0 +1,25 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "getting-started-ruby/.kokoro/trampoline.sh" + +# Configure the docker image for kokoro-trampoline. +# Dockerfile is maintained at https://github.com/googleapis/google-cloud-ruby/tree/master/.kokoro/docker/multi +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/multi" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/getting-started-ruby/.kokoro/build.sh" +} + +env_vars: { + key: "TRAMPOLINE_SCRIPT" + value: "trampoline_v1.py" +} + +env_vars: { + key: "OS" + value: "linux" +} diff --git a/.kokoro/continuous/osx.cfg b/.kokoro/continuous/osx.cfg new file mode 100644 index 00000000..75eba531 --- /dev/null +++ b/.kokoro/continuous/osx.cfg @@ -0,0 +1,8 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "getting-started-ruby/.kokoro/osx.sh" + +env_vars: { + key: "OS" + value: "osx" +} diff --git a/.kokoro/continuous/post.cfg b/.kokoro/continuous/post.cfg new file mode 100644 index 00000000..8603496c --- /dev/null +++ b/.kokoro/continuous/post.cfg @@ -0,0 +1,30 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "getting-started-ruby/.kokoro/trampoline.sh" + +# Configure the docker image for kokoro-trampoline. +# Dockerfile is maintained at https://github.com/googleapis/google-cloud-ruby/tree/master/.kokoro/docker/multi-node +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/multi-node" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/getting-started-ruby/.kokoro/build.sh" +} + +env_vars: { + key: "TRAMPOLINE_SCRIPT" + value: "trampoline_v1.py" +} + +env_vars: { + key: "OS" + value: "linux" +} + +env_vars: { + key: "JOB_TYPE" + value: "post" +} diff --git a/.kokoro/continuous/windows.cfg b/.kokoro/continuous/windows.cfg new file mode 100644 index 00000000..023a32fe --- /dev/null +++ b/.kokoro/continuous/windows.cfg @@ -0,0 +1,29 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "getting-started-ruby/.kokoro/trampoline.bat" + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/windows" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/getting-started-ruby/.kokoro/build.bat" +} + +env_vars: { + key: "TRAMPOLINE_SCRIPT" + value: "trampoline_windows.py" +} + +env_vars: { + key: "REPO_DIR" + value: "getting-started-ruby" +} + +env_vars: { + key: "OS" + value: "windows" +} diff --git a/.kokoro/osx.sh b/.kokoro/osx.sh new file mode 100755 index 00000000..8be8ec05 --- /dev/null +++ b/.kokoro/osx.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +script_url="https://raw.githubusercontent.com/googleapis/google-cloud-ruby/master/.kokoro/osx.sh" +curl -o master-osx.sh $script_url && source master-osx.sh diff --git a/.kokoro/presubmit/common.cfg b/.kokoro/presubmit/common.cfg new file mode 100644 index 00000000..bb0eb58a --- /dev/null +++ b/.kokoro/presubmit/common.cfg @@ -0,0 +1,24 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Download resources for system tests (service account key, etc.) +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/google-cloud-ruby" + +env_vars: { + key: "JOB_TYPE" + value: "presubmit" +} + +env_vars: { + key: "REPO_DIR" + value: "github/getting-started-ruby" +} diff --git a/.kokoro/presubmit/linux.cfg b/.kokoro/presubmit/linux.cfg new file mode 100644 index 00000000..a0ca6dcd --- /dev/null +++ b/.kokoro/presubmit/linux.cfg @@ -0,0 +1,24 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "getting-started-ruby/.kokoro/trampoline.sh" + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/multi" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/getting-started-ruby/.kokoro/build.sh" +} + +env_vars: { + key: "TRAMPOLINE_SCRIPT" + value: "trampoline_v1.py" +} + +env_vars: { + key: "OS" + value: "linux" +} diff --git a/.kokoro/presubmit/osx.cfg b/.kokoro/presubmit/osx.cfg new file mode 100644 index 00000000..75eba531 --- /dev/null +++ b/.kokoro/presubmit/osx.cfg @@ -0,0 +1,8 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "getting-started-ruby/.kokoro/osx.sh" + +env_vars: { + key: "OS" + value: "osx" +} diff --git a/.kokoro/presubmit/windows.cfg b/.kokoro/presubmit/windows.cfg new file mode 100644 index 00000000..023a32fe --- /dev/null +++ b/.kokoro/presubmit/windows.cfg @@ -0,0 +1,29 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +build_file: "getting-started-ruby/.kokoro/trampoline.bat" + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/windows" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/getting-started-ruby/.kokoro/build.bat" +} + +env_vars: { + key: "TRAMPOLINE_SCRIPT" + value: "trampoline_windows.py" +} + +env_vars: { + key: "REPO_DIR" + value: "getting-started-ruby" +} + +env_vars: { + key: "OS" + value: "windows" +} diff --git a/.kokoro/trampoline.bat b/.kokoro/trampoline.bat new file mode 100644 index 00000000..1634b071 --- /dev/null +++ b/.kokoro/trampoline.bat @@ -0,0 +1,10 @@ + +SET url="https://raw.githubusercontent.com/googleapis/google-cloud-ruby/master/.kokoro/trampoline.bat" + +SET "download=powershell -C Invoke-WebRequest -Uri %url% -OutFile master-trampoline.bat" + +SET EXIT_STATUS=1 + +%download% && master-trampoline.bat && SET EXIT_STATUS=0 + +EXIT %EXIT_STATUS% diff --git a/.kokoro/trampoline.sh b/.kokoro/trampoline.sh new file mode 100755 index 00000000..4325866e --- /dev/null +++ b/.kokoro/trampoline.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +script_url="https://raw.githubusercontent.com/googleapis/google-cloud-ruby/master/.kokoro/trampoline.sh" +curl -o master-trampoline.sh $script_url && source master-trampoline.sh diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..7c3191e5 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,19 @@ +inherit_gem: + google-style: google-style.yml + +AllCops: + Exclude: + - "**/spec/**/*.rb" + - "Rakefile" + +Metrics/BlockLength: + Exclude: + - "**/*test.rb" +Style/Documentation: + Enabled: false +Style/GuardClause: + Enabled: false +Style/MixinUsage: + Exclude: + - "bookshelf/**/*" + - "**/*test.rb" diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..36a4d6d1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,20 @@ +# Copyright 2020 Google, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +source "https://rubygems.org" + +group :development, :test do + gem "google-style", "~> 1.24.0" + gem "rake", "~> 13.0" +end diff --git a/Rakefile b/Rakefile new file mode 100644 index 00000000..1c57de59 --- /dev/null +++ b/Rakefile @@ -0,0 +1,128 @@ +require "json" +require "rake" +require "open3" +require "timeout" + +task :test do + run_tests local: true +end + +task :acceptance do + run_tests local: true, acceptance: true +end + +namespace :kokoro do + task :presubmit do + run_tests + end + + task :continuous do + run_tests + end + + task :post do + require_relative "rakelib/link_checker.rb" + + link_checker = LinkChecker.new + link_checker.run + exit link_checker.exit_status + 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 "" +end + +def header_2 str, token = "#" + puts "\n#{token * 3} #{str} #{token * 3}\n" +end + +def each_sample + gemfiles = Dir.glob("**/Gemfile") - ["Gemfile"] + gemfiles.map! { |gemfile| File.dirname gemfile }.uniq! + gemfiles.each do |dir| + yield dir + end +end + +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']}/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 + +def job_info sample = nil + header "Using Ruby - #{RUBY_VERSION}" + header_2 "Job Type: #{ENV['JOB_TYPE']}" + header_2 "Sample: #{sample}" + puts "" +end + +def run_tests acceptance: false, local: false + failed = false + failed = true if run "bundle exec rubocop" + Dir.chdir "sessions" do + Bundler.with_clean_env do + job_info "sessions" + failed = true if run "bundle update" + load_env_vars unless local + failed = true if run "bundle exec rake test" + if acceptance + failed = true if run "bundle exec rake acceptance", 1800 + end + end + end + exit failed ? 1 : 0 unless acceptance + Dir.chdir "bookshelf" do + Bundler.with_clean_env do + job_info "bookshelf" + failed = true if run "wget -q https://storage.googleapis.com/gcd/tools/cloud-datastore-emulator-1.1.1.zip -O cloud-datastore-emulator.zip" + failed = true if run "unzip -o cloud-datastore-emulator.zip" + + failed = true if run "cloud-datastore-emulator/cloud_datastore_emulator create gcd-test-dataset-directory" + failed = true if run "cloud-datastore-emulator/cloud_datastore_emulator start --testing ./gcd-test-dataset-directory/ &" + + failed = true if run "RAILS_ENV=test bundle exec rake --rakefile=Rakefile assets:precompile" + failed = true if run "bundle update" + load_env_vars unless local + failed = true if run "bundle exec rspec" + end + end + exit failed ? 1 : 0 +end + +def run command, timeout = 0 + if timeout.positive? + run_command_with_timeout command, timeout + else + run_command command + end +end + +def run_command command + out, err, st = Open3.capture3 command + puts out + if st.to_i != 0 + puts err + return true + end + false +end + +def run_command_with_timeout command, timeout + Timeout.timeout timeout do + return run_command command + end +rescue Timeout::Error + header_2 "TIMEOUT - #{timeout / 60} minute limit exceeded." + true +end diff --git a/authenticating-users/Gemfile b/authenticating-users/Gemfile index d0e716d6..ffacdd89 100644 --- a/authenticating-users/Gemfile +++ b/authenticating-users/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } +git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # [START getting_started_requirements] gem "jwt", "~> 2.2" diff --git a/authenticating-users/app.rb b/authenticating-users/app.rb index 7b4d21a7..6ac55c99 100644 --- a/authenticating-users/app.rb +++ b/authenticating-users/app.rb @@ -61,8 +61,7 @@ def validate_assertion assertion key_id = JSON.parse(a_header)["kid"] cert = OpenSSL::PKey::EC.new settings.certificates[key_id] info = JWT.decode assertion, cert, true, algorithm: "ES256", audience: settings.audience - return info[0]["email"], info[0]["sub"] - + [info[0]["email"], info[0]["sub"]] rescue StandardError => e puts "Failed to validate assertion: #{e}" [nil, nil] diff --git a/bookshelf/Gemfile b/bookshelf/Gemfile index 78779992..f371cc0c 100644 --- a/bookshelf/Gemfile +++ b/bookshelf/Gemfile @@ -14,36 +14,36 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '>= 2.5' +ruby ">= 2.5" # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.2.3' +gem "google-cloud-error_reporting" gem "google-cloud-firestore", "~> 1.0" gem "google-cloud-storage", "~> 1.10" -gem "google-cloud-error_reporting" +gem "rails", "~> 5.2.3" gem "jquery-rails" group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem "byebug", platforms: [:mri, :mingw, :x64_mingw] end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. - gem 'web-console', '>= 3.3.0' - gem 'listen', '>= 3.0.5', '< 3.2' + gem "listen", ">= 3.0.5", "< 3.2" + gem "web-console", ">= 3.3.0" end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] group :test do - gem "rspec-rails" - gem "rspec-retry" - gem "rack-test" gem "capybara" + gem "phantomjs", require: "phantomjs/poltergeist" gem "poltergeist" - gem 'phantomjs', :require => 'phantomjs/poltergeist' + gem "rack-test" + gem "rspec-rails" + gem "rspec-retry" end diff --git a/bookshelf/Rakefile b/bookshelf/Rakefile index 3c82c54c..95cac7f1 100644 --- a/bookshelf/Rakefile +++ b/bookshelf/Rakefile @@ -14,6 +14,6 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require_relative 'config/application' +require_relative "config/application" Rails.application.load_tasks diff --git a/bookshelf/app/controllers/books_controller.rb b/bookshelf/app/controllers/books_controller.rb index e87fd7cc..1dab4fa3 100644 --- a/bookshelf/app/controllers/books_controller.rb +++ b/bookshelf/app/controllers/books_controller.rb @@ -12,7 +12,6 @@ # limitations under the License. class BooksController < ApplicationController - PER_PAGE = 10 def index @@ -66,5 +65,4 @@ def book_params params.require(:book).permit :title, :author, :published_on, :description, :cover_image end - end diff --git a/bookshelf/app/controllers/stackdriver_controller.rb b/bookshelf/app/controllers/stackdriver_controller.rb index 279fd30a..d4c36ded 100644 --- a/bookshelf/app/controllers/stackdriver_controller.rb +++ b/bookshelf/app/controllers/stackdriver_controller.rb @@ -13,7 +13,7 @@ class StackdriverController < ApplicationController def logs - Rails.logger.add(Logger::INFO, "Hey, you triggered a custom log entry. Good job!") + Rails.logger.add Logger::INFO, "Hey, you triggered a custom log entry. Good job!" redirect_to "/books", flash: { success: "Log message sent" } end diff --git a/bookshelf/app/models/book.rb b/bookshelf/app/models/book.rb index 85aabdf7..8d82a6d9 100644 --- a/bookshelf/app/models/book.rb +++ b/bookshelf/app/models/book.rb @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# rubocop:disable Metrics/ClassLength class Book # Add Active Model support. # Provides constructor that takes a Hash of attribute values. @@ -45,7 +46,7 @@ def self.storage_bucket # [START bookshelf_cloud_storage_client] require "google/cloud/storage" bucket_id = project_id + "_bucket" - storage = Google::Cloud::Storage.new project_id: config["project_id"], + storage = Google::Cloud::Storage.new project_id: config["project_id"], credentials: config["keyfile"] bucket = storage.bucket bucket_id # [END bookshelf_cloud_storage_client] @@ -64,11 +65,8 @@ def self.query options = {} query = query.start_after options[:last_title] if options[:last_title] books = [] - begin - query.get do |book| - books << Book.from_snapspot(book) - end - rescue + query.get do |book| + books << Book.from_snapspot(book) end books end @@ -79,7 +77,7 @@ def self.requires_pagination last_title .order(:title) .limit(1) .start_after(last_title) - .get.count > 0 + .get.count.positive? end end @@ -142,14 +140,14 @@ def upload_image cover_image.tempfile, "cover_images/#{id}/#{cover_image.original_filename}", content_type: cover_image.content_type, - acl: "public" + acl: "public" @image_url = file.public_url end def destroy delete_image if image_url book_ref = Book.collection.doc id - book_ref.delete if book_ref + book_ref&.delete end def delete_image @@ -165,9 +163,10 @@ def delete_image end end -################## + ################## def persisted? id.present? end end +# rubocop:enable Metrics/ClassLength diff --git a/bookshelf/bin/bundle b/bookshelf/bin/bundle index f0160ef3..733a1433 100755 --- a/bookshelf/bin/bundle +++ b/bookshelf/bin/bundle @@ -13,5 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -load Gem.bin_path('bundler', 'bundle') +ENV["BUNDLE_GEMFILE"] ||= File.expand_path "../Gemfile", __dir__ +load Gem.bin_path("bundler", "bundle") diff --git a/bookshelf/bin/rails b/bookshelf/bin/rails index 9ce2e125..a66d698c 100755 --- a/bookshelf/bin/rails +++ b/bookshelf/bin/rails @@ -13,6 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path "../config/application", __dir__ +require_relative "../config/boot" +require "rails/commands" diff --git a/bookshelf/bin/rake b/bookshelf/bin/rake index b5a09919..57ef663c 100755 --- a/bookshelf/bin/rake +++ b/bookshelf/bin/rake @@ -13,6 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bookshelf/bin/setup b/bookshelf/bin/setup index a6e0ff37..1d2c5929 100755 --- a/bookshelf/bin/setup +++ b/bookshelf/bin/setup @@ -13,13 +13,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'fileutils' +require "fileutils" include FileUtils # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path "..", __dir__ -def system!(*args) +def system! *args system(*args) || abort("\n== Command #{args} failed ==") end @@ -27,9 +27,9 @@ chdir APP_ROOT do # This script is a starting point to setup your application. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') @@ -37,11 +37,11 @@ chdir APP_ROOT do # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! "bin/rails db:setup" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" end diff --git a/bookshelf/config.ru b/bookshelf/config.ru index e8150033..6807d6b9 100644 --- a/bookshelf/config.ru +++ b/bookshelf/config.ru @@ -13,6 +13,6 @@ # This file is used by Rack-based servers to start the application. -require_relative 'config/environment' +require_relative "config/environment" run Rails.application diff --git a/bookshelf/config/application.rb b/bookshelf/config/application.rb index 8fbe6a48..c5e57745 100644 --- a/bookshelf/config/application.rb +++ b/bookshelf/config/application.rb @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require_relative 'boot' +require_relative "boot" require "rails" # Pick the frameworks you want: diff --git a/bookshelf/config/boot.rb b/bookshelf/config/boot.rb index 122835d2..c9a65abb 100644 --- a/bookshelf/config/boot.rb +++ b/bookshelf/config/boot.rb @@ -11,6 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path "../Gemfile", __dir__ -require 'bundler/setup' # Set up gems listed in the Gemfile. +require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/bookshelf/config/environment.rb b/bookshelf/config/environment.rb index 49506954..47af2ed8 100644 --- a/bookshelf/config/environment.rb +++ b/bookshelf/config/environment.rb @@ -12,7 +12,7 @@ # limitations under the License. # Load the Rails application. -require_relative 'application' +require_relative "application" # Initialize the Rails application. Rails.application.initialize! diff --git a/bookshelf/config/environments/development.rb b/bookshelf/config/environments/development.rb index d381801e..21eab417 100644 --- a/bookshelf/config/environments/development.rb +++ b/bookshelf/config/environments/development.rb @@ -27,12 +27,12 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join('tmp', 'caching-dev.txt').exist? + if Rails.root.join("tmp", "caching-dev.txt").exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" + "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false diff --git a/bookshelf/config/environments/production.rb b/bookshelf/config/environments/production.rb index 4bc53ce0..b0e54a17 100644 --- a/bookshelf/config/environments/production.rb +++ b/bookshelf/config/environments/production.rb @@ -33,7 +33,7 @@ # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' @@ -58,7 +58,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -88,9 +88,9 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new STDOUT logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new logger end # Do not dump schema after migrations. diff --git a/bookshelf/config/environments/test.rb b/bookshelf/config/environments/test.rb index e43533e9..35e28bdb 100644 --- a/bookshelf/config/environments/test.rb +++ b/bookshelf/config/environments/test.rb @@ -28,7 +28,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/bookshelf/config/initializers/session_store.rb b/bookshelf/config/initializers/session_store.rb index dc6bbade..b277a3f7 100644 --- a/bookshelf/config/initializers/session_store.rb +++ b/bookshelf/config/initializers/session_store.rb @@ -13,4 +13,4 @@ # Be sure to restart your server when you modify this file. -Rails.application.config.session_store :cookie_store, key: '_Bookshelf_session' +Rails.application.config.session_store :cookie_store, key: "_Bookshelf_session" diff --git a/bookshelf/config/initializers/wrap_parameters.rb b/bookshelf/config/initializers/wrap_parameters.rb index dc9d176a..41341fd7 100644 --- a/bookshelf/config/initializers/wrap_parameters.rb +++ b/bookshelf/config/initializers/wrap_parameters.rb @@ -17,7 +17,7 @@ # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActiveSupport.on_load(:action_controller) do +ActiveSupport.on_load :action_controller do wrap_parameters format: [:json] end diff --git a/bookshelf/config/routes.rb b/bookshelf/config/routes.rb index be9781b9..b63e78b8 100644 --- a/bookshelf/config/routes.rb +++ b/bookshelf/config/routes.rb @@ -12,7 +12,6 @@ # limitations under the License. Rails.application.routes.draw do - # Route root of application to BooksController#index action root "books#index" @@ -21,5 +20,4 @@ get "/logs", to: "stackdriver#logs" get "/errors", to: "stackdriver#errors" - end diff --git a/gce/Gemfile b/gce/Gemfile index cc0b14e2..91d27464 100644 --- a/gce/Gemfile +++ b/gce/Gemfile @@ -2,6 +2,4 @@ source "https://rubygems.org" -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } - gem "sinatra", "~> 2.0" diff --git a/rakelib/link_checker.rb b/rakelib/link_checker.rb new file mode 100644 index 00000000..d1b5f49f --- /dev/null +++ b/rakelib/link_checker.rb @@ -0,0 +1,64 @@ +require "open3" + +class LinkChecker + def initialize + @failed = false + end + + def run + job_info + git_commit = ENV.fetch "KOKORO_GITHUB_COMMIT", "master" + + markdown_files = Dir.glob "**/*.md" + broken_markdown_links = check_links markdown_files, + "https://github.com/googleapis/signet/tree/#{git_commit}", + " --skip '^(?!(\\Wruby.*google|.*google.*\\Wruby|.*cloud\\.google\\.com))'" + + broken_devsite_links = check_links ["signet"], + "https://googleapis.dev/ruby", + "/latest/ --recurse --skip https:.*github.*" + + puts_broken_links broken_markdown_links + puts_broken_links broken_devsite_links + end + + def check_links location_list, base, tail + broken_links = Hash.new { |h, k| h[k] = [] } + location_list.each do |location| + out, err, st = Open3.capture3 "npx linkinator #{base}/#{location}#{tail}" + puts out + unless st.to_i.zero? + @failed = true + puts err + end + checked_links = out.split "\n" + checked_links.select! { |link| link =~ /\[\d+\]/ && !link.include?("[200]") } + unless checked_links.empty? + @failed = true + broken_links[location] += checked_links + end + end + broken_links + end + + def puts_broken_links link_hash + link_hash.each do |location, links| + puts "#{location} contains the following broken links:" + links.each { |link| puts " #{link}" } + puts + end + end + + def job_info + line_length = "Using Ruby - #{RUBY_VERSION}".length + 8 + puts + puts "#" * line_length + puts "### Using Ruby - #{RUBY_VERSION} ###" + puts "#" * line_length + puts + end + + def exit_status + @failed ? 1 : 0 + end +end diff --git a/sessions/acceptance/app_test.rb b/sessions/acceptance/app_test.rb index 5dc39fd6..1877c6ba 100644 --- a/sessions/acceptance/app_test.rb +++ b/sessions/acceptance/app_test.rb @@ -1,4 +1,4 @@ -require File.expand_path "../../test/test_helper.rb", __FILE__ +require File.expand_path "../test/test_helper.rb", __dir__ include Rack::Test::Methods @@ -7,15 +7,15 @@ def app end def firestore - firestore = Google::Cloud::Firestore.new + Google::Cloud::Firestore.new end def col - col = firestore.col "sessions" + firestore.col "sessions" end def docs - docs = col.list_documents + col.list_documents end def delete_all_sessions @@ -37,7 +37,7 @@ def delete_all_sessions it "should display the number of views" do get "/" - assert_match /\d+ views for /, last_response.body + assert_match(/\d+ views for /, last_response.body) end it "should increment the number of views on successive views" do diff --git a/sessions/test/app_test.rb b/sessions/test/app_test.rb index f7f57967..651ea9d8 100644 --- a/sessions/test/app_test.rb +++ b/sessions/test/app_test.rb @@ -1,4 +1,4 @@ -require File.expand_path "../test_helper.rb", __FILE__ +require File.expand_path "test_helper.rb", __dir__ include Rack::Test::Methods @@ -14,7 +14,7 @@ def initialize app, options = {} def find_session _req, session_id return [generate_sid, {}] if session_id.nil? - return session_id, @data[session_id] + [session_id, @data[session_id]] end def write_session _req, session_id, new_session, _opts @@ -30,7 +30,7 @@ def delete_session _req, session_id, _opts describe "app" do before do - @mock_session = lambda do |app, options = {}| + @mock_session = lambda do |app, _options = {}| FirestoreSessionMock.new app, {} end end @@ -41,13 +41,12 @@ def delete_session _req, session_id, _opts greetings = /"Hello World"|"Hallo Welt"|"Ciao Mondo"|"Salut le Monde"|"Hola Mundo"/ assert_match greetings, last_response.body end - end it "should display the number of views" do Rack::Session::FirestoreSession.stub :new, @mock_session do get "/" - assert_match /\d+ views for /, last_response.body + assert_match(/\d+ views for /, last_response.body) end end diff --git a/sessions/test/test_helper.rb b/sessions/test/test_helper.rb index 9a71cf16..1e6d564a 100644 --- a/sessions/test/test_helper.rb +++ b/sessions/test/test_helper.rb @@ -2,4 +2,4 @@ require "minitest/autorun" require "rack/test" -require File.expand_path "../../app.rb", __FILE__ +require File.expand_path "../app.rb", __dir__