Project

shalala

0.0
No release in over 3 years
Mounts /commit and returns a git commit SHA based on environment rules.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

Runtime

>= 7.0
 Project Readme

Shalala

Shalala is a Rails engine that exposes the current git commit SHA and branch name at /commit.

What it does

When you request GET /commit:

  • If GIT_COMMIT is set, it returns that value.
  • If GIT_BRANCH is set, it returns that value for the branch.
  • If GIT_COMMIT is not set and the Rails environment is development, it runs git rev-parse HEAD and returns the current SHA.
  • If GIT_BRANCH is not set, it derives the branch from git (git branch --show-current, with git rev-parse --abbrev-ref HEAD as fallback).
  • If GIT_COMMIT is not set and the environment is not development, it returns 404 Not Found.

This is useful for surfacing deployment version information in environments like staging and production.

Installation

Add this line to your application Gemfile:

gem "shalala"

Then install:

bundle install

Mounting

The engine mounts itself at /commit via an initializer, so no manual route declaration is required.

Usage examples

Set the commit explicitly (recommended for CI/CD and production):

export GIT_COMMIT=$(git rev-parse HEAD)
export GIT_BRANCH=$(git branch --show-current)

Then request:

curl http://localhost:3000/commit

Example response:

commit: f2e9b8d4a3c11f2f9c2fd6f5b76f6f3cf1a1d9e2
branch: main

Testing

Run the test suite with:

bundle exec rspec

License

MIT