From e85dd77977ced9934efe7d4bf10af123422fb50b Mon Sep 17 00:00:00 2001 From: Rob Paskin Date: Wed, 5 Feb 2025 16:47:24 +0000 Subject: [PATCH 1/7] Update Ruby & MySQL versions to 'current' Versions match what we're currently running. --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2e143f2..b01a2ed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: app: - image: ruby:${RUBY_VERSION:-2.5.8} + image: ruby:${RUBY_VERSION:-2.7.8} working_dir: /app command: > bash -eu -c ' @@ -18,7 +18,7 @@ services: - .:/app:cached db: - image: mysql:5.7 + image: mysql:8.0.34 environment: - MYSQL_ALLOW_EMPTY_PASSWORD=yes expose: From 0220371867bcb0f521032d1c4120d10344cc21e6 Mon Sep 17 00:00:00 2001 From: Rob Paskin Date: Wed, 5 Feb 2025 16:47:46 +0000 Subject: [PATCH 2/7] Fix error in spec_helper > uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger --- spec/spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5eb42dc..ab4fa2b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'bundler/setup' require 'byebug' require 'mysql2' +require 'logger' require 'rails/all' require 'rspec/rails' require 'active_support/testing/time_helpers' From c5aff2400c1ee96c5c2aa22f9a4bdceab8adbfa5 Mon Sep 17 00:00:00 2001 From: Rob Paskin Date: Fri, 7 Feb 2025 16:12:40 +0000 Subject: [PATCH 3/7] Add GH workflow for CI We use containers (rather than `setup-ruby`) since that's more representative of the environment in which we use the gem, even though it's presumably slower. Changes from Buildkite: - Use Docker healthcheck rather than waiting ourselves - Inline test script steps in workflows, rather than having a separate script (since we don't have the wait-for-MySQL part anymore) - Add GitHub-Actions-specific output grouping - Don't collect test failures via JUnit (it's overkill for the amount of tests we have). - Only run tests for 'current' Ruby (rather than matrix) - we'll reinstate this (likely with the appraisal gem) once we start again on Rails upgrades --- .github/workflows/ci.yml | 51 ++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 19 +++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5b4cd1c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: Test Suite + +on: + push: + workflow_dispatch: + +jobs: + spec: + name: RSpec + runs-on: ubuntu-latest + + container: + image: ruby:2.7.8 + credentials: + username: ${{ secrets.ORG_DOCKERHUB_USERNAME }} + password: ${{ secrets.ORG_DOCKERHUB_TOKEN }} + env: + DB_HOST: db + DB_USERNAME: root + + services: # versions here should match those used in docker-compose.yml + db: + image: mysql:8.0.34 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: "yes" + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + + steps: + - uses: actions/checkout@v4 + + - name: Run RSpec + shell: script -q -e -c "bash {0}" # force colour output - see https://github.com/actions/runner/issues/241 + run: | + set -euo pipefail + + ./docker-entrypoint.sh + + mkdir -p tmp + mkdir -p log + + bin/rspec + + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: "test.log" + path: log/test.log diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index fe20106..8af6506 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,7 +1,17 @@ #!/usr/bin/env sh set -eu -echo "~~~ update RubyGems and Bundler" +# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#grouping-log-lines +group() { + echo "::group::${1}" +} + +endgroup() { + echo "::endgroup::" +} + +group "update RubyGems and Bundler" + if [ "${RUBY_VERSION:-}" = "2.6.10" ]; then gem install bundler -v "~> 2.4.22" gem update --system 3.4.22 >/dev/null @@ -10,7 +20,12 @@ else gem update --system 3.2.3 >/dev/null fi -echo "~~~ bundle install" +endgroup + +group "bundle install" + bundle install \ --jobs "$(getconf _NPROCESSORS_ONLN)" \ --retry 2 + +endgroup From 3e270268cc2a738d7bcbaee69877f4ba9bc6be40 Mon Sep 17 00:00:00 2001 From: Rob Paskin Date: Fri, 7 Feb 2025 16:15:19 +0000 Subject: [PATCH 4/7] Remove Buildkite files Superseded by GitHub Actions workflow. --- .buildkite/pipeline.yml | 51 ----------------------------------------- .buildkite/test.sh | 26 --------------------- 2 files changed, 77 deletions(-) delete mode 100644 .buildkite/pipeline.yml delete mode 100755 .buildkite/test.sh diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml deleted file mode 100644 index 7d70dd8..0000000 --- a/.buildkite/pipeline.yml +++ /dev/null @@ -1,51 +0,0 @@ -steps: - - label: ':rspec: Rails {{matrix.rails}} (Ruby {{matrix.ruby}})' - key: spec - plugins: - - docker-compose#v3.9.0: - run: app - env: - - 'RAILS_VERSION={{matrix.rails}}' - # used for names of JUnit XML files - - BUILDKITE_JOB_ID - timeout_in_minutes: 5 - command: - - './docker-entrypoint.sh' - - '.buildkite/test.sh' - env: - BYEBUG: '0' - DEBUGGER: '0' - RUBY_VERSION: '{{matrix.ruby}}' - matrix: - setup: - rails: - - '4.2' - - '5.2' - ruby: - - '2.5.8' - - '2.6.10' - adjustments: - - with: - rails: '5.2' - ruby: '2.5.8' - skip: true - - with: - rails: '4.2' - ruby: '2.6.10' - skip: true - artifact_paths: - - log/*.log - - tmp/rspec-junit-*.xml - - tmp/rspec/*.txt - - tmp/capybara/* - - tmp/screenshots/* - - - wait: ~ - continue_on_failure: true - - - label: ':junit:' - plugins: - - junit-annotate#v1.9.0: - artifacts: tmp/rspec-junit-*.xml - job-uuid-file-pattern: rspec-junit-([^.]+)\.xml - failure-format: file diff --git a/.buildkite/test.sh b/.buildkite/test.sh deleted file mode 100755 index 08e258c..0000000 --- a/.buildkite/test.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env sh -set -eu - -echo "~~~ Waiting for MySQL" -retries=5 - -until ruby -rsocket -e 'Socket.tcp(ENV["DB_HOST"], 3306).close' 2>/dev/null; do - retries="$(("$retries" - 1))" - - if [ "$retries" -eq 0 ]; then - echo "Failed to reach MySQL" >&2 - exit 1 - fi - - sleep 5 - echo "Waiting for MySQL ($retries retries left)" -done - -echo "+++ :rspec: Running specs" -mkdir -p tmp -mkdir -p log - -bin/rspec \ - --format RspecJunitFormatter \ - --out "tmp/rspec-junit-$BUILDKITE_JOB_ID.xml" \ - --format documentation From 316651f2a7cf18a75aaa4bda0eca0484b0b8b442 Mon Sep 17 00:00:00 2001 From: Rob Paskin Date: Fri, 7 Feb 2025 16:16:40 +0000 Subject: [PATCH 5/7] Remove no-longer-needed development gem --- report_generator.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/report_generator.gemspec b/report_generator.gemspec index 7ff3453..d47cd50 100644 --- a/report_generator.gemspec +++ b/report_generator.gemspec @@ -49,6 +49,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'dragonfly-s3_data_store', '~> 1.3' spec.add_development_dependency 'mysql2', '~> 0.5.3' spec.add_development_dependency 'rake', '~> 12.3.3' - spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4' spec.add_development_dependency 'rspec-rails', '~> 3.0' end From e614a1f6822466fb52e944eb70fa33bddedacf5b Mon Sep 17 00:00:00 2001 From: Rob Paskin Date: Fri, 7 Feb 2025 16:16:56 +0000 Subject: [PATCH 6/7] Remove obsolete reference to CircleCI --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ab4fa2b..e135153 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,7 +31,7 @@ Rails.application = ReportGenerator::Engine db_config = { - database: "report_generator_test#{ENV['CIRCLE_NODE_INDEX']}", + database: 'report_generator_test', adapter: 'mysql2', encoding: 'utf8mb4', pool: 5, From b086b453f1e12c1f270ff2b86438e9d743a10e96 Mon Sep 17 00:00:00 2001 From: Rob Paskin Date: Fri, 7 Feb 2025 16:17:24 +0000 Subject: [PATCH 7/7] Remove support for multiple Rails versions Will reinstate with appraisal gem. --- Gemfile | 5 ----- docker-entrypoint.sh | 10 +++------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index acf8695..88c1871 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,3 @@ source 'https://rubygems.org' # Specify your gem's dependencies in report_generator.gemspec gemspec - -rails_version = ENV['RAILS_VERSION'] -rails_version = '4.2' if !rails_version || rails_version.strip.empty? - -gem 'railties', "~> #{rails_version}" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 8af6506..a430d43 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -12,13 +12,9 @@ endgroup() { group "update RubyGems and Bundler" -if [ "${RUBY_VERSION:-}" = "2.6.10" ]; then - gem install bundler -v "~> 2.4.22" - gem update --system 3.4.22 >/dev/null -else - gem install bundler -v 2.3.27 - gem update --system 3.2.3 >/dev/null -fi +# latest supported versions for Ruby 2.x +gem install bundler -v "~> 2.4.22" +gem update --system 3.4.22 >/dev/null endgroup