Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: collectiveidea/protoc-gen-twirp_ruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.1.1
Choose a base ref
...
head repository: collectiveidea/protoc-gen-twirp_ruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on May 24, 2024

  1. Add local rake task for regenerating the example code

    Rather than having to try and remember or look up the command to run code generation for the example, hit the easy button and create a simple rake task for it.
    darronschall committed May 24, 2024
    Copy the full SHA
    a87b6cb View commit details
  2. Copy the full SHA
    c4466f8 View commit details
  3. Copy the full SHA
    cde8adc View commit details
  4. Copy the full SHA
    0383f40 View commit details
  5. Copy the full SHA
    6a32a0d View commit details
  6. Split out rspec and standardrb GitHub actions

    By keeping these separate, we can more easily tell at-a-glance what is causing a GitHub action failure.
    
    This also allows the `spec` and `standard` rake tasks to run in parallel as separate actions. Previously, the combined action simply ran `rake` which would run specs and then only ran standard when specs passed.
    darronschall committed May 24, 2024
    Copy the full SHA
    d2e36bb View commit details
  7. Add additional Rubies to spec action

    Given our gemspec defines Ruby >= 3.0, let's ensure that's actually true by running our specs across all support versions.
    darronschall committed May 24, 2024
    Copy the full SHA
    30cc380 View commit details
  8. Update CHANGELOG.md

    darronschall committed May 24, 2024
    Copy the full SHA
    e62f634 View commit details
  9. Copy the full SHA
    555c424 View commit details
  10. Copy the full SHA
    6dedff2 View commit details
  11. Merge pull request #37 from collectiveidea/split-spec-and-standard-ac…

    …tions
    
    GitHub Action improvements
    darronschall authored May 24, 2024
    Copy the full SHA
    aae22e5 View commit details
  12. Add simplecov gem for development

    Don't forget to `rm Gemfile.lock && bundle install`
    darronschall committed May 24, 2024
    Copy the full SHA
    f479441 View commit details
  13. Run specs with coverage when COVERAGE is truthy

    We default to not running with coverage to speed up the suite. To run with coverage locally, use:
    
    ```
    COVERAGE=true bundle exec rake spec
    ```
    darronschall committed May 24, 2024
    Copy the full SHA
    757022b View commit details
  14. Copy the full SHA
    67f478a View commit details
  15. Merge pull request #38 from collectiveidea/add-simplecov-and-code-cli…

    …mate
    
    Add simplecov dev dependency and integrate Code Climate
    darronschall authored May 24, 2024
    Copy the full SHA
    04013d2 View commit details
  16. Copy the full SHA
    2ffc7a5 View commit details
  17. Merge pull request #39 from collectiveidea/add-test-coverage-badge

    Add test coverage badge to README.md
    darronschall authored May 24, 2024
    Copy the full SHA
    328e071 View commit details

Commits on May 28, 2024

  1. Copy the full SHA
    a711ee4 View commit details
  2. Delete custom "be empty scaffolding" matcher

    The plugin never generates empty scaffolding anymore. As such, we no longer need our custom matcher to validate the empty scaffolding content.
    darronschall committed May 28, 2024
    Copy the full SHA
    e4f8100 View commit details
  3. Deprecate and warn on skip-empty flag.

    This is now the default behavior.
    darronschall committed May 28, 2024
    Copy the full SHA
    dd26ed5 View commit details
  4. Copy the full SHA
    c2db72e View commit details
  5. Update CHANGELOG.md

    darronschall committed May 28, 2024
    Copy the full SHA
    707a597 View commit details
  6. Remove skip-empty warning; error instead.

    Rather than a soft deprecation here over two releases, we remove recognizing the flag entirely.
    
    The migration path is small/easy for this change (updating the command to simply remove the option), and we don't have a very large user base at the moment.
    darronschall committed May 28, 2024
    Copy the full SHA
    ba15374 View commit details
  7. Merge pull request #40 from collectiveidea/make-skip-empty-the-defaul…

    …t-and-remove-flag
    
    Make `skip-empty` the default behavior and deprecate option
    darronschall authored May 28, 2024
    Copy the full SHA
    739e63f View commit details
  8. Add #to_anchor String extension

    This will convert a string into an URL HREF anchor. Specifically, we anticipate using this for headings in GitHub markdown files to construct links to those headings.
    darronschall committed May 28, 2024
    Copy the full SHA
    04f3ebf View commit details
  9. Add release:latest_github_release task

    Requires installing the `gh` CLI. Gets the latest release from GitHub and outputs the version to STDOUT.
    darronschall committed May 28, 2024
    Copy the full SHA
    545fa32 View commit details
  10. Add release:create_github_release task

    Leverages the `gh` CLI to create a release. This uses the same command that we specified in the README for releasing, but programmatically determines the version to specify and automatically crafts the proper release notes (linking to the CHANGELOG and the diff view).
    darronschall committed May 28, 2024
    Copy the full SHA
    38bc660 View commit details
  11. Override default gem release task

    We don't want the `release:rubygem_push` task to execute at all. Previously we used `gem_push=no bundle exec rake release` for this.. but since we're customize `release` to _also_ create a GitHub release, let's just remove the RubyGem push to it will never accidentally trigger if someone forgets the `gem_push=no` ENV var.
    darronschall committed May 28, 2024
    Copy the full SHA
    ae40231 View commit details
  12. Simplify README.md release instructions.

    Our `rake release` task override does everything we need for release now. There are no more manual steps.
    darronschall committed May 28, 2024
    Copy the full SHA
    b0ff5ea View commit details
  13. Update CHANGELOG.md

    darronschall committed May 28, 2024
    Copy the full SHA
    7ed83a3 View commit details

Commits on May 29, 2024

  1. Merge pull request #41 from collectiveidea/streamline-release-task

    Streamline gem release with bundler gem task release override
    darronschall authored May 29, 2024
    Copy the full SHA
    891adce View commit details
  2. Bump version to 1.2.0

    darronschall committed May 29, 2024
    Copy the full SHA
    5506401 View commit details
  3. Update CHANGELOG.md

    darronschall committed May 29, 2024
    Copy the full SHA
    80ce8b4 View commit details
  4. bundle exec rake example

    darronschall committed May 29, 2024
    Copy the full SHA
    751d48a View commit details
  5. Copy the full SHA
    f9d6d9f View commit details
  6. Tweak publish action to only build and push

    Previously the action was running `bundle exec rake release`, which was doing too much.
    
    The GitHub publish_gem action automatically runs when a release tag is pushed. The only thing the action should do is build the gem and publish to RubyGems.
    darronschall committed May 29, 2024
    Copy the full SHA
    3b87e66 View commit details
  7. Copy the full SHA
    df8bb61 View commit details
  8. Merge pull request #43 from collectiveidea/tweak-github-publish-action

    Tweak publish action to only build and push
    darronschall authored May 29, 2024
    Copy the full SHA
    e9e2b69 View commit details
7 changes: 5 additions & 2 deletions .github/workflows/buildlight.yml
Original file line number Diff line number Diff line change
@@ -2,8 +2,11 @@ name: Buildlight

on:
workflow_run:
workflows: [Ruby]
branches: [main]
workflows:
- rspec
- standardrb
branches:
- main

jobs:
buildlight:
28 changes: 0 additions & 28 deletions .github/workflows/main.yml

This file was deleted.

7 changes: 5 additions & 2 deletions .github/workflows/publish_gem.yml
Original file line number Diff line number Diff line change
@@ -24,5 +24,8 @@ jobs:
bundler-cache: true
ruby-version: ruby

# Release
- uses: rubygems/release-gem@v1
- name: Configure trusted publishing credentials
uses: rubygems/configure-rubygems-credentials@v1.0.0

- name: Build and Release to RubyGems
run: bundle exec rake build release:rubygem_push
46 changes: 46 additions & 0 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: rspec

on:
push:
branches:
- main

pull_request:

jobs:
build:
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
COVERAGE: true

runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3.1'

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
cache-version: 1

- name: Setup Code Climate Test Reporter
run: |
sudo curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
sudo chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: Run RSpec
run: bundle exec rake spec

- name: Coverage Report
run: |
./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
23 changes: 23 additions & 0 deletions .github/workflows/standardrb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: standardrb

on:
push:
branches:
- main

pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3.1
bundler-cache: true
cache-version: 1
- name: Run Standard Ruby
run: bundle exec rake standard
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- No notable changes since last release

## [1.2.0] - 2024-05-29

- Streamline gem release with rake task - [#41](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/41)
- Make `skip-empty` the default behavior; remove recognizing the option flag - [#40](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/40)
- Update GitHub action to run specs on all supported Ruby versions - [#37](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/37)

## [1.1.1] - 2024-05-22

- Remove unnecessary `racc` runtime dependency - [#33](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/33)
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![Gem Version](https://img.shields.io/gem/v/protoc-gen-twirp_ruby.svg)](https://rubygems.org/gems/protoc-gen-twirp_ruby)
[![Build](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/main.yml/badge.svg)](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/main.yml)
[![Specs](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/rspec.yml/badge.svg)](https://github.com/collectiveidea/protoc-gen-twirp_ruby/actions/workflows/rspec.yml)
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)
[![Test Coverage](https://api.codeclimate.com/v1/badges/a0020a73103eedbe760c/test_coverage)](https://codeclimate.com/github/collectiveidea/protoc-gen-twirp_ruby/test_coverage)

# protoc-gen-twirp_ruby - A `protoc` plugin for Twirp-Ruby.

@@ -52,18 +53,16 @@ protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. ./path/to/service.proto

You can configure the code generation. Pass options by specifying `--twirp_ruby_opt=<option>` on the `protoc` command line.

* `skip-empty`: Avoid generating a `_twirp.rb` for a `.proto` with no service definitions. By default, a `_twirp.rb`
file is generated for every proto file listed on the command line, even if the file is empty scaffolding.
* `generate=<service|client|both>`: Customize generated output to include generated services, clients, or both.
* `generate=service` - only generate `::Twirp::Service` subclass(es).
* `generate=client` - only generate `::Twirp::Client` subclass(es).
* `generate=both` - generate both services and clients. This is the default option to preserve
backwards compatibility.
* `generate=<service|client|both>`: Customize generated output to include generated services, clients, or both. Optional,
defaults to both to preserve backwards compatibility.
* `generate=service` - only generate `::Twirp::Service`s.
* `generate=client` - only generate `::Twirp::Client`s.
* `generate=both` - default; generate both services and clients.

Example (with two options):
Example :

```bash
protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --twirp_ruby_opt=generate=client --twirp_ruby_opt=skip-empty ./path/to/service.proto
protoc --proto_path=. --ruby_out=. --twirp_ruby_out=. --twirp_ruby_opt=generate=client ./path/to/service.proto
```

## Migrating from the Go module
@@ -83,20 +82,20 @@ that might affect migration include:
* Generated output code is in [standardrb style](https://github.com/standardrb/standard).
* Generated service and client class names are improved for well-named protobuf services. See [#6](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/6).
* Supports `ruby_package` in `.proto` files
* Supports various protoc command line [configuration options](https://github.com/collectiveidea/protoc-gen-twirp_ruby?tab=readme-ov-file#options).

* Supports protoc command line [configuration options](#options).

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

For continued development purposes, we can route `protoc` to the local repo code for the plugin and generate against the example via:
To experiment with development changes, route `protoc` to the local plugin when generating code
via the `--plugin=protoc-gen-twirp_ruby=./exe/protoc-gen-twirp_ruby` option. For example:

```bash
protoc --plugin=protoc-gen-twirp_ruby=./exe/protoc-gen-twirp_ruby --ruby_out=. --twirp_ruby_out=. ./example/hello_world.proto
```

The local code for the gem can also be installed via `bundle exec rake install` to omit the `--plugin=protoc-gen-twirp_ruby=` option from `protoc`:
Alternatively, install the local gem before invoking `protoc`:

```bash
bundle exec rake install
@@ -105,20 +104,16 @@ protoc --ruby_out=. --twirp_ruby_out=. ./example/hello_world.proto

## Releasing

Install the [GitHub CLI](https://cli.github.com): `brew install gh` or [follow the instructions](https://github.com/cli/cli#installation).

To release a new version:

* Submit a PR with the following changes (see [#30](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/30)):
* Submit a PR with the following changes (see e.g. [#30](https://github.com/collectiveidea/protoc-gen-twirp_ruby/pull/30)):
* Update the version number in `version.rb`
* Update the CHANGELOG.md
* Create a section for the new version and move the unreleased version there
* Re-generate the example:
* `protoc --plugin=protoc-gen-twirp_ruby=./exe/protoc-gen-twirp_ruby --ruby_out=. --twirp_ruby_out=. ./example/hello_world.proto`
* Once merged, run the release task from main. Note that we prepend `gem_push=no` to avoid
pushing to RubyGems directly; our GitHub publish action will do this for us.
* `gem_push=no bundle exec rake release`
* Create a GitHub release:
* `gh release create v<version>`
* Edit the release notes to link to the notes in the CHANGELOG.md for the version
* Create a section for the new version and move the unreleased version there
* Re-generate the example: `bundle exec rake example`
* Once merged and `main` is up-to-date, run `bundle exec rake release`.

## Contributing

4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -7,4 +7,8 @@ RSpec::Core::RakeTask.new(:spec)

require "standard/rake"

# Load development-only rake tasks. There are in `tasks/` and not
# `lib/tasks/` because we don't want to ship them with the gem.
Rake.add_rakelib "tasks"

task default: %i[spec standard]
2 changes: 1 addition & 1 deletion example/hello_world_twirp.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Generated by the protoc-gen-twirp_ruby gem v1.1.1. DO NOT EDIT!
# Generated by the protoc-gen-twirp_ruby gem v1.2.0. DO NOT EDIT!
# source: example/hello_world.proto

require "twirp"
8 changes: 1 addition & 7 deletions lib/twirp/protoc_plugin/code_generator.rb
Original file line number Diff line number Diff line change
@@ -10,9 +10,7 @@ module ProtocPlugin
class CodeGenerator
# @param proto_file [Google::Protobuf::FileDescriptorProto]
# @param relative_ruby_protobuf [String] e.g. "example_rb.pb"
# @param options [Hash{Symbol => Boolean, Symbol}]
# * :skip_empty [Boolean] indicating whether generation should skip creating a twirp file
# for proto files that contain no services.
# @param options [Hash{Symbol => Symbol}]
# * :generate [Symbol] one of: :service, :client, or :both.
def initialize(proto_file, relative_ruby_protobuf, options)
@proto_file = proto_file
@@ -42,10 +40,6 @@ def generate
indent_level += 1
end

unless @proto_file.has_service?
output << line("# No services found; To skip generating this file, specify `--twirp_ruby_opt=skip-empty`.", indent_level)
end

@proto_file.service.each_with_index do |service, index| # service: <Google::Protobuf::ServiceDescriptorProto>
# Add newline between definitions when multiple are generated
output << "\n" if index > 0
14 changes: 14 additions & 0 deletions lib/twirp/protoc_plugin/core_ext/string/to_anchor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

class String
# Converts the string to an acceptable URL anchor.
#
# Thw rules for GitHub markdown links are:
# - force lowercase
# - strip punctuation
# - replace spaces with dashes
# @return [String] the string converted to an acceptable URL anchor
def to_anchor
downcase.gsub(/[^a-z0-9_ -]/, "").tr(" ", "-")
end
end
23 changes: 9 additions & 14 deletions lib/twirp/protoc_plugin/process.rb
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ def process(input)

request.proto_file.each do |proto_file| # proto_file: <Google::Protobuf::FileDescriptorProto>
next unless request.file_to_generate.include?(proto_file.name)
next if options[:skip_empty] && !proto_file.has_service?
next unless proto_file.has_service? # do not generate when no services defined

file = Google::Protobuf::Compiler::CodeGeneratorResponse::File.new
file.name = proto_file.twirp_output_filename
@@ -39,19 +39,19 @@ def process(input)

private

# @param params [String] the parameters from protoc command line in comma-separated stringified
# array format, e.g. "some-flag,key1=value1".
# @param params [String] the parameters from `protoc` command line in comma-separated stringified
# array format, e.g. "some-flag,key1=value1". For repeated command line options, `protoc` will
# add the option multiple times, e.g. "some-flag,key1=value1,key1=twice,key2=value2".
#
# The only valid parameter is currently the optional "skip-empty" flag.
# @return [Hash{Symbol => Boolean, Symbol}]
# * :skip_empty [Boolean] indicating whether generation should skip creating a twirp file
# for proto files that contain no services. Default false.
# The only valid parameter is currently the optional "generate" parameter.
#
# @return Hash{Symbol => Symbol} the extracted options, a Hash that contains:
# * :generate [Symbol] one of: :service, :client, or :both. Default :both.
#
# @raise [ArgumentError] when a required parameter is missing, a parameter value is invalid, or
# an unrecognized parameter is present on the command line
def extract_options(params)
opts = {
skip_empty: false,
generate: :both
}

@@ -60,12 +60,7 @@ def extract_options(params)
# In the event value contains an =, we want to leave that intact.
# Limit the split to just separate the key out.
key, value = param.split("=", 2)
if key == "skip-empty"
unless value.nil? || value.empty?
raise ArgumentError, "Unexpected value passed to skip-empty flag: #{value}"
end
opts[:skip_empty] = true
elsif key == "generate"
if key == "generate"
if value.nil? || value.empty?
raise ArgumentError, "Unexpected missing value for generate option. Please supply one of: service, client, both."
end
2 changes: 1 addition & 1 deletion lib/twirp/protoc_plugin/version.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@

module Twirp
module ProtocPlugin
VERSION = "1.1.1"
VERSION = "1.2.0"
end
end
2 changes: 2 additions & 0 deletions protoc-gen-twirp_ruby.gemspec
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
example/
proto/
spec/
tasks/
.git
.rspec
.standard
@@ -50,6 +51,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rspec-file_fixtures"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "standard"

# For more information and examples about making a new gem, check out our
15 changes: 15 additions & 0 deletions spec/core_ext/string/to_anchor_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "twirp/protoc_plugin/core_ext/string/to_anchor"

RSpec.describe String do
describe "#to_anchor" do
it "converts a string with brackets, numbers, and dates" do
expect("[1.1.1] - 2024-05-22".to_anchor).to eq("111---2024-05-22")
end

it "converts a string with mixed case and backticks" do
expect("Install the `protoc-gen-twirp_ruby` plugin gem".to_anchor).to eq("install-the-protoc-gen-twirp_ruby-plugin-gem")
end
end
end
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 7 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# frozen_string_literal: true

if %w[t true yes y 1].include?(ENV["COVERAGE"])
require "simplecov"
SimpleCov.start do
enable_coverage :branch
end
end

require "rspec/file_fixtures"
require "twirp/protoc_plugin"
require "support/matchers/be_empty_scaffolding_matcher"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Loading