From 772173a101664a7f3f411ae0df0df32606b5764d Mon Sep 17 00:00:00 2001 From: WillNigel23 Date: Tue, 16 Jul 2024 02:17:32 +0800 Subject: [PATCH] 4179 - Github workflows --- .coveralls.yml | 2 +- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++++++ Gemfile | 6 +++-- Gemfile.lock | 36 ++++++++++++++++-------------- config/database.yml | 7 +++--- spec/spec_helper.rb | 6 +++-- 6 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.coveralls.yml b/.coveralls.yml index 91600595a1..fce062d2ef 100644 --- a/.coveralls.yml +++ b/.coveralls.yml @@ -1 +1 @@ -service_name: travis-ci +service_name: github diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..045e5b2c30 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: "CI" +on: + pull_request: {} +jobs: + test: + runs-on: ubuntu-latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_DATABASE: diary_test + MYSQL_ROOT_PASSWORD: password + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + env: + RAILS_ENV: test + MYSQL_ROOT_PASSWORD: password + MYSQL_SOCKET: /tmp/mysql.sock + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Install Ruby and gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7.3 + bundler-cache: true + - name: Install dependencies + run: | + sudo apt-get -qq update + sudo apt-get install -y ghostscript poppler-utils graphviz + bundle install --jobs 4 --retry 3 + - name: Create db + run: bundle exec rake db:create + - name: Migrate + run: bundle exec rake db:migrate + - name: Load fixtures + run: bundle exec rake db:fixtures:load FIXTURES_PATH=spec/fixtures + - name: Run RuboCop + run: bundle exec rubocop + continue-on-error: true + - name: Run tests + uses: coactions/setup-xvfb@v1 + with: + run: bundle exec rspec spec + - name: Run Coveralls + run: bundle exec coveralls push diff --git a/Gemfile b/Gemfile index 25483df616..9c32a258de 100644 --- a/Gemfile +++ b/Gemfile @@ -82,8 +82,7 @@ end group :test do gem 'capybara' - gem 'capybara-webkit' - gem 'coveralls', require: false + gem 'coveralls_reborn', require: false gem 'database_cleaner' gem 'selenium-webdriver' gem 'shoulda' @@ -96,6 +95,7 @@ group :development, :test do gem 'better_errors' gem 'binding_of_caller' gem 'bullet' + gem 'dotenv-rails' gem 'easy_translate' gem 'factory_bot_rails' gem 'i18n-tasks' @@ -106,6 +106,8 @@ group :development, :test do gem 'rspec-rails' end +gem 'dotenv', group: [:development, :test], require: 'dotenv/load' + # Use SassC for stylesheets gem 'sassc-rails' diff --git a/Gemfile.lock b/Gemfile.lock index f0a1da62ce..32b7a2e3e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -169,9 +169,6 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - capybara-webkit (1.15.1) - capybara (>= 2.3, < 4.0) - json carrierwave (3.0.7) activemodel (>= 6.0.0) activesupport (>= 6.0.0) @@ -184,12 +181,11 @@ GEM clipboard-rails (1.7.1) coderay (1.1.3) concurrent-ruby (1.2.3) - coveralls (0.8.23) - json (>= 1.8, < 3) - simplecov (~> 0.16.1) - term-ansicolor (~> 1.3) - thor (>= 0.19.4, < 2.0) - tins (~> 1.6) + coveralls_reborn (0.28.0) + simplecov (~> 0.22.0) + term-ansicolor (~> 1.7) + thor (~> 1.2) + tins (~> 1.32) crack (1.0.0) bigdecimal rexml @@ -221,6 +217,10 @@ GEM diff-lcs (1.5.1) diffy (3.4.2) docile (1.4.0) + dotenv (2.8.1) + dotenv-rails (2.8.1) + dotenv (= 2.8.1) + railties (>= 3.2) easy_translate (0.5.1) thread thread_safe @@ -351,6 +351,7 @@ GEM mini_mime (1.1.5) mini_portile2 (2.8.6) minitest (5.22.3) + mize (0.5.0) msgpack (1.7.2) multi_json (1.15.0) multi_xml (0.6.0) @@ -564,11 +565,12 @@ GEM shoulda-context (2.0.0) shoulda-matchers (4.5.1) activesupport (>= 4.2.0) - simplecov (0.16.1) + simplecov (0.22.0) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) slim (5.2.1) temple (~> 0.10.0) tilt (>= 2.1.0) @@ -595,7 +597,8 @@ GEM stackprof (0.2.26) sync (0.5.0) temple (0.10.3) - term-ansicolor (1.8.0) + term-ansicolor (1.10.4) + mize (~> 0.5) tins (~> 1.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) @@ -681,16 +684,17 @@ DEPENDENCIES capistrano-bundler (~> 1.6) capistrano-rails (~> 1.4) capybara - capybara-webkit carrierwave charlock_holmes clipboard-rails - coveralls + coveralls_reborn database_cleaner devise devise-encryptable devise_masquerade (~> 1.2.0) diffy + dotenv + dotenv-rails easy_translate edtf edtf-humanize diff --git a/config/database.yml b/config/database.yml index 416123e984..a0273dba9c 100644 --- a/config/database.yml +++ b/config/database.yml @@ -15,8 +15,8 @@ default: &default collation: utf8mb4_unicode_ci pool: 5 username: root - password: - socket: /var/run/mysqld/mysqld.sock + password: <%= ENV['MYSQL_ROOT_PASSWORD'] %> + socket: <%= ENV['MYSQL_SOCKET'] %> strict: false variables: sql_mode: TRADITIONAL @@ -25,7 +25,7 @@ default: &default development: <<: *default username: rails - password: rails + password: <%= ENV['MYSQL_DEV_PASSWORD'] %> database: diary_development # Warning: The database defined as "test" will be erased and @@ -34,6 +34,7 @@ development: test: <<: *default database: diary_test + host: 127.0.0.1 # 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eab2809ad3..2177b33bba 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,8 +5,9 @@ require 'factory_bot' require 'webmock/rspec' require 'database_cleaner' + require 'coveralls' -Coveralls.wear! +Coveralls.wear!('rails') DatabaseCleaner.strategy = :transaction @@ -85,10 +86,11 @@ end Capybara.configure do |config| - config.asset_host = "http://localhost:3000" + config.asset_host = 'http://localhost:3000' config.raise_server_errors = false end + Shoulda::Matchers.configure do |config| config.integrate do |with| with.test_framework :rspec