From acdafb77dde617eb6c931ef3a1cf09c0ad33985e Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 01:15:53 +1300 Subject: [PATCH 1/3] Replace $TRAVIS with $CI to support GitHub Actions Travis CI sets both environment variables. Switch to $CI, since that also works on platforms such as GitHub Actions. Also explicitly propagate $CI to debootstrap.bash via sudo (it wasn't necessary on Travis CI because Travis has a special sudo configuration that preserves certain environment variables[1]). [1] https://github.com/travis-ci/travis-cookbooks/blob/v7.0.0/ci_environment/travis_build_environment/files/default/etc/sudoers/env_keep Co-authored-by: Tom Levy --- script/install.bash | 2 +- script/install/debootstrap.bash | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/script/install.bash b/script/install.bash index 61274dbd..9dedd570 100755 --- a/script/install.bash +++ b/script/install.bash @@ -47,7 +47,7 @@ bash script/install/jdk.bash || exit 1 # required by yui-compressor sudo bash script/install/isolate.bash || exit 1 # install isolate sudo bash script/install/cgroup.bash || exit 1 # install cgroups sudo bash script/install/isolock.bash || exit 1 # install isolock -sudo bash script/install/debootstrap.bash || exit 1 # install debootstrap ubuntu if required +sudo CI=$CI bash script/install/debootstrap.bash || exit 1 # install debootstrap ubuntu if required if [[ "$REDIS_INSTALL" = "true" ]]; then sudo bash script/install/redis.bash || exit 1 # install redis diff --git a/script/install/debootstrap.bash b/script/install/debootstrap.bash index 6e532e9b..187415dc 100644 --- a/script/install/debootstrap.bash +++ b/script/install/debootstrap.bash @@ -59,7 +59,7 @@ chroot "$ISOLATE_ROOT" apt-get update echo "$chroot_install software-properties-common" chroot "$ISOLATE_ROOT" apt-get install software-properties-common # provides add-apt-repository -[ -z "$TRAVIS" ] && { # if not in Travis-CI +[ -z "$CI" ] && { # if not in CI # python ppa if ! chroot "$ISOLATE_ROOT" apt-cache show python3.4 &>/dev/null || ! chroot "$ISOLATE_ROOT" apt-cache show python3.8 &>/dev/null; then @@ -91,7 +91,7 @@ chroot "$ISOLATE_ROOT" apt-get install build-essential # C/C++ (g++, gcc) echo "$chroot_install ruby" chroot "$ISOLATE_ROOT" apt-get install ruby # Ruby (ruby) -[ -z "$TRAVIS" ] && { # if not in Travis-CI +[ -z "$CI" ] && { # if not in CI # add haskell ppa echo "$chroot_cmd add-apt-repository ppa:hvr/ghc -y" chroot "$ISOLATE_ROOT" add-apt-repository ppa:hvr/ghc -y @@ -125,7 +125,7 @@ fi echo "$chroot_install openjdk-11-jdk" chroot "$ISOLATE_ROOT" apt-get install openjdk-11-jdk # Java -[ -z "$TRAVIS" ] && { # if not in Travis-CI +[ -z "$CI" ] && { # if not in CI # echo "$chroot_install python" # chroot "$ISOLATE_ROOT" apt-get install python # Python 2 (deprecated) @@ -204,11 +204,11 @@ echo "$chroot_cmd update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 chroot "$ISOLATE_ROOT" update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 75 # gcc 9 done -[ -z "$TRAVIS" ] && bash script/confirm.bash 'Install the V8 JavaScript Engine (submissions in JavaScript will fail without this!)' && { +[ -z "$CI" ] && bash script/confirm.bash 'Install the V8 JavaScript Engine (submissions in JavaScript will fail without this!)' && { HOME=/root ISOLATE_ROOT= chroot "$ISOLATE_ROOT" bash < script/install/v8.bash } -[ -z "$TRAVIS" ] && bash script/confirm.bash 'Install .NET Core (C#)' && { +[ -z "$CI" ] && bash script/confirm.bash 'Install .NET Core (C#)' && { # check kernel version uname -r | bash script/check_version.bash 4.14.0 || { echo "Warning: Linux kernel $(uname -r) detected, .NET Core requires kernel >= 4.14" From c5e325319b953c9671f3aa784b179e0d162137b5 Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 00:41:55 +1300 Subject: [PATCH 2/3] Add GitHub Actions workflow This workflow runs the tests and is a replacement for our previous Travis CI setup (.travis.yml), which we no longer use due to #147. The commands to run the install scripts and the tests are loosely based on .travis.yml, with several updates and fixes. The overall structure of the workflow is based on the GitHub Actions Ruby on Rails CI template[1]. The most notable change compared to .travis.yml is that we are dropping the `--skip-update` option when running install.bash. That option skips a couple of steps: `bundle install`, migrate.bash, whenever.bash. The new workflow can run without those steps, but it's fragile: the `bundle install` step is only safe to skip because we pass `bundler-cache: true` to ruby/setup-ruby; if we disable the cache then ruby/setup-ruby won't run `bundle install` and the build will fail. So it's better to always run `bundle install` explicitly (running it twice doesn't do any harm, and it's very fast the second time). Dropping `--skip-updates` also causes migrate.bash to be executed, which is a good thing because it exercises the migration code. It also allows us to drop the `rake db:test:load` step. (Creating the database by loading the schema is fast, but db/schema.rb is slightly incomplete: it doesn't include the index "index_users_on_username" because of a Rails limitation. Since we are running the migrations anyway, we might as well use the database created by them.) Later on we will also add a check that reports an error if the schema dumped after running the migrations has any differences compared to the schema in the repository (#245). Running whenever.bash is quick and doesn't do any harm. Another notable change is that we are adding a "lint" job that runs "standardrb" (recently added in #215). Currently this doesn't do much because .standard.yml ignores all the files. Compared to the GitHub Actions Ruby on Rails CI template[1], there are a couple of differences: - The template only runs the job on push/pull-request for branch "master", but we run the job for all branches because we want to be able to push commits and have them tested without having to open a pull request. - The template runs on ubuntu-latest, but we use ubuntu-20.04 because the build currently fails on ubuntu-latest. - The template doesn't have a Docker health check for the "postgres" service (to wait until it starts). We use a health check based on [2], but with a slightly different command[3]. - We have a "redis" service (based on [4]). - We have a custom install script. - The template uses bin/rails etc., which we don't have yet. - The template uses db:schema:load, which we don't need (see discussion of db:test:load above). - The template has pretty step names, which we don't bother with. - The template's "lint" job uses bundler-audit, brakeman, and rubocop. We use standardrb (which wraps rubocop), and will add bundler-audit later (#244). [1] https://github.com/actions/starter-workflows/blob/c31fe3d5d44d7cb4c912f4c3213f7b4610f13ea2/ci/rubyonrails.yml [2] https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers#running-jobs-directly-on-the-runner-machine [3] We pass `-U postgres` to pg_isready to suppress error messages: pg_isready works even if the username is invalid, however it causes the following error message to appear repeatedly in the postgres container log (displayed in the "Stop containers" step): `FATAL: role "root" does not exist` [4] https://docs.github.com/en/actions/using-containerized-services/creating-redis-service-containers#running-jobs-directly-on-the-runner-machine Co-authored-by: Tom Levy --- .github/workflows/ci.yml | 68 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..235367e5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,68 @@ +name: Continuous Integration +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-20.04 + services: + postgres: + image: postgres:11-alpine + ports: ["5432:5432"] + env: + #POSTGRES_DB: nztraintest # not required because script/install.bash creates the database + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd "pg_isready -U postgres" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + redis: + image: redis + ports: ["6379:6379"] + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + env: + RAILS_ENV: test + DATABASE_URL: "postgresql://postgres:postgres@localhost:5432" + + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - run: bash script/install/config.bash --defaults + env: + DATABASE_INSTALL: false + DATABASE_USERNAME: postgres + DATABASE: + TEST_DATABASE: nztraintest + REDIS_INSTALL: false + REDIS_PASS: + SCHEDULE_BACKUPS: 0 + ISOLATE_ROOT: / + ISOLATE_CGROUPS: false + ISOLATE_BRANCH: master + + - run: AUTOCONFIRM=true script/install.bash + env: + PGHOST: localhost + PGUSER: postgres + PGPASSWORD: postgres + + #- run: bundle exec rake db:test:load # not required because script/install.bash runs db:migrate + - run: bundle exec rspec + + lint: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - run: bundle exec standardrb --parallel From 451003bb14166f14299f8cf8900e01a7cf400e0c Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 02:18:44 +1300 Subject: [PATCH 3/3] Fix coveralls integration Switch from the deprecated coveralls gem to the Coveralls GitHub Action. The coveralls gem fails with SSLError [1] because it sets ssl_version to TLSv1, and its API endpoint is gone (404 Not Found). There is a community-maintained replacement called coveralls-ruby-reborn, but the official integration is through the Coveralls GitHub Action which is easy enough to use so we just switch to that. [1] https://www.github.com/lemurheavy/coveralls-ruby/issues/163 Co-authored-by: Tom Levy --- .github/workflows/ci.yml | 2 ++ .gitignore | 2 +- Gemfile | 2 +- Gemfile.lock | 22 ++++++---------------- spec/spec_helper.rb | 4 ++-- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 235367e5..909e1650 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,8 @@ jobs: #- run: bundle exec rake db:test:load # not required because script/install.bash runs db:migrate - run: bundle exec rspec + - uses: coverallsapp/github-action@v2 + lint: runs-on: ubuntu-20.04 steps: diff --git a/.gitignore b/.gitignore index 8b5ec3b4..8bfd125f 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,6 @@ /db/backup/ /db/backups/ /.fontello -/coverage/.* +/coverage/ /vendor/bundle diff --git a/Gemfile b/Gemfile index 27bf685b..110aed37 100644 --- a/Gemfile +++ b/Gemfile @@ -62,7 +62,7 @@ gem 'sinatra' # Monitoring gem 'newrelic_rpm' -gem 'coveralls', require: false +gem 'simplecov', require: false gem 'sentry-raven' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 42a1bb12..722abfd3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,12 +106,6 @@ GEM country_select (3.1.1) countries (~> 2.0) sort_alphabetical (~> 1.0) - coveralls (0.8.21) - json (>= 1.8, < 3) - simplecov (~> 0.14.1) - term-ansicolor (~> 1.3) - thor (~> 0.19.4) - tins (~> 1.6) crass (1.0.5) daemons (1.4.1) debug_inspector (0.0.3) @@ -123,7 +117,7 @@ GEM thread_safe (~> 0.1) warden (~> 1.2.3) diff-lcs (1.5.0) - docile (1.1.5) + docile (1.3.5) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) erubi (1.12.0) @@ -365,11 +359,10 @@ GEM simple_form (3.2.1) actionpack (> 4, < 5.1) activemodel (> 4, < 5.1) - simplecov (0.14.1) - docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) + simplecov (0.18.5) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov-html (0.12.3) sinatra (1.4.8) rack (~> 1.5) rack-protection (~> 1.4) @@ -403,8 +396,6 @@ GEM request_store (~> 1.0.3) strong_attributes (~> 0.0.2) superfish-rails (1.6.0.1) - term-ansicolor (1.6.0) - tins (~> 1.0) thin (1.8.2) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) @@ -412,7 +403,6 @@ GEM thor (0.19.4) thread_safe (0.3.6) tilt (2.0.8) - tins (1.16.3) ttfunk (1.5.1) tzinfo (1.2.11) thread_safe (~> 0.1) @@ -454,7 +444,6 @@ DEPENDENCIES connection_pool countries country_select - coveralls devise (~> 3.4.1) facebox-rails factory_bot_rails @@ -495,6 +484,7 @@ DEPENDENCIES sentry-raven simple-navigation (= 3.11.0) simple_form (= 3.2.1) + simplecov sinatra spring squeel diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 118c29f9..fcdf3a9b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ -require 'coveralls' -Coveralls.wear!('rails') +require 'simplecov' +SimpleCov.start 'rails' # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test'