From 7ef273e4c36977c6f133643cdf1825d8dd1f5789 Mon Sep 17 00:00:00 2001 From: Azeem Sajid Date: Fri, 11 Aug 2023 15:39:40 +0500 Subject: [PATCH] [CI] Run tests in Windows runner too (#8) * [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 --- .github/workflows/ci.yml | 11 ++++++----- README.md | 10 ++++++++-- bin/proto-convert | 29 +++++++++++++---------------- proto-convert.gemspec | 10 ++++------ 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6dba4c5..17cb805 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - ruby-version: ['2.6', '2.7'] + ruby-version: ['2.7'] runs-on: ${{ matrix.os }} @@ -26,23 +26,24 @@ jobs: - 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 diff --git a/README.md b/README.md index 00d9ef8..325ed8f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/bin/proto-convert b/bin/proto-convert index 9e3f4c2..b3354ae 100755 --- a/bin/proto-convert +++ b/bin/proto-convert @@ -32,7 +32,7 @@ require 'optparse' require 'English' -VERSION = '0.4.0' +VERSION = '0.4.1' AUTHOR_NAME = 'Azeem Sajid' AUTHOR_EMAIL = '' AUTHOR_INFO = "Author: #{AUTHOR_NAME} #{AUTHOR_EMAIL}" @@ -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? @@ -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: 'msg_type' + 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}]" @@ -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) diff --git a/proto-convert.gemspec b/proto-convert.gemspec index 8be317e..b4a0e02 100644 --- a/proto-convert.gemspec +++ b/proto-convert.gemspec @@ -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