Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorbet integration #310

Merged
merged 10 commits into from
Mar 14, 2024
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
31 changes: 31 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,37 @@ jobs:
- name: RSpec run
run: bundle exec rspec

typecheck:
runs-on: ubuntu-20.04
strategy:
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Update Ubuntu package repository
run: sudo apt-get update
- name: Setup sqlite-devel
run: sudo apt-get -y install libsqlite3-dev
- name: Setup libcurl-devel
run: sudo apt-get -y install libcurl4 libcurl3-gnutls libcurl4-openssl-dev

- name: Set up Ruby 3.1.4
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.4
bundler-cache: false

- name: Install dependencies
run: bundle install

- name: Check for out-of-date RBIs
run: bundle exec tapioca gems --verify

- name: Run sorbet type check
run: bundle exec srb typecheck

rubocop:
runs-on: ubuntu-20.04
strategy:
Expand Down
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ gem 'openssl', require: false
gem 'rtoolsHCK', git: 'https://github.com/HCK-CI/rtoolsHCK.git', tag: 'v0.4.0'
gem 'rubyzip'
gem 'sentry-ruby'
gem 'sorbet-runtime'
gem 'sqlite3'

group :development, :test do
gem 'sorbet', require: false
gem 'tapioca', require: false
end

group :test do
gem 'code-scanning-rubocop'
gem 'jtd'
Expand Down
43 changes: 39 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ GEM
logging (2.3.1)
little-plugger (~> 1.1)
multi_json (~> 1.14)
mini_portile2 (2.8.4)
minitest (5.21.2)
mono_logger (1.1.2)
multi_json (1.15.0)
multi_xml (0.6.0)
mutex_m (0.2.0)
net-http (0.4.1)
uri
netrc (0.11.0)
nori (2.6.0)
oauth2 (1.4.11)
faraday (>= 0.17.3, < 3.0)
Expand All @@ -87,12 +87,17 @@ GEM
parser (3.3.0.5)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
prism (0.24.0)
psych (5.1.0)
stringio
public_suffix (5.0.4)
racc (1.7.3)
rack (3.0.6.1)
rainbow (3.1.1)
rbi (0.1.9)
prism (>= 0.18.0, < 0.25)
sorbet-runtime (>= 0.5.9204)
rdoc (6.5.0)
psych (>= 4.0.0)
regexp_parser (2.9.0)
Expand Down Expand Up @@ -137,9 +142,32 @@ GEM
sentry-ruby-core (4.7.1)
concurrent-ruby
faraday
sqlite3 (1.6.6)
mini_portile2 (~> 2.8.0)
sorbet (0.5.11264)
sorbet-static (= 0.5.11264)
sorbet-runtime (0.5.11264)
sorbet-static (0.5.11264-x86_64-linux)
sorbet-static-and-runtime (0.5.11264)
sorbet (= 0.5.11264)
sorbet-runtime (= 0.5.11264)
spoom (1.2.4)
erubi (>= 1.10.0)
sorbet-static-and-runtime (>= 0.5.10187)
syntax_tree (>= 6.1.1)
thor (>= 0.19.2)
sqlite3 (1.6.6-x86_64-linux)
stringio (3.0.8)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
tapioca (0.12.0)
bundler (>= 2.2.25)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
rbi (>= 0.1.4, < 0.2)
sorbet-static-and-runtime (>= 0.5.10820)
spoom (~> 1.2.0, >= 1.2.0)
thor (>= 1.2.0)
yard-sorbet
thor (1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand All @@ -158,9 +186,13 @@ GEM
logging (>= 1.6.1, < 3.0)
rubyzip (~> 2.0)
winrm (~> 2.0)
yard (0.9.34)
yard-sorbet (0.8.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
activesupport
Expand All @@ -178,7 +210,10 @@ DEPENDENCIES
rubocop
rubyzip
sentry-ruby
sorbet
sorbet-runtime
sqlite3
tapioca

RUBY VERSION
ruby 3.1.4p223
Expand Down
3 changes: 1 addition & 2 deletions bin/auto_hck
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'bundler/setup'
require 'dotenv/load'
require './lib/config/sentry'
require 'sorbet-runtime'

begin
require 'filelock'
Expand All @@ -19,8 +20,6 @@ begin

ENV.store 'LC_ALL', 'en_US.UTF-8'

AUTOHCK_RETRIES = 5

Trap.init_traps(%w[TERM INT])

Thread.abort_on_exception = true
Expand Down
12 changes: 10 additions & 2 deletions lib/auxiliary/json_helper.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
# typed: false
# frozen_string_literal: true

require 'active_support'
require 'active_support/core_ext/hash/deep_merge'
require 'json'
require 'fileutils'
require 'sorbet-runtime'
require './lib/exceptions'
require './lib/auxiliary/multi_logger'

# AutoHCK module
module AutoHCK
# Helper module
module Helper
# Json class
class Json
extend T::Sig

@json_override_file = 'override.json'

def self.update_json_override(json_file)
@json_override_file = json_file
end

def self.read_json(json_file, logger)
sig do
params(json_file: String, logger: T.nilable(T.any(MultiLogger, ::Logger))).returns(T::Hash[String, T.untyped])
akihikodaki marked this conversation as resolved.
Show resolved Hide resolved
end
def self.read_json(json_file, logger = nil)
data = JSON.parse(File.read(json_file))

if File.exist?(@json_override_file)
Expand All @@ -28,7 +36,7 @@ def self.read_json(json_file, logger)

data
rescue Errno::ENOENT, JSON::ParserError
logger.fatal("Could not open #{json_file} file")
logger&.fatal("Could not open #{json_file} file")
raise OpenJsonError, "Could not open #{json_file} file"
end
end
Expand Down
17 changes: 10 additions & 7 deletions lib/engines/hckinstall/hckinstall.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

require 'uri'
Expand All @@ -10,6 +11,8 @@
require './lib/auxiliary/resource_scope'
require './lib/engines/hckinstall/setup_scripts_helper'

require './lib/models/driver'

# AutoHCK module
module AutoHCK
# HCKInstall class
Expand Down Expand Up @@ -153,7 +156,7 @@ def read_driver(driver)
driver_json = "#{DRIVERS_JSON_DIR}/#{driver}.json"

@logger.info("Loading driver: #{driver}")
Json.read_json(driver_json, @logger)
Models::Driver.from_json_file(driver_json, @logger)
rescue Errno::ENOENT
@logger.fatal("#{driver} does not exist")
raise(InvalidConfigFile, "#{driver} does not exist")
Expand All @@ -163,7 +166,7 @@ def find_drivers
@project.options.install.drivers.map do |short_name|
driver = read_driver(short_name)

driver['short'] = short_name
driver.short = short_name

driver
end
Expand All @@ -174,14 +177,15 @@ def drivers

@need_copy_drivers = false
drivers.each do |driver|
next if driver['install_method'] == 'no-drv'
next if driver.install_method == Models::DriverInstallMethods::NoDrviver

if driver['install_method'] == 'PNP' && File.exist?("#{@project.options.install.driver_path}/#{driver['inf']}")
if driver.install_method == Models::DriverInstallMethods::PNP &&
File.exist?("#{@project.options.install.driver_path}/#{driver.inf}")
@need_copy_drivers = true
next
end

msg = "Can't install #{driver['short']} driver for device #{driver['device']} in install mode"
msg = "Can't install #{driver.short} driver for device #{driver.device} in install mode"
@project.logger.fatal(msg)
raise(InvalidConfigFile, msg)
end
Expand Down Expand Up @@ -364,8 +368,7 @@ def copy_drivers
@logger.info('HCKInstall: Copy all drivers')
FileUtils.rm_rf("#{@hck_setup_scripts_path}/drivers")
FileUtils.copy_entry(@project.options.install.driver_path,
"#{@hck_setup_scripts_path}/drivers",
remove_destination: true)
"#{@hck_setup_scripts_path}/drivers")
end

def prepare_client_drives
Expand Down
Loading
Loading