Skip to content

Commit

Permalink
Merge pull request #711 from Homebrew/wip-srb
Browse files Browse the repository at this point in the history
Basic Sorbet `typed: true`
  • Loading branch information
issyl0 authored Aug 19, 2024
2 parents e7fc591 + 1a0684b commit 7d38bfc
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@ jobs:
run: |
rm -rf "$(brew --repo homebrew/services)"
ln -s "$PWD" "$(brew --repo homebrew/services)"
sorbet:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- run: brew typecheck homebrew/services
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ group :test do
gem "activesupport"
gem "rspec"
gem "simplecov"
gem "sorbet-runtime"
end
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
sorbet-runtime (0.5.11528)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
zeitwerk (2.6.17)
Expand All @@ -43,6 +44,7 @@ DEPENDENCIES
activesupport
rspec
simplecov
sorbet-runtime

RUBY VERSION
ruby 3.3.4p94
Expand Down
1 change: 1 addition & 0 deletions cmd/services.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

homebrew_version = if HOMEBREW_VERSION.present?
Expand Down
26 changes: 26 additions & 0 deletions cmd/services.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# typed: strict

class Homebrew::Cmd::Services
sig { returns(Homebrew::Cmd::Services::Args) }
def args; end
end

class Homebrew::Cmd::Services::Args < Homebrew::CLI::Args
sig { returns(T::Boolean) }
def all?; end

sig { returns(T.nilable(String)) }
def file; end

sig { returns(T::Boolean) }
def json?; end

sig { returns(T::Boolean) }
def non_bundler_gems?; end

sig { returns(T::Boolean) }
def no_wait?; end

sig { returns(T.nilable(String)) }
def sudo_service_user; end
end
1 change: 1 addition & 0 deletions lib/service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

$LOAD_PATH.unshift(File.dirname(__FILE__))
Expand Down
6 changes: 6 additions & 0 deletions lib/service.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# typed: strict

module Service
include Kernel
include FileUtils
end
1 change: 1 addition & 0 deletions lib/service/commands/cleanup.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
1 change: 1 addition & 0 deletions lib/service/commands/info.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
1 change: 1 addition & 0 deletions lib/service/commands/kill.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
1 change: 1 addition & 0 deletions lib/service/commands/list.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

require "service/formulae"
Expand Down
1 change: 1 addition & 0 deletions lib/service/commands/restart.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
1 change: 1 addition & 0 deletions lib/service/commands/run.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
1 change: 1 addition & 0 deletions lib/service/commands/start.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
1 change: 1 addition & 0 deletions lib/service/commands/stop.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
3 changes: 2 additions & 1 deletion lib/service/formula_wrapper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

# Wrapper for a formula to handle service-related stuff like parsing and
Expand All @@ -12,7 +13,7 @@ def self.from(path_or_label)
return unless path_or_label =~ path_or_label_regex

begin
new(Formulary.factory(Regexp.last_match(1)))
new(Formulary.factory(T.must(Regexp.last_match(1))))
rescue
nil
end
Expand Down
1 change: 1 addition & 0 deletions lib/service/formulae.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
7 changes: 5 additions & 2 deletions lib/service/services_cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down Expand Up @@ -87,6 +88,8 @@ def self.run(targets, verbose: false)

# Start a service.
def self.start(targets, service_file = nil, verbose: false)
file = T.let(nil, T.nilable(Pathname))

if service_file.present?
file = Pathname.new service_file
raise UsageError, "Provided service file does not exist" unless file.exist?
Expand Down Expand Up @@ -202,7 +205,7 @@ def self.take_root_ownership(service)
return unless System.root?
return if sudo_service_user

root_paths = []
root_paths = T.let([], T::Array[Pathname])

if System.systemctl?
group = "root"
Expand Down Expand Up @@ -320,7 +323,7 @@ def self.install_service_file(service, file)

rm service.dest if service.dest.exist?
service.dest_dir.mkpath unless service.dest_dir.directory?
cp temp.path, service.dest
cp T.must(temp.path), service.dest

# Clear tempfile.
temp.close
Expand Down
1 change: 1 addition & 0 deletions lib/service/system.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: true
# frozen_string_literal: true

module Service
Expand Down
6 changes: 4 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter]

require "sorbet-runtime"

require "bundler"
require "rspec/support/object_formatter"
require "stub/exceptions"
Expand All @@ -35,11 +37,11 @@
end

module Formatter
def self.success(string)
def self.success(string, label: nil)
string
end

def self.error(string)
def self.error(string, label: nil)
string
end
end
Expand Down

0 comments on commit 7d38bfc

Please sign in to comment.