From 375134ea048a2f024f71acb8443f75ecd0a626fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 21 Nov 2020 19:48:08 +0100 Subject: [PATCH 1/3] Run the test suite using GitHub Actions Using GitHub Actions has a few advantages over using Travis CI: * More jobs can be run in parallel * All CONSUL repositories on GitHub will be configured automatically Besides, Travis have recently changed their policy twice. First, they announced their site for free software projects would be shut down but free software projects could still use their site for private projects. And then, they limited the usage of their services for free software projects. Just like we used to do with Travis, we're enabling builds for pull requests but not for pushed branches. We're also building the master branch. Even if we never push to the master branch directly, we're aware other CONSUL repositories do, so we're running the tests for this case. --- .github/ISSUE_TEMPLATE/flakies.md | 4 ++-- .github/PULL_REQUEST_TEMPLATE | 2 +- .github/workflows/tests.yml | 40 +++++++++++++++++++++++++++++++ .travis.yml | 23 ------------------ CONTRIBUTING.md | 2 +- CONTRIBUTING_ES.md | 2 +- README.md | 2 +- README_ES.md | 2 +- spec/rails_helper.rb | 2 +- spec/spec_helper.rb | 2 +- 10 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.github/ISSUE_TEMPLATE/flakies.md b/.github/ISSUE_TEMPLATE/flakies.md index d7fde88a5..c253bc3cd 100644 --- a/.github/ISSUE_TEMPLATE/flakies.md +++ b/.github/ISSUE_TEMPLATE/flakies.md @@ -3,7 +3,7 @@ Tests that fail randomly are called "flakies", this one seems to be one: **Randomized seed:** FILL_WITH_RANDOM_SEED -**Travis failed build:** FILL_WITH_TRAVIS_FAILED_BUILD_LINK +**Failed action:** FILL_WITH_A_LINK_WHERE_THE_FAILURE_IS_SHOWN **Failure:** @@ -26,7 +26,7 @@ do done ``` -You can also try running a single spec in Travis: +You can also try running a single spec: Add option `:focus` to the spec and push your branch to Github, for example: ```ruby scenario 'Show', :focus do diff --git a/.github/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE index a8c151f5d..3a5935e50 100644 --- a/.github/PULL_REQUEST_TEMPLATE +++ b/.github/PULL_REQUEST_TEMPLATE @@ -1,6 +1,6 @@ ## References -> Related Issues/Pull Requests/Travis Builds/Rollbar errors/etc... +> Related Issues/Pull Requests/errors/etc... ## Objectives diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 000000000..2b6aa1985 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,40 @@ +name: Test suite +on: + push: + branches: + - master + pull_request: + branches-ignore: + - i18n_master + +jobs: + test: + runs-on: ubuntu-18.04 + services: + postgres: + image: postgres:10.10 + ports: ["5432:5432"] + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + env: + POSTGRES_USER: consul + POSTGRES_PASSWORD: "" + env: + PGUSER: consul + POSTGRES_HOST: postgres + RAILS_ENV: test + COVERALLS: true + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Setup NPM + uses: actions/setup-node@v1 + - name: Copy secrets and database files + run: for i in config/*.example; do cp "$i" "${i/.example}"; done + - name: Setup database + run: bundle exec rake db:setup + - name: Compile assets + run: bundle exec rake assets:precompile > /dev/null 2>&1 + - name: Run test suite + run: bin/rspec diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 682a4a82e..000000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: ruby -addons: - postgresql: "9.4" - chrome: stable -cache: bundler -bundler_args: --without development -before_script: -- for i in config/*.example; do cp "$i" "${i/.example}"; done -- bundle exec rake db:setup -script: -- "bundle exec rake assets:precompile RAILS_ENV=test > /dev/null 2>&1" -- "bin/knapsack_pro_rspec" -env: - global: - - KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true - - KNAPSACK_PRO_LOG_LEVEL=info - - KNAPSACK_PRO_CI_NODE_TOTAL=5 - matrix: - - KNAPSACK_PRO_CI_NODE_INDEX=0 - - KNAPSACK_PRO_CI_NODE_INDEX=1 - - KNAPSACK_PRO_CI_NODE_INDEX=2 - - KNAPSACK_PRO_CI_NODE_INDEX=3 - - KNAPSACK_PRO_CI_NODE_INDEX=4 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9e267ac38..0bc2d1b98 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ If you want to contribute code to solve an issue: If you'd like us to review your pull request in good spirits, please follow our coding conventions: * Include specs to test any changes you've made -* Travis CI will check whether the rest of the application is still working properly; check its build and make sure all tests are passing +* Our CI will check whether the rest of the application is still working properly; check its build and make sure all tests are passing * Your pull request will be automatically reviewed by Hound CI; fix any issues it reports * Follow [the seven rules of a great commit message](https://chris.beams.io/posts/git-commit/) diff --git a/CONTRIBUTING_ES.md b/CONTRIBUTING_ES.md index e61022079..f189ee3ef 100644 --- a/CONTRIBUTING_ES.md +++ b/CONTRIBUTING_ES.md @@ -33,7 +33,7 @@ Cuando quieras resolver una incidencia mediante código: Si quieres que revisemos tu código con una sonrisa, por favor sigue nuestras convenciones: * Incluye tests para los cambios que hayas hecho -* Travis CI comprobará automáticamente que el resto de la aplicación sigue funcionando; asegúrate de que los tests pasan +* Los tests se ejecutarán automáticamente para comprobar que el resto de la aplicación sigue funcionando; asegúrate de que los tests pasan * Tus cambios serán revisados automáticamente por Hound CI; arregla los problemas de los que informa (si es que hay alguno) * Sigue [las siete reglas para un gran mensaje de commit](https://chris.beams.io/posts/git-commit/) diff --git a/README.md b/README.md index 450533f11..1ca192299 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Citizen Participation and Open Government Application -[![Build Status](https://travis-ci.com/consul/consul.svg?branch=master)](https://travis-ci.com/consul/consul) +![Build status](https://github.com/consul/consul/workflows/.github/workflows/tests.yml/badge.svg) [![Code Climate](https://codeclimate.com/github/consul/consul/badges/gpa.svg)](https://codeclimate.com/github/consul/consul) [![Coverage Status](https://coveralls.io/repos/github/consul/consul/badge.svg)](https://coveralls.io/github/consul/consul?branch=master) [![Crowdin](https://d322cqt584bo4o.cloudfront.net/consul/localized.svg)](https://crowdin.com/project/consul) diff --git a/README_ES.md b/README_ES.md index 4dc398f6f..0bd7dec96 100644 --- a/README_ES.md +++ b/README_ES.md @@ -10,7 +10,7 @@ Aplicación de Participación Ciudadana y Gobierno Abierto -[![Build Status](https://travis-ci.com/consul/consul.svg?branch=master)](https://travis-ci.com/consul/consul) +![Estado de los tests](https://github.com/consul/consul/workflows/.github/workflows/tests.yml/badge.svg) [![Code Climate](https://codeclimate.com/github/consul/consul/badges/gpa.svg)](https://codeclimate.com/github/consul/consul) [![Coverage Status](https://coveralls.io/repos/github/consul/consul/badge.svg?branch=master)](https://coveralls.io/github/consul/consul?branch=master) [![Crowdin](https://d322cqt584bo4o.cloudfront.net/consul/localized.svg)](https://crowdin.com/project/consul) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 717007659..6bcf75793 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,5 +1,5 @@ ENV["RAILS_ENV"] ||= "test" -if ENV["TRAVIS"] +if ENV["COVERALLS"] require "coveralls" Coveralls.wear!("rails") end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 00b5c8c9e..6a6154100 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -171,5 +171,5 @@ RSpec.configure do |config| config.expect_with(:rspec) { |c| c.syntax = :expect } end -# Parallel build helper configuration for travis +# Parallel build helper configuration for CI KnapsackPro::Adapters::RSpecAdapter.bind From 9c4d24d76793777a5222d3054a5fe3e6b1c71204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 21 Nov 2020 20:29:36 +0100 Subject: [PATCH 2/3] Use Knapscack Pro to run tests in parallel Just like we used to do with Travis. The configuration was taken from the Knapsack Pro documentation [1]. [1] https://docs.knapsackpro.com/2019/github-actions-ci-config-for-ruby-on-rails-project-with-mysql-redis-elasticsearch-how-to-run-parallel-tests --- .github/workflows/tests.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2b6aa1985..57d22d9dd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,6 +23,11 @@ jobs: POSTGRES_HOST: postgres RAILS_ENV: test COVERALLS: true + strategy: + fail-fast: false + matrix: + ci_node_total: [5] + ci_node_index: [0, 1, 2, 3, 4] steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 @@ -37,4 +42,10 @@ jobs: - name: Compile assets run: bundle exec rake assets:precompile > /dev/null 2>&1 - name: Run test suite - run: bin/rspec + env: + KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: ${{ secrets.KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC }} + KNAPSACK_PRO_CI_NODE_TOTAL: ${{ matrix.ci_node_total }} + KNAPSACK_PRO_CI_NODE_INDEX: ${{ matrix.ci_node_index }} + KNAPSACK_PRO_FIXED_QUEUE_SPLIT: true + KNAPSACK_PRO_LOG_LEVEL: info + run: bin/knapsack_pro_rspec From af1943284bc39c3b15d8c95a47f1af9682c68c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sat, 21 Nov 2020 21:44:57 +0100 Subject: [PATCH 3/3] Downgrade sassc to version 2.1.0 Version 2.2.x seems to cause some issues with Ruby 2.6, as mentioned in the comments of issue 146 in the sassc-ruby repository. Due to these issues, our test suite was failing sometimes when running on GitHub Actions. --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 22a627467..59b833970 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -524,7 +524,7 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sassc (2.2.1) + sassc (2.1.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0)