Skip to content

Commit

Permalink
[CI] Run tests in Windows runner too (#8)
Browse files Browse the repository at this point in the history
* [CI] Run tests in Windows runner too

* Test only with 2.7

* Install google-protobuf  gem

* Pin protoc version to 3.17.3

* Pin protoc version to 3.17.3

* Fix type extraction for latest protoc versions

* Fix type extraction for latest protoc versions

* Install latest google-protobuf gem

* Test with Ruby 2.7 only

* Install latest google-protobuf

* Test on Windows only

* Enable ubnutu and macos runners

* Test with all combinations

* Test with Ruby 2.6 and 2.7

* Install protoc according to Ruby version

* Install protoc according to Ruby version

* Install protoc according to Ruby version

* Install protoc according to Ruby version

* Install protoc according to Ruby version

* Install protoc according to Ruby version

* Remove Ruby 3.5

* Test wirh Ruby 2.7 only

* Add Known Issues section

* Print msg types in verbose info

* Remove commented config
  • Loading branch information
iamazeem committed Aug 11, 2023
1 parent ce464e5 commit 7ef273e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,32 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ruby-version: ['2.6', '2.7']
ruby-version: ['2.7']

runs-on: ${{ matrix.os }}

steps:
- name: Checkout [${{ github.repository }}]
uses: actions/checkout@v3

- name: Set up Ruby ${{ matrix.ruby-version }}
- name: Set up Ruby [${{ matrix.ruby-version }}]
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Install protoc
uses: arduino/setup-protoc@master
uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build and install
shell: bash
run: |
gem build *.gemspec
gem install *.gem
proto-convert -h
proto-convert --help
- name: Run tests [${{ matrix.os }}]
if: ${{ runner.os != 'Windows' }}
shell: bash
run: cd test && ./run_tests.sh
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
to convert [protobuf](https://github.com/protocolbuffers/protobuf) messages
from binary to [JSON](https://www.json.org/json-en.html) and vice versa.

[Tested](./test/run_tests.sh) on Ubuntu and macOS.
For details, please see [CI workflow](./.github/workflows/ci.yml).
[Tested](./test/run_tests.sh) on Ubuntu, macOS and Windows runners.
For details, see [CI workflow](./.github/workflows/ci.yml).

## Installation

Expand Down Expand Up @@ -86,6 +86,12 @@ $ cat test.json
{"id":123,"body":"test"}
```

## Known Issues

- It has been observed that the installed `protoc` and `google-protobuf` gem
may be incompatible and may result into compilation failure of the `input`
file.

## Contribute

- [Fork](https://github.com/iamazeem/proto-convert/fork) the project.
Expand Down
29 changes: 13 additions & 16 deletions bin/proto-convert
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
require 'optparse'
require 'English'

VERSION = '0.4.0'
VERSION = '0.4.1'
AUTHOR_NAME = 'Azeem Sajid'
AUTHOR_EMAIL = '<azeem.sajid@gmail.com>'
AUTHOR_INFO = "Author: #{AUTHOR_NAME} #{AUTHOR_EMAIL}"
Expand All @@ -52,13 +52,9 @@ def compile_proto(filename)
puts " proto file path : #{file_path}"
end

protoc_cmd =
" protoc \\\n" \
" --ruby_out=#{file_dir} \\\n" \
" --proto_path=#{file_dir} \\\n" \
" #{file_path}"
protoc_cmd = "protoc --ruby_out=\"#{file_dir}\" --proto_path=\"#{file_dir}\" \"#{file_path}\""

puts "\n#{protoc_cmd}" if $verbose
puts "\n #{protoc_cmd}" if $verbose

`#{protoc_cmd}`
abort "ERROR: Invalid schema! [#{filename}] Resolve error(s)." unless $CHILD_STATUS.success?
Expand All @@ -72,20 +68,21 @@ def compile_proto(filename)
end

def valid_msgtype?(compiled_proto, msg_type)
if $verbose
puts "\n>> Validate msgtype"
puts " msgtype : #{msg_type}"
puts " pb file : #{compiled_proto}"
end

msg_types = []
File.foreach(compiled_proto) do |line|
if line.lstrip.start_with?('add_message')
extracted_msg_type = line[/"([^"]*)"/, 1].freeze # regex: <add_message> 'msg_type' <do>
if line.include?('::Google::Protobuf::DescriptorPool.generated_pool.lookup')
extracted_msg_type = line[/"([^"]*)"/, 1].freeze
msg_types.push(extracted_msg_type) unless extracted_msg_type.nil?
end
end

if $verbose
puts "\n>> Validate msgtype"
puts " msgtype : #{msg_type}"
puts " pb file : #{compiled_proto}"
puts " pb types: #{msg_types}"
end

is_valid = msg_types.include?(msg_type)
unless is_valid
puts "ERROR: Invalid msgtype! [#{msg_type}]"
Expand Down Expand Up @@ -173,7 +170,7 @@ def start
args[:mode] = mode
end

opts.on('-p', '--proto [FILENAME]', String, 'protobuf schema (.proto)') do |filename|
opts.on('-p', '--proto [FILENAME]', String, 'protobuf schema (.proto file)') do |filename|
abort 'ERROR: Missing schema filename!' if filename.nil?
abort "ERROR: Protobuf schema not found! [#{filename}]" unless File.file?(filename)

Expand Down
10 changes: 4 additions & 6 deletions proto-convert.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = 'proto-convert'
spec.version = '0.4.0'
spec.date = '2021-05-14'
spec.version = '0.4.1'
spec.date = '2023-08-11'
spec.authors = ['Azeem Sajid']
spec.email = ['azeem.sajid@gmail.com']

spec.summary = 'Protobuf Message Converter [Binary <-> JSON]'
spec.description = 'A command-line tool to convert protobuf messages from binary to JSON and vice versa'
spec.description = 'a CLI tool to convert protobuf messages from binary to JSON and vice versa'
spec.homepage = 'https://github.com/iamAzeem/proto-convert'
spec.license = 'MIT'

spec.executables = ['proto-convert']

spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.0'
spec.add_runtime_dependency 'google-protobuf', '~> 3.12', '>= 3.12.2'

spec.post_install_message = 'Thanks for installing! :)'
spec.add_runtime_dependency 'google-protobuf', '~> 3.12'
end

0 comments on commit 7ef273e

Please sign in to comment.