Skip to content

Commit

Permalink
Packages common code into a Rubygem
Browse files Browse the repository at this point in the history
This version was extracted from the Python language agent repository (https://github.com/corgibytes/freshli-agent-python). Subsequent adjustments might need to be made to accommodate customizations that have been made in other repositories.
  • Loading branch information
mscottford committed Aug 18, 2023
1 parent eca749f commit dc48947
Show file tree
Hide file tree
Showing 30 changed files with 1,073 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# editorconfig.org

# Used the .NET Runtime as the base configuration.
#
# https://github.com/dotnet/runtime/blob/main/.editorconfig

# top-most EditorConfig file
root = true

# Default settings:
# A newline ending every file
# Use 4 spaces as indentation
[*]
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
tab_width = 8

[*.json]
insert_final_newline = unset

# Shell scripts
[*.sh]
end_of_line = lf
[*.{cmd,bat}]
end_of_line = crlf

# Ruby files
[Gemfile.lock]
indent_size = unset

[LICENSE]
indent_size = unset
max_line_length = unset

[CONTRIBUTING.md]
indent_size = unset
max_line_length = unset

[README.md]
indent_size = unset
max_line_length = unset

[lib/corgibytes/freshli/commons/step_definitions/grpc/**/*.rb]
generated_code = true
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Ruby

on:
push:
branches:
- main

pull_request:

jobs:
build:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby:
- '3.0.5'

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status

lib/corgibytes/freshli/commons/step_definitions/grpc/*.rb
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AllCops:
NewCops: enable
SuggestExtensions: false
TargetRubyVersion: 3.0
Exclude:
- 'lib/corgibytes/freshli/commons/step_definitions/grpc/**/*'
- 'vendor/bundle/**/*'

Style/ConditionalAssignment:
Enabled: false
6 changes: 6 additions & 0 deletions .semver
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
:major: 0
:minor: 6
:patch: 0
:special: 'dev'
:metadata: ''
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in corgibytes-freshli-commons.gemspec
gemspec

gem 'rake', '~> 13.0'

gem 'rspec', '~> 3.0'

gem 'rubocop', '~> 1.21'
gem 'rubocop-performance'

gem 'semver2', '~> 3.4', '>= 3.4.2'

gem 'grpc-tools'
124 changes: 124 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
PATH
remote: .
specs:
freshli-commons (0.6.0.pre.dev)
aruba (~> 2.1.0)
grpc
rspec-expectations
sqlite3

GEM
remote: https://rubygems.org/
specs:
aruba (2.1.0)
bundler (>= 1.17, < 3.0)
childprocess (>= 2.0, < 5.0)
contracts (>= 0.16.0, < 0.18.0)
cucumber (>= 4.0, < 9.0)
rspec-expectations (~> 3.4)
thor (~> 1.0)
ast (2.4.2)
base64 (0.1.1)
builder (3.2.4)
childprocess (4.1.0)
contracts (0.17)
cucumber (8.0.0)
builder (~> 3.2, >= 3.2.4)
cucumber-ci-environment (~> 9.0, >= 9.0.4)
cucumber-core (~> 11.0, >= 11.0.0)
cucumber-cucumber-expressions (~> 15.1, >= 15.1.1)
cucumber-gherkin (~> 23.0, >= 23.0.1)
cucumber-html-formatter (~> 19.1, >= 19.1.0)
cucumber-messages (~> 18.0, >= 18.0.0)
diff-lcs (~> 1.5, >= 1.5.0)
mime-types (~> 3.4, >= 3.4.1)
multi_test (~> 1.1, >= 1.1.0)
sys-uname (~> 1.2, >= 1.2.2)
cucumber-ci-environment (9.2.0)
cucumber-core (11.0.0)
cucumber-gherkin (~> 23.0, >= 23.0.1)
cucumber-messages (~> 18.0, >= 18.0.0)
cucumber-tag-expressions (~> 4.1, >= 4.1.0)
cucumber-cucumber-expressions (15.2.0)
cucumber-gherkin (23.0.1)
cucumber-messages (~> 18.0, >= 18.0.0)
cucumber-html-formatter (19.2.0)
cucumber-messages (~> 18.0, >= 18.0.0)
cucumber-messages (18.0.0)
cucumber-tag-expressions (4.1.0)
diff-lcs (1.5.0)
ffi (1.15.5)
google-protobuf (3.24.0-arm64-darwin)
googleapis-common-protos-types (1.8.0)
google-protobuf (~> 3.18)
grpc (1.57.0)
google-protobuf (~> 3.23)
googleapis-common-protos-types (~> 1.0)
grpc-tools (1.57.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
mime-types (3.5.0)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.0808)
multi_test (1.1.0)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
racc (1.7.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.8.1)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.56.0)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-performance (1.19.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
ruby-progressbar (1.13.0)
semver2 (3.4.2)
sqlite3 (1.6.3-arm64-darwin)
sys-uname (1.2.3)
ffi (~> 1.1)
thor (1.2.2)
unicode-display_width (2.4.2)

PLATFORMS
arm64-darwin-22

DEPENDENCIES
freshli-commons!
grpc-tools
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 1.21)
rubocop-performance
semver2 (~> 3.4, >= 3.4.2)

BUNDLED WITH
2.4.18
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,31 @@
# freshli-commons
Common code that is shared amongst the Freshli repositories
# Corgibytes::Freshli::Commons

TODO: Delete this and the text below, and describe your gem

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/corgibytes/freshli/commons`. To experiment with that code, run `bin/console` for an interactive prompt.

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.

Install the gem and add to the application's Gemfile by executing:

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG

## Usage

TODO: Write usage instructions here

## Development

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

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/corgibytes-freshli-commons.
76 changes: 76 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

require 'fileutils'

# TODO: Copy the `freshli_agent.proto` from the `corgibytes/freshli` repository
# instead of having it live in this repository. Similar to what's being done
# with the health status proto file below.

# based on https://stackoverflow.com/a/29743469/243215
def download(url, target_path)
# rubocop:disable Security/Open
require 'open-uri'
download = URI.open(url)
# rubocop:enable Security/Open
IO.copy_stream(download, target_path)
end

# Generate gRPC files from the freshli_agent.proto file
GENERATED_GRPC_FILES = [
'lib/corgibytes/freshli/commons/step_definitions/grpc/freshli_agent_pb.rb',
'lib/corgibytes/freshli/commons/step_definitions/grpc/freshli_agent_services_pb.rb',
'lib/corgibytes/freshli/commons/step_definitions/grpc/health_services_pb.rb',
'lib/corgibytes/freshli/commons/step_definitions/grpc/health_pb.rb'
].freeze
# rubocop:disable Metrics/BlockLength
namespace :grpc do
task :generate do
Rake::Task['grpc:generate:force'].invoke unless GENERATED_GRPC_FILES.all? { |file| File.exist?(file) }
end

namespace :generate do
desc 'Generate gRPC files even if they already exist'
task :force do
system(
'bundle exec grpc_tools_ruby_protoc -I ' \
'./protos/corgibytes/freshli/agent/grpc ' \
'--ruby_out=./lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'--grpc_out=./lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'./protos/corgibytes/freshli/agent/grpc/freshli_agent.proto'
)

FileUtils.mkdir_p('tmp')

download(
'https://raw.githubusercontent.com/grpc/grpc/e35cf362a49b4de753cbe69f3e836d2e40408ca2' \
'/src/proto/grpc/health/v1/health.proto',
File.expand_path(File.join(File.dirname(__FILE__), 'tmp', 'health.proto'))
)
system(
'bundle exec grpc_tools_ruby_protoc -I tmp ' \
'--ruby_out=lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'--grpc_out=lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'tmp/health.proto'
)
end
end
end
# rubocop:enable Metrics/BlockLength

desc 'Generate gRPC files'
task grpc: %i[grpc:generate]

# Ensure that the grpc files are generated before the tests run
RSpec::Core::RakeTask.new(spec: 'grpc')

require 'rubocop/rake_task'

RuboCop::RakeTask.new

# Ensure that the grpc files are generated before the build runs
Rake::Task['build'].enhance(['grpc'])

task default: %i[grpc spec rubocop]
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'corgibytes/freshli/commons'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require 'irb'
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
Loading

0 comments on commit dc48947

Please sign in to comment.