Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rails engine exposing a page of git version info.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app/controllers
lib
.gitignore
Readme.md
plus2_version.gemspec

Readme.md

Plus2 version

A Rails engine for exposing git version info.

installation

In your Gemfile

gem 'plus2_version'

then

bundle install

sha-stamp mode

Create an initialiser, such as plus2_version.rb

require 'plus2_version'

Plus2Version.git_path = '/path/to/git/if/you/like'

# take snapshot of the git sha
Plus2Version::VersionFinder.snapshot_version(:init)

# optionally - log the sha
Rails.logger.info "git sha #{Plus2Version::VersionFinder.sha_at(:init)}"

# optionally - use the sha to namespace your cache entries: a redeploy automatically "expires" your cache entries!
Rails.cache.options[:namespace] = "app:" + Plus2Version::VersionFinder.sha_at(:init)[0..7]

Now, in a page in your app (erb):

<!-- <%= Plus2Version::VersionFinder.sha_at(:init) %> -->

snapshot

Notice how we're taking a "snapshot" of the git sha? Its an important subtlety.

The snapshot tells us which version the repo was at at boot time; even 1/2 way through a deployment, this number remains the same.

Thus we know for sure which version is running, not just which code is checked out.

Its also faster than running git every time we want the sha :)

works great with

prod_versions - A simple node.js script that fetches the stamped sha and compares it to local repos. Lets you know exactly which version of your app is running.

page mode

Page mode exposes /plus2-version which dumps the latest git log entry in json. Handy for staging, but not great for production. To set up:

In config/routes.rb

add_plus2_version_routes

And run your app. The version page is at

http://yourapp.com/plus2-version
Something went wrong with that request. Please try again.