diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 898ff513..0ad0c501 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.kokoro/samples.sh b/.kokoro/samples.sh index a8b79b98..50ae3929 100755 --- a/.kokoro/samples.sh +++ b/.kokoro/samples.sh @@ -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 diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 00000000..e9ba0338 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +ruby 3.4.9 +nodejs 25.9.0 diff --git a/.toys/.lib/repo_context.rb b/.toys/.lib/repo_context.rb index 9ffe6776..bde035e6 100644 --- a/.toys/.lib/repo_context.rb +++ b/.toys/.lib/repo_context.rb @@ -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 diff --git a/.toys/.toys.rb b/.toys/.toys.rb index 28395037..9f76ff2a 100644 --- a/.toys/.toys.rb +++ b/.toys/.toys.rb @@ -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 diff --git a/.toys/samples.rb b/.toys/samples.rb index dbee686e..bb0fa013 100644 --- a/.toys/samples.rb +++ b/.toys/samples.rb @@ -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 @@ -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 diff --git a/samples/acceptance/authenticate_implicit_with_adc_test.rb b/samples/acceptance/authenticate_implicit_with_adc_test.rb index e67dc193..437b151b 100644 --- a/samples/acceptance/authenticate_implicit_with_adc_test.rb +++ b/samples/acceptance/authenticate_implicit_with_adc_test.rb @@ -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 diff --git a/samples/acceptance/helper.rb b/samples/acceptance/helper.rb index 443d7a55..486341ac 100644 --- a/samples/acceptance/helper.rb +++ b/samples/acceptance/helper.rb @@ -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"