Skip to content
Edit this page View source of this page

Development

This page is for contributors who change, test, or release the Mankai gems. It shows you how to set up the repository, run the tests and linters, build these docs, add a changelog entry, and release a gem. For the contribution workflow and pull request rules, see Contribute.

The repository holds six gems in gems/, a separate Hanami demo app in examples/demo_app, and this documentation site in docs/. One root Gemfile loads all six gems from their directories; the gems have no Gemfiles of their own.

Every task is a make target. To list them, run make. Pass settings as make arguments, for example make test/jobs RSPEC_ARGS="spec/unit/mankai/jobs/enqueuer_spec.rb".

Set up the repository

Before you begin, install the tools pinned in mise.toml: Ruby 4.0.10, Python 3.14.10, changie 1.26.0, and ShellCheck 0.11.0. The browser client's tests also need Node.

To install the root bundle and the demo app's separate bundle, run:

make deps

Run the tests

To run every gem's specs, with the SQL gems on SQLite, plus the browser client's Node tests, run:

make test/all

Each gem also has its own target. The following table lists the test targets:

Target Runs
make test/jobs The mankai-jobs specs
make test/jobs-sql The mankai-jobs-sql specs, on DATABASE_URL (default: SQLite)
make test/cache The mankai-cache specs
make test/cache-sql The mankai-cache-sql specs, on DATABASE_URL (default: SQLite)
make test/sockets The mankai-sockets specs
make test/sockets-sql The mankai-sockets-sql specs, on DATABASE_URL (default: SQLite)
make test/js The browser client's Node tests
make test/sql-all All three SQL gems' specs, on one DATABASE_URL
make test/demo The demo app's specs, on PostgreSQL at DEMO_DATABASE_URL

test/core and test/sql are aliases for test/jobs and test/jobs-sql.

Run one spec

Each gem's .rspec file requires spec_helper, so RSpec fails if you run it from the repository root. To run one spec, pass RSPEC_ARGS to the gem's target, or run RSpec from the gem's directory:

make test/jobs RSPEC_ARGS="spec/unit/mankai/jobs/enqueuer_spec.rb:42"
cd gems/mankai-jobs && bundle exec rspec spec/unit/mankai/jobs/enqueuer_spec.rb:42

Run the SQL gems on another database

To run the SQL gems on another database, set DATABASE_URL:

make test/sql-all DATABASE_URL=postgres:///mankai_test

An empty DATABASE_URL counts as unset. The test helper adds fractional_seconds=true to MySQL and MariaDB URLs.

Run the demo app's specs

make test/demo needs PostgreSQL at DEMO_DATABASE_URL (default: postgres:///demo_app_test), with the demo app's migrations applied.

  1. Prepare the test database:

    cd examples/demo_app && HANAMI_ENV=test bundle exec hanami db prepare
    
  2. From the repository root, run the specs:

    make test/demo
    

Run the linters

To run every linter, run:

make lint/all

The following table lists the lint targets:

Target Description
make lint/all Runs ShellCheck on every script, then RuboCop in each gem and the demo app.
make lint/shell Runs ShellCheck only, at style level.
make lint/fix Applies RuboCop's safe autocorrections in every gem.
make lint/config Downloads Hanakai's shared RuboCop config into each gem's .rubocop.yml.

Each gem's .rubocop.yml is a pinned copy of the shared RuboCop config from Hanakai, the organization behind Hanami, dry-rb, and ROM. Don't edit it by hand; to update it, run make lint/config.

To lint one gem, run RuboCop from its directory:

cd gems/mankai-jobs && bundle exec rubocop

Shell scripts follow the Google Shell Style Guide, except that they keep the #!/usr/bin/env bash shebang.

Test against other databases

The database matrix runs the SQL gems against several versions of PostgreSQL, MySQL, and MariaDB in Docker containers. Before you begin, install Docker.

  1. Start the databases:

    make db/up
    
  2. Run the SQL gems on SQLite and on every database that db/up started:

    make test/matrix
    

    The logs are in tmp/matrix/.

  3. Stop the databases:

    make db/down
    

To print the connection URLs, run make db/list. To choose the versions, set DB_POSTGRES_VERSIONS, DB_MYSQL_VERSIONS, and DB_MARIADB_VERSIONS.

Continuous integration

The workflows live in .github/workflows/:

  • lint.yml runs make lint/all on Ruby 4.0.10. On pull requests, it also runs scripts/changelog-check, which fails when a gem's lib/ changed without a changelog entry.
  • test.yml runs make test/all on Ruby 4.0.10 and 3.4.13, builds every gem, and runs the demo app's specs against a PostgreSQL service container.
  • db-matrix.yml runs the SQL gems on every database in the matrix every night, when you start it by hand, or when a pull request has the full-db-matrix label.
  • docs.yml builds the docs site with make docs/build on pull requests. On pushes to main, it also deploys the site to GitHub Pages.
  • release.yml publishes a gem when you push its release tag.

Build the docs

This site is built with Zensical, pinned in requirements-docs.txt. To install it and preview the site at http://localhost:8000, run:

make docs/deps
make docs/serve

To build the site into site/, run make docs/build. The build fails on broken internal links.

The gem reference pages include each gem's README, so edit the README, not a copy. The site follows these sections:

  • Tutorials, which teach by building one thing, go in docs/get-started/tutorials/. Installation goes in docs/get-started/.
  • Guides, which cover one task each, go in docs/guides/<feature>/. Production guides go in docs/guides/production/.
  • Reference pages go in docs/reference/. Each gem page includes the gem's README.
  • Explanation pages, which cover concepts and design, go in docs/explanation/.

Add a changelog entry

Each gem owns its version (lib/**/version.rb) and its changelog state (.changie.yaml and .changes/). Mankai uses changie to collect changelog entries as small files called fragments. A pull request that changes a gem's lib/ adds a fragment to that gem.

To add a fragment, run the following command and answer the prompts:

make changie/new GEM_NAME=GEM_NAME

Replace GEM_NAME with the gem's name, for example mankai-jobs.

Don't edit CHANGELOG.md by hand; changie generates it when you release.

Release a gem

Each gem is released on its own. Release core gems before the SQL gems that depend on them.

Before you begin, check the SQL gem's dependency. Each SQL gem depends on its core gem with a ~> x.y.0 constraint. If you bump a core gem's minor or major version, update that constraint in the SQL gem's gemspec, and release the SQL gem too.

In the following steps, replace these placeholders:

  • GEM_NAME: the gem's name, for example mankai-jobs.
  • VERSION: the new version, for example 0.2.0.

  • Prepare the release:

    make release/prepare GEM_NAME=GEM_NAME VERSION=VERSION
    

    This command batches the unreleased fragments into .changes/VERSION.md, sets the version in lib/**/version.rb, merges the notes into CHANGELOG.md, and refreshes the root and demo app lockfiles.

  • Check the release:

    make release/check GEM_NAME=GEM_NAME VERSION=VERSION
    

    The check fails if the version file, the CHANGELOG.md section, or .changes/VERSION.md is missing, or if any unreleased fragments remain.

  • Commit CHANGELOG.md, .changes/, version.rb, Gemfile.lock, and examples/demo_app/Gemfile.lock.

  • Merge the commit to main.
  • Tag the merged commit, and push the tag:

    git tag gems/GEM_NAME/vVERSION
    git push origin gems/GEM_NAME/vVERSION
    

Pushing the tag starts the release.yml workflow. The workflow runs in the release environment, so a reviewer must approve it first. The workflow then does the following:

  1. Checks the tag, and checks that gems/GEM_NAME/.changes/VERSION.md exists.
  2. Gets short-lived RubyGems credentials through trusted publishing.
  3. Runs make release/check.
  4. Runs make release/publish, which builds the gem into pkg/, checks its version, and pushes it to RubyGems.
  5. Creates a GitHub release with gems/GEM_NAME/.changes/VERSION.md as its notes.

CI runs make release/publish for you. If CI can't publish, set GEM_HOST_API_KEY, and run make release/publish GEM_NAME=GEM_NAME VERSION=VERSION yourself.