diff options
author | The Bundler Bot <bot@bundler.io> | 2017-06-16 01:11:10 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-06-16 01:11:10 +0000 |
commit | 0c651a97a8edff5be1a4a00e0c1f240dcf000137 (patch) | |
tree | 9e7dfd47c004d54a5673fd9b404b7f02eae80703 /lib | |
parent | 72e20ac28ce6faed24c053fffdbcf459b444335c (diff) | |
parent | 3c552274695aae4439ce0a6d83dd36c8179089cf (diff) | |
download | bundler-0c651a97a8edff5be1a4a00e0c1f240dcf000137.tar.gz |
Auto merge of #5716 - bundler:seg-version-build-metadata, r=indirect
Print build metadata when running `bundle version`
Closes #5049.
Will get all the build metadata into `bundle env` once https://github.com/bundler/bundler/pull/5703 lands, since I don't want conflicts and want to use that code for generating the "tables"
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler.rb | 1 | ||||
-rw-r--r-- | lib/bundler/build_metadata.rb | 36 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 5 | ||||
-rw-r--r-- | lib/bundler/env.rb | 1 |
4 files changed, 42 insertions, 1 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 1228785734..9bcadc381f 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -13,6 +13,7 @@ require "bundler/rubygems_integration" require "bundler/version" require "bundler/constants" require "bundler/current_ruby" +require "bundler/build_metadata" module Bundler environment_preserver = EnvironmentPreserver.new(ENV, EnvironmentPreserver::BUNDLER_KEYS) diff --git a/lib/bundler/build_metadata.rb b/lib/bundler/build_metadata.rb new file mode 100644 index 0000000000..54436f982d --- /dev/null +++ b/lib/bundler/build_metadata.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Bundler + # Represents metadata from when the Bundler gem was built. + module BuildMetadata + # begin ivars + @release = false + # end ivars + + # A hash representation of the build metadata. + def self.to_h + { + "Built At" => built_at, + "Git SHA" => git_commit_sha, + "Released Version" => release?, + } + end + + # A string representing the date the bundler gem was built. + def self.built_at + @built_at ||= Time.now.utc.strftime("%Y-%m-%d").freeze + end + + # The SHA for the git commit the bundler gem was built from. + def self.git_commit_sha + @git_commit_sha ||= Dir.chdir(File.expand_path("..", __FILE__)) do + `git rev-parse --short HEAD`.strip.freeze + end + end + + # Whether this is an official release build of Bundler. + def self.release? + @release + end + end +end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index e93fc9529d..0c89e41656 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -395,7 +395,10 @@ module Bundler desc "version", "Prints the bundler's version information" def version - Bundler.ui.info "Bundler version #{Bundler::VERSION}" + if ARGV.include?("version") + build_info = " (#{BuildMetadata.built_at} commit #{BuildMetadata.git_commit_sha})" + end + Bundler.ui.info "Bundler version #{Bundler::VERSION}#{build_info}" end map %w[-v --version] => :version diff --git a/lib/bundler/env.rb b/lib/bundler/env.rb index 325b96fbfa..333173ac27 100644 --- a/lib/bundler/env.rb +++ b/lib/bundler/env.rb @@ -14,6 +14,7 @@ module Bundler out = String.new append_formatted_table("Environment", environment, out) + append_formatted_table("Bundler Build Metadata", BuildMetadata.to_h, out) unless Bundler.settings.all.empty? out << "\n## Bundler settings\n\n```\n" |