Skip to content

Commit

Permalink
Make code compatible with Shopify ruby style.
Browse files Browse the repository at this point in the history
Add .editorconfig to support common config for editors.
Update Github action workflow to run Linter task.
Update code to support Shopify ruby style.

Sidecar:
Update tests that never worked and always successed.
  • Loading branch information
miry committed May 23, 2022
1 parent ac97513 commit 83977b3
Show file tree
Hide file tree
Showing 57 changed files with 1,312 additions and 1,078 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# EditorConfig is awesome: https://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 2
trim_trailing_whitespace = true

[{*.rb,*.rake}]
indent_size = 2
indent_style = space

[{*.har,*.json}]
indent_size = 2
indent_style = space

[{*.lock,*.yaml,*.yml}]
indent_size = 2
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Gemfile.lock linguist-generated
75 changes: 37 additions & 38 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,14 @@ concurrency:
cancel-in-progress: true

env:
BUNDLE_PATH: vendor/bundle
SEED: 58485

jobs:
bundle:
name: Install dependency
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container
container: ruby:${{ matrix.ruby }}

strategy:
fail-fast: false
matrix:
ruby:
# - "3.1" # grpc is causing issues with Ruby 3.1
- "3.0"
- "2.7"
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Cache
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-ruby-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-ruby-${{ matrix.ruby }}-gems-
-
name: Bundle
if: steps.cache-primes.outputs.cache-hit != 'true'
run: |
bundle config path vendor/bundle
bundle install
test:
name: Ruby tests
runs-on: ubuntu-latest
needs: bundle
# https://docs.github.com/en/actions/using-jobs/running-jobs-in-a-container
container:
image: ruby:${{ matrix.ruby }}
ports:
Expand All @@ -61,8 +31,8 @@ jobs:

env:
CI: "1"

strategy:
fail-fast: true
matrix:
ruby:
# - "3.1" # grpc is causing issues with Ruby 3.1
Expand All @@ -87,6 +57,7 @@ jobs:
--health-retries 5
toxiproxy:
image: ghcr.io/shopify/toxiproxy:2.4.0

steps:
-
name: Checkout
Expand All @@ -95,20 +66,48 @@ jobs:
name: Cache
uses: actions/cache@v2
with:
path: vendor/bundle
path: ${{env.BUNDLE_PATH}}
key: ${{ runner.os }}-ruby-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-ruby-${{ matrix.ruby }}-gems-
-
name: Bundle
run: |
bundle config path vendor/bundle
name: Install dependencies
run: bundle install
-
name: Build C extension
name: Build C extension and gem
run: bundle exec rake build
-
name: Test
run: |
bundle exec rake test ||
(echo "===== Retry Attempt: 2 ====" && bundle exec rake test) || \
(echo "===== Retry Attempt: 3 ====" && bundle exec rake test)
lint:
env:
RUBY_VERSION: "3.0"
BUNDLE_WITHOUT: test

name: Ruby linter
runs-on: ubuntu-latest
container: ruby:3.0
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Cache
uses: actions/cache@v2
with:
path: ${{env.BUNDLE_PATH}}
key: ${{ runner.os }}-ruby-${{ env.RUBY_VERSION }}-linter-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-ruby-${{ env.RUBY_VERSION }}-linter-gems-
-
name: Bundle
if: steps.cache-primes.outputs.cache-hit != 'true'
run: bundle install
-
name: Linting
run: bundle exec rubocop

20 changes: 17 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
inherit_from:
- http://shopify.github.io/ruby-style-guide/rubocop.yml
require:
- rubocop-minitest
- rubocop-rake

inherit_from: .rubocop_todo.yml

inherit_gem:
rubocop-shopify: rubocop.yml

AllCops:
TargetRubyVersion: '2.6'
TargetRubyVersion: '2.7'
NewCops: enable

Naming/InclusiveLanguage:
Enabled: false

Style/GlobalVars:
Exclude:
- ext/semian/extconf.rb
15 changes: 15 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-05-19 18:59:22 UTC using RuboCop version 1.29.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
# Configuration parameters: AllowComments, AllowNil.
Lint/SuppressedException:
Exclude:
- 'test/helpers/circuit_breaker_helper.rb'
- 'test/net_http_test.rb'
- 'test/protected_resource_test.rb'
7 changes: 4 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"recommendations": [
"ms-vscode-remote.vscode-remote-extensionpack"
],
"recommendations": [
"ms-vscode-remote.vscode-remote-extensionpack",
"EditorConfig.EditorConfig"
]
}
44 changes: 27 additions & 17 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
source 'https://rubygems.org'
# frozen_string_literal: true

gem 'benchmark-memory'
gem 'grpc'
gem 'hiredis', '~> 0.6'
gem 'memory_profiler'
gem 'minitest'
gem 'mocha'
gem 'mysql2', '~> 0.5', github: 'brianmario/mysql2'
gem 'pry-byebug', require: false
gem 'rake-compiler'
gem 'rake'
gem 'redis-client', '0.2.0'
gem 'redis'
gem 'rubocop'
gem 'timecop'
gem 'toxiproxy', '~> 1.0.0'
gem 'webrick'
source "https://rubygems.org"

group :test do
gem "benchmark-memory"
gem "grpc"
gem "hiredis", "~> 0.6"
gem "memory_profiler"
gem "minitest"
gem "mocha"
gem "mysql2", "~> 0.5", github: "brianmario/mysql2"
gem "pry-byebug", require: false
gem "rake-compiler"
gem "rake"
gem "redis-client", "0.2.0"
gem "redis"
gem "timecop"
gem "toxiproxy", "~> 1.0.0"
gem "webrick"
end

group :lint do
gem "rubocop-minitest", require: false
gem "rubocop-rake", require: false
gem "rubocop-shopify", require: false
gem "rubocop", require: false
end

gemspec
9 changes: 9 additions & 0 deletions Gemfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 24 additions & 20 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
require 'bundler/gem_tasks'
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue LoadError
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rubocop/rake_task"
RuboCop::RakeTask.new do |task|
task.requires << "rubocop-minitest"
task.requires << "rubocop-rake"
end

# ==========================================================
# Packaging
# ==========================================================

GEMSPEC = eval(File.read('semian.gemspec'))
GEMSPEC = eval(File.read("semian.gemspec")) # rubocop:disable Security/Eval

require 'rubygems/package_task'
require "rubygems/package_task"
Gem::PackageTask.new(GEMSPEC) do |_pkg|
end

# ==========================================================
# Ruby Extension
# ==========================================================

$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require 'semian/platform'
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
require "semian/platform"
if Semian.sysv_semaphores_supported?
require 'rake/extensiontask'
Rake::ExtensionTask.new('semian', GEMSPEC) do |ext|
ext.ext_dir = 'ext/semian'
ext.lib_dir = 'lib/semian'
require "rake/extensiontask"
Rake::ExtensionTask.new("semian", GEMSPEC) do |ext|
ext.ext_dir = "ext/semian"
ext.lib_dir = "lib/semian"
end
desc "Build gem"
task build: :compile
else
task :build do
desc "Build gem"
task :build do # rubocop:disable Rake/DuplicateTask
end
end

# ==========================================================
# Testing
# ==========================================================

require 'rake/testtask'
Rake::TestTask.new 'test' do |t|
t.libs = %w(lib test)
require "rake/testtask"
Rake::TestTask.new("test") do |t|
t.libs = ["lib", "test"]
t.pattern = "test/*_test.rb"
t.warning = false
if ENV["CI"] || ENV["VERBOSE"]
t.options = '-v'
t.options = "-v"
end
end

# ==========================================================
# Documentation
# ==========================================================
require 'rdoc/task'
require "rdoc/task"
RDoc::Task.new do |rdoc|
rdoc.rdoc_files.include("lib/*.rb", "ext/semian/*.c")
end

task default: :build
task default: :test
task default: :test # rubocop:disable Rake/DuplicateTask
Loading

0 comments on commit 83977b3

Please sign in to comment.