From d595bbbff0b5849c37798158a1a49bd018a3692e Mon Sep 17 00:00:00 2001 From: "m.oleynik" Date: Sat, 14 Nov 2020 19:16:51 +0300 Subject: [PATCH] adding github actions --- .github/workflows/main.yml | 97 ++++++++++++++++++++++++++++++++++++++ .rubocop.yml | 2 + .rubocop_todo.yml | 55 +++++++++++++++++++++ .ruby-version | 2 +- .travis.yml | 15 ------ Gemfile | 12 ++++- Gemfile.lock | 50 +++++++++++++++++++- config/database.yml.sample | 74 +---------------------------- 8 files changed, 216 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .rubocop_todo.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c299a2a --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,97 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:11 + ports: ['5432:5432'] + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v2 + - name: Setup Ruby + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + + - name: Install library for postgres + run: sudo apt-get install libpq-dev + + - name: Install gems + run: | + gem install bundler + bundle install + + - name: Setup database + env: + DATABASE_URL: postgres://postgres:@localhost:5432/rock_test + run: | + cp config/database.yml.sample config/database.yml + bundle exec rails db:create db:migrate + + - name: RSpec + run: bundle exec rspec spec + + rubocop: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Ruby + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + + - name: Install rubocop + run: gem install rubocop + + - name: Rubocop + run: bundle exec rubocop + + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Ruby + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + + - name: Install security gems + run: | + gem install brakeman + gem install bundler-audit + + - name: Run Brakeman + run: bundle exec brakeman -q + + - name: Run bundler-audit + run: bundle exec bundle audit check --update + + leak: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Ruby + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + + - name: Install bundler-leak + run: gem install bundler-leak + + - name: Run bundler-leak + run: bundle exec bundle leak check --update diff --git a/.rubocop.yml b/.rubocop.yml index 74d9ac9..1a744ee 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + AllCops: Include: - 'app/**/*.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..6463dd2 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,55 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2020-11-14 16:14:11 UTC using RuboCop version 0.92.0. +# 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: 1 +# Cop supports --auto-correct. +Layout/EmptyLines: + Exclude: + - 'config/environments/development.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 112 + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'config/environments/production.rb' + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'config/environments/development.rb' + - 'config/environments/production.rb' + - 'config/environments/test.rb' + - 'config/puma.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: . +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: percent + MinSize: 3 diff --git a/.ruby-version b/.ruby-version index b2eb314..57cf282 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.6.3 \ No newline at end of file +2.6.5 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 547c279..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: ruby -rvm: - - 2.6.3 - -addons: - postgresql: '10' - -before_script: - - sudo /etc/init.d/postgresql restart - - cp config/database.yml.sample config/database.yml - - psql -c 'create database rock_test;' -U postgres - -script: - - bundle exec rails db:migrate RAILS_ENV=test - - bundle exec rspec \ No newline at end of file diff --git a/Gemfile b/Gemfile index 646ecaf..1dc2996 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.6.3' +ruby '2.6.5' gem 'rails', '~> 5.2.3' gem 'pg', '>= 0.18', '< 2.0' @@ -12,7 +12,16 @@ gem 'devise_invitable', '~> 2.0.0' gem 'fast_jsonapi' gem 'carrierwave', '~> 2.0' +# Inspection +gem 'rubocop', '~> 0.92.0', require: false +gem 'rubocop-performance', '~> 1.8.1', require: false +gem 'rubocop-rails', '~> 2.8.1', require: false +gem 'rubocop-rake', '~> 0.5.1', require: false +gem 'rubocop-rspec', '~> 1.43.2', require: false + group :development, :test do + gem 'bundler-audit' + gem 'bundler-leak', '~> 0.2.0' gem 'pry-byebug' gem 'rspec-rails', '~> 3.8' gem 'factory_bot_rails' @@ -22,6 +31,7 @@ end group :development do gem 'annotate' + gem 'brakeman', '~> 4.10.0' gem 'listen', '>= 3.0.5', '< 3.2' gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index fd57f54..39366ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,10 +56,18 @@ GEM activerecord (>= 3.2, < 7.0) rake (>= 10.4, < 13.0) arel (9.0.0) + ast (2.4.1) bcrypt (3.1.13) bootsnap (1.4.5) msgpack (~> 1.0) + brakeman (4.10.0) builder (3.2.3) + bundler-audit (0.7.0.1) + bundler (>= 1.2.0, < 3) + thor (>= 0.18, < 2) + bundler-leak (0.2.0) + bundler (>= 1.2.0, < 3) + thor (>= 0.18, < 2) byebug (11.0.1) carrierwave (2.0.1) activemodel (>= 5.0.0) @@ -139,6 +147,9 @@ GEM nokogiri (1.10.4) mini_portile2 (~> 2.4.0) orm_adapter (0.5.0) + parallel (1.20.0) + parser (2.7.2.0) + ast (~> 2.4.1) pg (1.1.4) pry (0.12.2) coderay (~> 1.1.0) @@ -175,13 +186,16 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) + rainbow (3.0.0) rake (12.3.3) rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) + regexp_parser (1.8.2) responders (3.0.0) actionpack (>= 5.0) railties (>= 5.0) + rexml (3.2.4) rspec-core (3.8.2) rspec-support (~> 3.8.0) rspec-expectations (3.8.4) @@ -199,6 +213,29 @@ GEM rspec-mocks (~> 3.8.0) rspec-support (~> 3.8.0) rspec-support (3.8.2) + rubocop (0.92.0) + parallel (~> 1.10) + parser (>= 2.7.1.5) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.7) + rexml + rubocop-ast (>= 0.5.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (1.1.1) + parser (>= 2.7.1.5) + rubocop-performance (1.8.1) + rubocop (>= 0.87.0) + rubocop-ast (>= 0.4.0) + rubocop-rails (2.8.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 0.87.0) + rubocop-rake (0.5.1) + rubocop + rubocop-rspec (1.43.2) + rubocop (~> 0.87) + ruby-progressbar (1.10.1) ruby-vips (2.0.15) ffi (~> 1.9) ruby_dep (1.5.0) @@ -222,6 +259,7 @@ GEM tilt (2.0.9) tzinfo (1.2.5) thread_safe (~> 0.1) + unicode-display_width (1.7.0) warden (1.2.8) rack (>= 2.0.6) websocket-driver (0.7.1) @@ -234,6 +272,9 @@ PLATFORMS DEPENDENCIES annotate bootsnap (>= 1.1.0) + brakeman (~> 4.10.0) + bundler-audit + bundler-leak (~> 0.2.0) carrierwave (~> 2.0) database_cleaner devise_invitable (~> 2.0.0) @@ -248,12 +289,17 @@ DEPENDENCIES puma (~> 3.11) rails (~> 5.2.3) rspec-rails (~> 3.8) + rubocop (~> 0.92.0) + rubocop-performance (~> 1.8.1) + rubocop-rails (~> 2.8.1) + rubocop-rake (~> 0.5.1) + rubocop-rspec (~> 1.43.2) spring spring-watcher-listen (~> 2.0.0) tzinfo-data RUBY VERSION - ruby 2.6.3p62 + ruby 2.6.5p114 BUNDLED WITH - 2.0.2 + 2.1.4 diff --git a/config/database.yml.sample b/config/database.yml.sample index 69c4fd6..6e64331 100644 --- a/config/database.yml.sample +++ b/config/database.yml.sample @@ -1,85 +1,15 @@ -# PostgreSQL. Versions 9.1 and up are supported. -# -# Install the pg driver: -# gem install pg -# On OS X with Homebrew: -# gem install pg -- --with-pg-config=/usr/local/bin/pg_config -# On OS X with MacPorts: -# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config -# On Windows: -# gem install pg -# Choose the win32 build. -# Install PostgreSQL and put its /bin directory on your path. -# -# Configure Using Gemfile -# gem 'pg' -# default: &default adapter: postgresql encoding: unicode - # For details on connection pooling, see Rails configuration guide - # http://guides.rubyonrails.org/configuring.html#database-pooling + username: postgres + password: postgres pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default database: rock_development - # The specified database role being used to connect to postgres. - # To create additional roles in postgres see `$ createuser --help`. - # When left blank, postgres will use the default role. This is - # the same name as the operating system user that initialized the database. - #username: rock - - # The password associated with the postgres role (username). - #password: - - # Connect on a TCP socket. Omitted by default since the client uses a - # domain socket that doesn't need configuration. Windows does not have - # domain sockets, so uncomment these lines. - #host: localhost - - # The TCP port the server listens on. Defaults to 5432. - # If your server runs on a different port number, change accordingly. - #port: 5432 - - # Schema search path. The server defaults to $user,public - #schema_search_path: myapp,sharedapp,public - - # Minimum log levels, in increasing order: - # debug5, debug4, debug3, debug2, debug1, - # log, notice, warning, error, fatal, and panic - # Defaults to warning. - #min_messages: notice - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. test: <<: *default database: rock_test -# As with config/secrets.yml, you never want to store sensitive information, -# like your database password, in your source code. If your source code is -# ever seen by anyone, they now have access to your database. -# -# Instead, provide the password as a unix environment variable when you boot -# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database -# for a full rundown on how to provide these environment variables in a -# production deployment. -# -# On Heroku and other platform providers, you may have a full connection URL -# available as an environment variable. For example: -# -# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" -# -# You can use this database configuration with: -# -# production: -# url: <%= ENV['DATABASE_URL'] %> -# -production: - <<: *default - database: rock_production - username: rock - password: <%= ENV['ROCK_DATABASE_PASSWORD'] %>