From f03fbba5acac86fcf17d138f79f8cab57de1f88d Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 27 Nov 2025 16:14:57 +0100 Subject: [PATCH] Restore local CI, sensible setup for open source users --- Gemfile.saas.lock | 2 +- bin/setup | 42 ++++++++++++++++++++++++++++++++++++------ config/ci.rb | 13 +++++++++---- lib/fizzy.rb | 2 +- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/Gemfile.saas.lock b/Gemfile.saas.lock index 618c1dc44..78f4a172c 100644 --- a/Gemfile.saas.lock +++ b/Gemfile.saas.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/basecamp/fizzy-saas - revision: f251028405bd0ba586fe836d1a8c56428b8abff0 + revision: 720bedaf37faf8dff18c9586e1fa7031bad1d2a9 specs: fizzy-saas (0.1.0) queenbee diff --git a/bin/setup b/bin/setup index 0b7fb10f7..3c3c02fdc 100755 --- a/bin/setup +++ b/bin/setup @@ -82,16 +82,46 @@ step "Installing RubyGems" bundle install if [ -n "$SAAS" ]; then saas_setup=$(bundle show fizzy-saas)/bin/setup source "$saas_setup" +else + if ! nc -z localhost 3306 2>/dev/null; then + if docker ps -aq -f name=fizzy-mysql | grep -q .; then + step "Starting MySQL" docker start fizzy-mysql + else + step "Setting up MySQL" bash -c ' + docker pull mysql:8.4 + docker run -d \ + --name fizzy-mysql \ + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ + -p 3306:3306 \ + mysql:8.4 + echo "MySQL is starting… (it may take a few seconds)" + ' + fi + fi fi -if [[ $* == *--reset* ]]; then - step "Resetting the database" rails db:reset -else - step "Preparing the database" rails db:prepare +if [ -n "$SAAS" ]; then + if [[ $* == *--reset* ]]; then + step "Resetting the database" rails db:reset + else + step "Preparing the database" rails db:prepare - if needs_seeding; then - step "Seeding the database" rails db:seed + if needs_seeding; then + step "Seeding the database" rails db:seed + fi fi +else + for adapter in sqlite mysql; do + if [[ $* == *--reset* ]]; then + step "Resetting the database ($adapter)" env DATABASE_ADAPTER=$adapter rails db:reset + else + step "Preparing the database ($adapter)" env DATABASE_ADAPTER=$adapter rails db:prepare + + if needs_seeding; then + step "Seeding the database ($adapter)" env DATABASE_ADAPTER=$adapter rails db:seed + fi + fi + done fi step "Cleaning up logs and tempfiles" rails log:clear tmp:clear diff --git a/config/ci.rb b/config/ci.rb index 9ba7b979d..b642c2534 100644 --- a/config/ci.rb +++ b/config/ci.rb @@ -7,12 +7,17 @@ CI.run do step "Style: Ruby", "bin/rubocop" - step "Security: Gem audit", "bin/bundler-audit check --update" + step "Security: Gem audit", "bin/bundler-audit check --update" step "Security: Importmap audit", "bin/importmap audit" - step "Security: Brakeman audit", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error" + step "Security: Brakeman audit", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error" + + if Fizzy.saas? + step "Tests: SaaS", "SAAS=true BUNDLE_GEMFILE=Gemfile.saas bin/rails test:all" + else + step "Tests: MySQL", "SAAS=false BUNDLE_GEMFILE=Gemfile DATABASE_ADAPTER=mysql bin/rails test:all" + step "Tests: SQLite", "SAAS=false BUNDLE_GEMFILE=Gemfile DATABASE_ADAPTER=sqlite bin/rails test:all" + end - step "Tests: Open source", "bin/rails test" - step "Tests: System", "bin/rails test:system" if success? step "Signoff: All systems go. Ready for merge and deploy.", "gh signoff" diff --git a/lib/fizzy.rb b/lib/fizzy.rb index 69b3f9c6f..e009c8f78 100644 --- a/lib/fizzy.rb +++ b/lib/fizzy.rb @@ -2,7 +2,7 @@ module Fizzy class << self def saas? return @saas if defined?(@saas) - @saas = !!(ENV["SAAS"] || File.exist?(File.expand_path("../tmp/saas.txt", __dir__))) + @saas = !!(((ENV["SAAS"] || File.exist?(File.expand_path("../tmp/saas.txt", __dir__))) && ENV["SAAS"] != "false")) end def db_adapter