Skip to content

Allow for prerequisites to be declared and run #149

Open
saturnflyer wants to merge 3 commits intomainfrom
prereq
Open

Allow for prerequisites to be declared and run #149
saturnflyer wants to merge 3 commits intomainfrom
prereq

Conversation

@saturnflyer
Copy link
Member

@saturnflyer saturnflyer commented Dec 18, 2025

Adds a unified setup entry point (Discharger::Setup) that orchestrates the full application setup lifecycle, including tasks that must run before Rails loads.

Problem

Some setup tasks need to run before Rails initializes—setting environment variables that database.yml reads, installing Homebrew, or ensuring PostgreSQL client tools are available. Previously, developers were adding this logic directly to bin/setup, which defeats the purpose of configuring setup through setup.yml.

Solution

The setup lifecycle is now split into phases:

  1. Load Bundler — Activates correct gem versions (must happen before YAML parsing to avoid psych conflicts)
  2. Run pre_steps — Environment variables, Homebrew, PostgreSQL tools (before Rails)
  3. Load Rails — Now has access to env vars set in step 2
  4. Run setup steps — Standard Discharger commands (after Rails)

New configuration in setup.yml:

pre_steps:
  - homebrew
  - postgresql_tools

Simplified bin/setup:

require "discharger/setup"
Discharger::Setup.run("config/setup.yml")

Key files

  • lib/discharger/setup.rb — Main orchestrator
  • lib/discharger/setup_runner/prerequisites_loader.rb — Handles pre-Rails setup
  • lib/discharger/setup_runner/pre_commands/ — Built-in pre-commands (Homebrew, PostgreSQL tools)
  • lib/discharger/setup_runner/configuration.rb — Added pre_steps attribute

Copy link
Contributor

@cseeman cseeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good Jim. Just a heads up that discharger hasn't been changed over to git fragments yet, and is still on changelog. Also with these new pre-steps, they probably should be documented in the README somewhere. Maybe around the Using Default Steps section?

Setup tasks like setting environment variables and installing system
dependencies need to run before Rails loads. This allows bin/setup to
remain minimal while configuring pre-Rails steps in setup.yml.

Version: minor
Added: Unified setup entry point with pre-steps support
These generated files should not be tracked.
Add respond_to? guards for config accessors in DockerCommand for
consistency with PgToolsCommand. Document pre_steps in README.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@saturnflyer saturnflyer requested a review from cseeman March 10, 2026 15:04
Copy link
Contributor

@cseeman cseeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Jim, looks great, the respond_to? guards and README section are exactly what I was hoping for. Nice placement before "Using Default Steps" too.

One thing I noticed while re-reading: the evaluate_condition method in prerequisites_loader.rb handles File.exist?('...') but doesn't have a case for the negated form !File.exist?('...'). The README example uses condition: "!File.exist?('.env')" which would fall through to the else branch and always return false, silently skipping the step.

Might just need another when clause like the ENV patterns already have. Something like:

when /^!File\.exist\?\(['"](.+)['"]\)$/
  !File.exist?($1)

Not a blocker, just wanted to flag it before it trips someone up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants