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_COMMITis set, it returns that value. - If
GIT_BRANCHis set, it returns that value for the branch. - If
GIT_COMMITis not set and the Rails environment is development, it runsgit rev-parse HEADand returns the current SHA. - If
GIT_BRANCHis not set, it derives the branch from git (git branch --show-current, withgit rev-parse --abbrev-ref HEADas fallback). - If
GIT_COMMITis not set and the environment is not development, it returns404 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 installMounting
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/commitExample response:
commit: f2e9b8d4a3c11f2f9c2fd6f5b76f6f3cf1a1d9e2
branch: main
Testing
Run the test suite with:
bundle exec rspecLicense
MIT