From 13fee8f7139c7e09fa39d733b0edc2744c09f0cf Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 00:41:55 +1300 Subject: [PATCH 01/15] Add GitHub Actions workflow --- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 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..ff414dfd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,47 @@ +name: Continuous Integration +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-20.04 + services: + postgres: + image: postgres:11 + env: + POSTGRES_PASSWORD: postgres + ports: ['5432:5432'] + options: >- + --health-cmd pg_isready + --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 + + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - run: bash script/install/config.bash --defaults + env: + RAILS_ENV: test + 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 --skip-update + - run: bundle exec rake db:test:load + - run: bundle exec rspec From ff6ecb3353feb1520ab7db33497f7d2eebfb75d5 Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 01:08:06 +1300 Subject: [PATCH 02/15] Add postgres configuration for CI --- .github/workflows/ci.yml | 6 ++++++ config/database.yml.template | 4 +++- script/install/postgresql.bash | 6 +++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff414dfd..494ca953 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,5 +43,11 @@ jobs: ISOLATE_BRANCH: master - run: AUTOCONFIRM=true script/install.bash --skip-update + env: + DATABASE_URL: postgresql://postgres:postgres@localhost:5432 + PGHOST: localhost + PGUSER: postgres + PGPASSWORD: postgres + - run: bundle exec rake db:test:load - run: bundle exec rspec diff --git a/config/database.yml.template b/config/database.yml.template index 252b43f7..504a9106 100644 --- a/config/database.yml.template +++ b/config/database.yml.template @@ -7,6 +7,7 @@ development: pool: 5 username: ${DATABASE_USERNAME} password: + url: ${DATABASE_URL} # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -17,6 +18,7 @@ test: database: ${TEST_DATABASE} pool: 5 username: ${DATABASE_USERNAME} + url: ${DATABASE_URL} production: adapter: postgresql @@ -25,4 +27,4 @@ production: pool: 5 username: ${DATABASE_USERNAME} password: - + url: ${DATABASE_URL} diff --git a/script/install/postgresql.bash b/script/install/postgresql.bash index e3358b5a..3f0624dc 100644 --- a/script/install/postgresql.bash +++ b/script/install/postgresql.bash @@ -24,7 +24,7 @@ $cmd || exit 1 # setup user if required psql -U$DATABASE_USERNAME postgres -c '' &> /dev/null || { bash script/confirm.bash "Create new PostgreSQL user $DATABASE_USERNAME" && { - cmd="sudo -u postgres createuser --superuser $DATABASE_USERNAME" + cmd="sudo -Eu postgres createuser --superuser $DATABASE_USERNAME" echo "$ $cmd" $cmd } || exit 1 @@ -34,7 +34,7 @@ psql -U$DATABASE_USERNAME postgres -c '' &> /dev/null || { if [[ $DATABASE ]] ; then psql -U$DATABASE_USERNAME $DATABASE -c '' &> /dev/null || { bash script/confirm.bash "Create new PostgreSQL database $DATABASE" && { - cmd="sudo -u postgres createdb $DATABASE" + cmd="sudo -Eu postgres createdb $DATABASE" echo "$ $cmd" $cmd } || exit 1 @@ -45,7 +45,7 @@ fi if [[ $TEST_DATABASE ]] ; then psql -U$DATABASE_USERNAME $TEST_DATABASE -c '' &> /dev/null || { bash script/confirm.bash "Create new PostgreSQL database $TEST_DATABASE" && { - cmd="sudo -u postgres createdb $TEST_DATABASE" + cmd="sudo -Eu postgres createdb $TEST_DATABASE" echo "$ $cmd" $cmd } || exit From 087ff3cf2ad797f599ba1672d2584768ce9d9ac9 Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 01:15:53 +1300 Subject: [PATCH 03/15] Fix debootstrap install script in CI --- 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 3840596a6f6ab4456d75a0046f606b4aed819028 Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 02:18:44 +1300 Subject: [PATCH 04/15] Fix coveralls integration --- .github/workflows/ci.yml | 4 ++++ .gitignore | 2 +- Gemfile | 3 ++- Gemfile.lock | 24 ++++++++---------------- spec/spec_helper.rb | 8 ++++++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 494ca953..2d46ba9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,3 +51,7 @@ jobs: - run: bundle exec rake db:test:load - run: bundle exec rspec + + - uses: coverallsapp/github-action@v1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} 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 b9468484..747243dc 100644 --- a/Gemfile +++ b/Gemfile @@ -62,7 +62,8 @@ gem 'sinatra' # Monitoring gem 'newrelic_rpm' -gem 'coveralls', require: false +gem 'simplecov', require: false +gem 'simplecov-lcov', require: false gem 'sentry-raven' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 12cd18e4..00c9961d 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) @@ -368,11 +362,11 @@ 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) + simplecov-lcov (0.8.0) sinatra (1.4.8) rack (~> 1.5) rack-protection (~> 1.4) @@ -406,8 +400,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) @@ -415,7 +407,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) @@ -457,7 +448,6 @@ DEPENDENCIES connection_pool countries country_select - coveralls devise (~> 3.4.1) facebox-rails factory_bot_rails @@ -499,6 +489,8 @@ DEPENDENCIES sentry-raven simple-navigation (= 3.11.0) simple_form (= 3.2.1) + simplecov + simplecov-lcov sinatra spring squeel diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 118c29f9..64c4ca05 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,9 @@ -require 'coveralls' -Coveralls.wear!('rails') +require 'simplecov' +require 'simplecov-lcov' +SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true +SimpleCov::Formatter::LcovFormatter.config.single_report_path = 'coverage/lcov.info' +SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter +SimpleCov.start 'rails' # This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' From ca9d8c3db4018bfba5bd280f5c3fd0481546741e Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Sun, 12 Mar 2023 02:44:39 +1300 Subject: [PATCH 05/15] Fix isolock permissions in CI This changes the permissions of isolock to match isolate, because the GitHub Actions runner user does not appear to be in their own group. --- script/install/isolock.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/install/isolock.bash b/script/install/isolock.bash index 3a968160..b1e1b255 100644 --- a/script/install/isolock.bash +++ b/script/install/isolock.bash @@ -16,7 +16,7 @@ else git clone https://github.com/NZOI/isolock.git && cd isolock || exit 1 fi -make && chown root bin/isolock && chgrp $APP_USER bin/isolock && chmod 6750 bin/isolock || { +make && chown root:root bin/isolock && chmod 4755 bin/isolock || { echo "Failure to setup isolock permissions - aborting" cd .. rm -r $srclocation/isolock From cb3055329122c3580ffe6fa1eecfdc27f24b9f7e Mon Sep 17 00:00:00 2001 From: Jonathan Khoo Date: Thu, 21 Dec 2023 20:15:26 +1300 Subject: [PATCH 06/15] Bump bcrypt from 3.1.11 to 3.1.20 This fixes the following error during rake db:seed on Ubuntu 20.04: BCrypt::Errors::InvalidHash (invalid hash) --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 00c9961d..c81e88e5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,7 +62,7 @@ GEM backup (3.4.0) open4 (~> 1.3.0) thor (>= 0.15.4, < 2) - bcrypt (3.1.11) + bcrypt (3.1.20) better_errors (2.9.1) coderay (>= 1.0.0) erubi (>= 1.0.0) From 90541ddb30e59b7f981639d697fff67b58a73454 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Mon, 1 Jan 2024 22:34:49 +1300 Subject: [PATCH 07/15] Update to coverallsapp/github-action@v2, remove simplecov-lcov Since this code was originally written, v2 has been released. It natively supports the simplecov format, so it allows us to remove simplecov-lcov. This gives us nice HTML coverage reports when running locally. Also, with v2 we longer have to pass the GitHub token explicitly. --- .github/workflows/ci.yml | 4 +--- Gemfile | 1 - Gemfile.lock | 2 -- spec/spec_helper.rb | 4 ---- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d46ba9c..36f08e49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,4 @@ jobs: - run: bundle exec rake db:test:load - run: bundle exec rspec - - uses: coverallsapp/github-action@v1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} + - uses: coverallsapp/github-action@v2 diff --git a/Gemfile b/Gemfile index 747243dc..aeee83e7 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,6 @@ gem 'sinatra' # Monitoring gem 'newrelic_rpm' gem 'simplecov', require: false -gem 'simplecov-lcov', require: false gem 'sentry-raven' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index c81e88e5..b23b40a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -366,7 +366,6 @@ GEM docile (~> 1.1) simplecov-html (~> 0.11) simplecov-html (0.12.3) - simplecov-lcov (0.8.0) sinatra (1.4.8) rack (~> 1.5) rack-protection (~> 1.4) @@ -490,7 +489,6 @@ DEPENDENCIES simple-navigation (= 3.11.0) simple_form (= 3.2.1) simplecov - simplecov-lcov sinatra spring squeel diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 64c4ca05..fcdf3a9b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,4 @@ require 'simplecov' -require 'simplecov-lcov' -SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true -SimpleCov::Formatter::LcovFormatter.config.single_report_path = 'coverage/lcov.info' -SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter SimpleCov.start 'rails' # This file is copied to spec/ when you run 'rails generate rspec:install' From b8ab4da8f7e20cbe98a646da7b2dbc5829c81a4c Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Mon, 1 Jan 2024 22:58:01 +1300 Subject: [PATCH 08/15] Set RAILS_ENV and DATABASE_URL for all of CI job Settings RAILS_ENV=test for all steps is important, because script/install/config.bash only persists it for other install scripts, and failing to set RAILS_ENV can cause some subtle issues; e.g. Rails normally respects the environment variable DATABASE_URL (so we can remove "url" from config/database.yml), but things breaks if RAILS_ENV is not set to "test". This change also matches GitHub's Ruby on Rails CI template. --- .github/workflows/ci.yml | 6 ++++-- config/database.yml.template | 4 +--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36f08e49..f82d3158 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,10 @@ jobs: --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 @@ -31,7 +35,6 @@ jobs: - run: bash script/install/config.bash --defaults env: - RAILS_ENV: test DATABASE_USERNAME: postgres DATABASE: TEST_DATABASE: nztraintest @@ -44,7 +47,6 @@ jobs: - run: AUTOCONFIRM=true script/install.bash --skip-update env: - DATABASE_URL: postgresql://postgres:postgres@localhost:5432 PGHOST: localhost PGUSER: postgres PGPASSWORD: postgres diff --git a/config/database.yml.template b/config/database.yml.template index 504a9106..252b43f7 100644 --- a/config/database.yml.template +++ b/config/database.yml.template @@ -7,7 +7,6 @@ development: pool: 5 username: ${DATABASE_USERNAME} password: - url: ${DATABASE_URL} # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". @@ -18,7 +17,6 @@ test: database: ${TEST_DATABASE} pool: 5 username: ${DATABASE_USERNAME} - url: ${DATABASE_URL} production: adapter: postgresql @@ -27,4 +25,4 @@ production: pool: 5 username: ${DATABASE_USERNAME} password: - url: ${DATABASE_URL} + From 28580906def799ce066e373c1386117d314d8bd1 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Jan 2024 19:15:06 +1300 Subject: [PATCH 09/15] Use valid user with 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 (which is displayed in the "Stop containers" step): ``` FATAL: role "root" does not exist ``` --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f82d3158..38447cec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: POSTGRES_PASSWORD: postgres ports: ['5432:5432'] options: >- - --health-cmd pg_isready + --health-cmd "pg_isready -U postgres" --health-interval 10s --health-timeout 5s --health-retries 5 From afdf0ca51d6723a6ca98da6022cbc72e40c5c96f Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Jan 2024 19:55:02 +1300 Subject: [PATCH 10/15] Don't use --skip-update with install.bash in CI This option was inherited from .travis.yml and causes install.bash to skip the following steps (which are also done during update): - bundle install - script/install/migrate.bash - script/install/whenever.bash - (if in production) script/install/assets.bash The job currently works even without these 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 don't use --skip-updates, in order to always run `bundle install` and ensure the build will work even without `bundler-cache: true`. (Running `bundle install` twice doesn't do any harm, it only takes ~0.27s the second time.) Not using --skip-updates has the a additional effect of running migrate.bash, which is probably a good thing because it exercises the migration code. The migrations take ~8s, which is a little slow but not a big deal. Note that the schema is dumped after migrating, so db:test:load will use the dumped schema rather than the one from the repository. We will add a check later on that reports an error if the dumped schema has any differences. Running whenever.bash is quick and doesn't do any harm. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38447cec..8da61a3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: ISOLATE_CGROUPS: false ISOLATE_BRANCH: master - - run: AUTOCONFIRM=true script/install.bash --skip-update + - run: AUTOCONFIRM=true script/install.bash env: PGHOST: localhost PGUSER: postgres From 71952650a7bb77edd9f21961b71d0895658fe8d4 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Jan 2024 20:48:21 +1300 Subject: [PATCH 11/15] Use postgres service settings to create nztraintest db Our install scripts create the database if it doesn't exist, but getting the postgres service to create the database is nicer and more consistent with the GitHub Actions Ruby on Rails CI template. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8da61a3e..13b3f36f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,7 @@ jobs: postgres: image: postgres:11 env: + POSTGRES_DB: nztraintest POSTGRES_PASSWORD: postgres ports: ['5432:5432'] options: >- From 65aef283e9080f2961e2a07b1c19b62aac5eee8c Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Jan 2024 21:02:10 +1300 Subject: [PATCH 12/15] Add lint job to CI running "standardrb" (Currently this doesn't do much because .standard.yml ignores all the files.) --- .github/workflows/ci.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13b3f36f..64aacc93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,3 +56,13 @@ jobs: - run: bundle exec rspec - uses: coverallsapp/github-action@v2 + + 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 a25c63739777cc51e9a4edbb72e2d7192a3ad7d6 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Jan 2024 21:03:01 +1300 Subject: [PATCH 13/15] Tweak CI workflow to match Ruby on Rails template The only semantic change is switching the postgres image from Debian-based to Alpine-based. There are a couple of differences compared to the GitHub Actions Ruby on Rails CI template: - 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 Docker health checks (for waiting until the services have started). - We have a "redis" service and a custom install script. - The template uses bin/rails etc., which we don't have yet. - The template has pretty step names, which we don't bother with. - The template's lint task uses bundler-audit, brakeman, and rubocop; we use standardrb. --- .github/workflows/ci.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64aacc93..c2b1035a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,16 @@ name: Continuous Integration on: [push, pull_request] jobs: - build: + test: runs-on: ubuntu-20.04 services: postgres: - image: postgres:11 + image: postgres:11-alpine + ports: ["5432:5432"] env: POSTGRES_DB: nztraintest + POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - ports: ['5432:5432'] options: >- --health-cmd "pg_isready -U postgres" --health-interval 10s @@ -17,7 +18,7 @@ jobs: --health-retries 5 redis: image: redis - ports: ['6379:6379'] + ports: ["6379:6379"] options: >- --health-cmd "redis-cli ping" --health-interval 10s From fc8ccc911b38b523f75a35b9c53d4272132be372 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Jan 2024 21:54:41 +1300 Subject: [PATCH 14/15] fixup! Use postgres service settings to create nztraintest db Comment out the setting for now, so that we're actually testing the script that creates the database. Keeping it as a comment because it might be useful when we pare down the install scripts. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2b1035a..9e4ad407 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: image: postgres:11-alpine ports: ["5432:5432"] env: - POSTGRES_DB: nztraintest + #POSTGRES_DB: nztraintest # not required because script/install.bash creates the database POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres options: >- From 2213c71037701c204e4ffbfbd13aaaf1dcc54b35 Mon Sep 17 00:00:00 2001 From: Tom Levy Date: Fri, 5 Jan 2024 22:14:45 +1300 Subject: [PATCH 15/15] Comment out db:test:load It's not required because we run db:migrate earlier. Also, db/schema.rb is slightly incomplete (it doesn't include the index index_users_on_username because of a Rails limitation). --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e4ad407..3232a1eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: PGUSER: postgres PGPASSWORD: postgres - - run: bundle exec rake db:test:load + #- 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