How to add build number and date from github in ruby ​​code?

How can you automatically import the latest github commit value from github?

The goal is to have this number appear on the footer of a web page, such as SO, with the date.

Structure :

I have a production branch that deploys using Capistrano. I want to show the latest github commit number with its deployment date.

+4
source share
2 answers

Assuming you are using gem settingslogic to configure your application, put this in your initializers:

 git_log = `git log -1 --pretty="format:%H %ci"` if git_log =~ /^([\d\w]+?)\s(.+)$/ Settings[:git_revision] = $1 Settings[:git_update] = $2.strip end 

You will have the last git commit SHA in Settings.git_revision and the commit date in Settings.git_update .

Alternatively, you can get the latest tag:

 git_tag = `git describe --tags --abbrev=0` Settings[:git_tag] = git_tag.strip if git_tag 

It will be available at Settings.git_tag .

Update:

I released a small ruby git-revision stone. With it, you can simply:

 "commit: #{Git::Revision.commit} date: #{Git::Revision.date}" 
+5
source

As a possible solution, you can see a (universal) solution with git smudge | clean filters (see section "Keyword Extension")

0
source

Source: https://habr.com/ru/post/1386251/


All Articles