Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Run tests in Windows runner too #8

Merged
merged 25 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a7042ae
[CI] Run tests in Windows runner too
iamazeem Aug 11, 2023
45f8fdb
Test only with 2.7
iamazeem Aug 11, 2023
0855196
Install google-protobuf gem
iamazeem Aug 11, 2023
d448850
Pin protoc version to 3.17.3
iamazeem Aug 11, 2023
72216c5
Pin protoc version to 3.17.3
iamazeem Aug 11, 2023
2aa5b6d
Fix type extraction for latest protoc versions
iamazeem Aug 11, 2023
8044467
Fix type extraction for latest protoc versions
iamazeem Aug 11, 2023
525d873
Install latest google-protobuf gem
iamazeem Aug 11, 2023
4a72446
Test with Ruby 2.7 only
iamazeem Aug 11, 2023
d882366
Install latest google-protobuf
iamazeem Aug 11, 2023
31b305b
Test on Windows only
iamazeem Aug 11, 2023
f5c5512
Enable ubnutu and macos runners
iamazeem Aug 11, 2023
80a6580
Test with all combinations
iamazeem Aug 11, 2023
4e05ab3
Test with Ruby 2.6 and 2.7
iamazeem Aug 11, 2023
87ceb89
Install protoc according to Ruby version
iamazeem Aug 11, 2023
19cae74
Install protoc according to Ruby version
iamazeem Aug 11, 2023
eedad08
Install protoc according to Ruby version
iamazeem Aug 11, 2023
38dc751
Install protoc according to Ruby version
iamazeem Aug 11, 2023
2603cb6
Install protoc according to Ruby version
iamazeem Aug 11, 2023
bf63e5c
Install protoc according to Ruby version
iamazeem Aug 11, 2023
c6c5496
Remove Ruby 3.5
iamazeem Aug 11, 2023
da8bd6e
Test wirh Ruby 2.7 only
iamazeem Aug 11, 2023
10d994c
Add Known Issues section
iamazeem Aug 11, 2023
4f778e0
Print msg types in verbose info
iamazeem Aug 11, 2023
00d74ef
Remove commented config
iamazeem Aug 11, 2023
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
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