# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require "rbconfig"20require "fileutils"21require "open3"2223# Find the rb directory - try multiple strategies for different Bazel contexts24root = if ENV['BUILD_WORKSPACE_DIRECTORY']25# bazel run sets this to the workspace root26File.join(ENV['BUILD_WORKSPACE_DIRECTORY'], 'rb')27elsif ENV['BUILD_WORKING_DIRECTORY']28# Alternative for some bazel run scenarios29rb_path = File.join(ENV['BUILD_WORKING_DIRECTORY'], 'rb')30File.exist?(rb_path) ? rb_path : File.expand_path("../..", __dir__)31else32# Direct execution or other scenarios - find rb relative to script33script_dir = File.expand_path(__dir__)34if script_dir.include?('runfiles')35# In bazel test, try to find the actual workspace36# Look for the workspace by finding where Gemfile exists37workspace = script_dir.split('runfiles').first.sub(%r{/bazel-out/.*}, '')38File.join(workspace, 'rb')39else40File.expand_path("../..", __dir__)41end42end4344Dir.chdir(root)4546ruby = RbConfig.ruby4748# Clear GIT_DIR to prevent it from interfering with RBS collection git operations49# (e.g., when running via git pre-push hook which sets GIT_DIR)50ENV.delete('GIT_DIR')5152# Install RBS collection from lockfile (--frozen skips Gemfile.lock validation)53system(ruby, "-S", "rbs", "collection", "install", "--frozen") || exit(1)5455# Run steep check, discarding stderr (internal Steep logs, not type errors)56cmd = [ruby, "-S", "steep", "check", "--severity-level=error", *ARGV]57stdout, status = Open3.capture2(*cmd, err: File::NULL)5859print stdout60exit status.exitstatus616263