Skip to content
Open
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
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ jobs:
with:
go-version: stable

# Needed because gRPC tools does not have a macOS protoc binary
# currently, see https://github.com/grpc/grpc/issues/25755
- name: Install protoc for mac
if: ${{ matrix.os == 'macos-latest' }}
- name: Install protoc
uses: arduino/setup-protoc@v3
with:
version: "23.x"
version: "34.x"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Install bundle
Expand All @@ -76,8 +73,7 @@ jobs:
if: ${{ matrix.checkTarget }}
working-directory: ./temporalio
run: |
bundle exec rake proto:generate
[[ -z $(git status --porcelain lib/temporalio/api) ]] || (git diff lib/temporalio/api; echo "Protos changed" 1>&2; exit 1)
bundle exec rake proto:check_generated

- name: Lint, compile, test Ruby
working-directory: ./temporalio
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,7 @@ Prerequisites:

* [Ruby](https://www.ruby-lang.org/) >= 3.2 (i.e. `ruby` and `bundle` on the `PATH`)
* [Rust](https://www.rust-lang.org/) latest stable (i.e. `cargo` on the `PATH`)
* [protoc](https://protobuf.dev/installation/) >= 34.0 (i.e. `protoc` on the `PATH`)
* This repository, cloned recursively
* Change to the `temporalio/` directory

Expand Down Expand Up @@ -1416,3 +1417,6 @@ Now can run `steep`:
Run:

bundle exec rake proto:generate

`proto:generate` now requires `protoc >= 34.0` because we generate RBS alongside the generated Ruby
protobuf files.
1 change: 0 additions & 1 deletion temporalio/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ group :development do
gem 'async'
gem 'base64'
gem 'googleapis-common-protos-types'
gem 'grpc-tools', '~> 1.69'
gem 'irb'
gem 'minitest'
# Have to explicitly depend on openssl for macos issue in GH CI described at
Expand Down
25 changes: 12 additions & 13 deletions temporalio/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/**/*_test.rb']
end

def add_protoc_to_path
tools_spec = Gem::Specification.find_by_name('grpc-tools')
cpu = RbConfig::CONFIG['host_cpu']
cpu = 'x86_64' if cpu == 'x64'
os = RbConfig::CONFIG['host_os']
os = 'windows' if os.start_with?('mingw')
protoc_path = "#{tools_spec.gem_dir}/bin/#{cpu}-#{os}"
separator = os == 'windows' ? ';' : ':'
ENV['PATH'] = "#{ENV.fetch('PATH', nil)}#{separator}#{protoc_path}"
end

add_protoc_to_path

require 'rubocop/rake_task'

RuboCop::RakeTask.new
Expand Down Expand Up @@ -75,6 +62,18 @@ namespace :proto do
require_relative 'extra/proto_gen'
ProtoGen.new.run
end

desc 'Fail if checked-in generated proto files are out of date'
task check_generated: :generate do
require_relative 'extra/proto_gen'
proto_generated_paths = ProtoGen.generated_paths

changed_paths = IO.popen(['git', 'status', '--porcelain', '--', *proto_generated_paths], &:read)
next if changed_paths.empty?

sh 'git', 'diff', '--', *proto_generated_paths
raise 'Protos changed'
end
end

namespace :rbs do
Expand Down
5 changes: 1 addition & 4 deletions temporalio/Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
D = Steep::Diagnostic

common_diagnostics = {
# TODO(cretz): Needed because lack of proto RBS, waiting on https://github.com/protocolbuffers/protobuf/pull/15633
D::Ruby::UnknownConstant => :information,

# Steep >= 1.9 started becoming too noisy in these cases
D::Ruby::UnannotatedEmptyCollection => :information,
D::Ruby::UndeclaredMethodDefinition => :information
Expand All @@ -14,7 +11,6 @@ common_diagnostics = {
target :lib do
signature 'sig'
check 'lib'
ignore 'lib/temporalio/api', 'lib/temporalio/internal/bridge/api'
library 'uri', 'objspace', 'etc'
configure_code_diagnostics do |hash|
hash.update(common_diagnostics)
Expand All @@ -27,6 +23,7 @@ target :test do
library 'uri', 'objspace', 'etc'
configure_code_diagnostics do |hash|
hash.update(common_diagnostics)
hash[D::Ruby::UnknownConstant] = :information
# Steep cannot infer some things, so we can ignore them in tests
hash[D::Ruby::InsufficientKeywordArguments] = :information
end
Expand Down
55 changes: 48 additions & 7 deletions temporalio/extra/payload_visitor_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ class PayloadVisitorGen
#
# @return [String] File code.
def gen_file_code
# Collect all the methods of all the classes
methods = {}
DESCRIPTORS.each do |name|
desc = Google::Protobuf::DescriptorPool.generated_pool.lookup(name) or raise "Unknown name: #{name}"
walk_desc(desc:, methods:)
end
methods = payload_methods

# Build the code for each method
method_bodies = methods.map do |_, method_hash|
Expand Down Expand Up @@ -108,7 +103,7 @@ def initialize(
# @param value [Google::Protobuf::Message] Message to visit.
def run(value)
return unless value.is_a?(Google::Protobuf::MessageExts)
method_name = method_name_from_proto_name(value.class.descriptor.name)
method_name = method_name_from_proto_name(value.class.descriptor.name) # steep:ignore NoMethod
send(method_name, value) if respond_to?(method_name, true)
nil
end
Expand Down Expand Up @@ -158,8 +153,54 @@ def google_protobuf_any(value)
TEXT
end

# Generate file signature.
#
# @return [String] File signature.
def gen_rbs_code
method_defs = payload_methods.filter_map do |_, method_hash|
next if method_hash[:fields].empty?

"def #{method_name_from_desc(method_hash[:desc])}: (untyped value) -> void"
end.sort

<<~TEXT
module Temporalio
module Api
class PayloadVisitor
def initialize: (
?on_enter: untyped,
?on_exit: untyped,
?skip_search_attributes: bool,
?traverse_any: bool
) { (untyped) -> untyped } -> void
def run: (untyped value) -> nil
def _run_activation: (untyped value) -> void
def _run_activation_completion: (untyped value) -> void

private

def method_name_from_proto_name: (::String name) -> ::String
def api_common_v1_payload: (untyped value) -> untyped
def api_common_v1_payload_repeated: (untyped value) -> untyped
def google_protobuf_any: (untyped value) -> void
#{method_defs.join("\n ")}
end
end
end
TEXT
end

private

def payload_methods
methods = {}
DESCRIPTORS.each do |name|
desc = Google::Protobuf::DescriptorPool.generated_pool.lookup(name) or raise "Unknown name: #{name}"
walk_desc(desc:, methods:)
end
methods
end

def walk_desc(desc:, methods:)
case desc
when Google::Protobuf::ServiceDescriptor
Expand Down
Loading
Loading