Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
strategy:
matrix:
include:
- os: ubuntu-22.04
ruby: "3.1"
task: test , spec
- os: ubuntu-22.04
ruby: "3.2"
task: test , spec
Expand Down
14 changes: 14 additions & 0 deletions .kokoro/samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ export PATH=$GEM_HOME/bin:$PATH

gem install --no-document toys

# To run acceptance tests for samples, we need the `sample_loader.rb` helper
# from the `googleapis/ruby-common-tools` repository.
#
# Previously, this file was downloaded dynamically at runtime in `helper.rb`
# using `Toys::Utils::GitCache`. However, that approach creates a dependency
# on Toys internal utilities during test execution, which fails when running
# within an isolated bundle (e.g., via Bundler).
#
# To make the tests more robust and independent of the task runner's internal
# state, we explicitly download the helper file here before executing the tests.
# This does not change the testing infrastructure; it only makes the download
# step explicit and reliable.
curl -sSL https://raw.githubusercontent.com/googleapis/ruby-common-tools/main/lib/sample_loader.rb -o samples/acceptance/sample_loader.rb

toys samples < /dev/null
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruby 3.4.9
nodejs 25.9.0
8 changes: 8 additions & 0 deletions .toys/.lib/repo_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@ def self.load_kokoro_env
filename = "#{gfile_dir}/secret_manager/ruby-main-ci-service-account"
raise "#{filename} is not a file" unless ::File.file? filename
::ENV["GOOGLE_APPLICATION_CREDENTIALS"] = filename

# Extract project_id from the key file if available
require "json"
key_data = JSON.parse File.read filename
if key_data["project_id"]
puts "Inferred project_id from keyfile: #{key_data['project_id']}"
::ENV["GOOGLE_CLOUD_PROJECT"] ||= key_data["project_id"]
end
end
end
40 changes: 24 additions & 16 deletions .toys/.toys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,38 @@

expand :clean, paths: :gitignore

expand :rspec do |t|
t.libs = ["lib", "spec"]
t.use_bundler
tool "spec" do
desc "Run RSpec tests"
include :exec
def run
exec ["bundle", "exec", "rspec"]
end
end

expand :minitest do |t|
t.libs = ["lib", "test"]
t.use_bundler
t.files = "test/**/*_test.rb"
tool "test" do
desc "Run unit tests"
include :exec
def run
exec ["bundle", "exec", "ruby", "-Ilib", "-Itest", "-e", "Dir.glob('test/**/*_test.rb').each{|f| require File.expand_path(f)}"]
end
end

expand :minitest do |t|
t.name = "integration"
t.libs = ["lib", "integration"]
t.use_bundler
t.files = "integration/**/*_test.rb"
tool "integration" do
desc "Run integration tests"
include :exec
def run
exec ["bundle", "exec", "ruby", "-Ilib", "-Iintegration", "-e", "Dir.glob('integration/**/*_test.rb').each{|f| require File.expand_path(f)}"]
end
end

expand :rubocop, bundler: true

expand :yardoc do |t|
t.generate_output_flag = true
# t.fail_on_warning = true
t.use_bundler
tool "yardoc" do
desc "Generate documentation"
include :exec
def run
exec ["bundle", "exec", "yard", "doc"]
end
end
alias_tool :yard, :yardoc

Expand Down
21 changes: 10 additions & 11 deletions .toys/samples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

expand :minitest do |t|
t.name = "test"
t.libs = ["lib", "samples"]
t.use_bundler on_missing: :install, gemfile_path: "samples/Gemfile"
t.files = "samples/acceptance/*_test.rb"
end

desc "Run samples tests"

include :exec
Expand All @@ -29,8 +22,14 @@ def run
require "repo_context"
RepoContext.load_kokoro_env

Dir.chdir context_directory

puts "Samples tests ...", :bold, :cyan
exec_tool ["samples", "test"], name: "Samples tests"
Dir.chdir File.join(context_directory, "samples") do
puts "Updating samples bundle ...", :bold, :cyan
exec ["bundle", "install"]

puts "Samples tests ...", :bold, :cyan
cmd = ["bundle", "exec", "ruby", "-I../lib", "-Iacceptance", "-e",
"Dir.glob('acceptance/*_test.rb').each{|f| require File.expand_path(f)}"]

exec cmd
end
end
4 changes: 3 additions & 1 deletion samples/acceptance/authenticate_implicit_with_adc_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
# list_buckets
sample = SampleLoader.load "authenticate_implicit_with_adc.rb"

test_project = ENV["GOOGLE_CLOUD_PROJECT"] || storage_client.project

assert_output(/Plaintext: Listed all storage buckets./) do
sample.run project_id: storage_client.project
sample.run project_id: test_project
end
end
end
4 changes: 1 addition & 3 deletions samples/acceptance/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@

require "minitest/autorun"
require "minitest/focus"
require "toys/utils/git_cache"
require Toys::Utils::GitCache.new.get "https://github.com/googleapis/ruby-common-tools.git",
path: "lib/sample_loader.rb", update: 300
require_relative "sample_loader"
Loading