app_revision 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/app_revision.gemspec +23 -0
- data/lib/app_revision/version.rb +3 -0
- data/lib/app_revision.rb +59 -0
- data/spec/app_revision_spec.rb +58 -0
- data/spec/spec_helper.rb +14 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ed2215f23235f03ade7fd73df421c04df6a4acad7cb94202ea388c38b2fd258
|
4
|
+
data.tar.gz: 8dab5494ff477d771de7aaf4068b6285ff5c1b87018434897d4049e58aa4a1f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48b4fff69ad74d66e4879650555faad8e0da532600584c391f823c9deb2794f99f6d52b2e8c8598d9d854533f6d43d26ab12131a61301851fbc3ced112ca2b66
|
7
|
+
data.tar.gz: 1f13fb5fe11351c137c4a93b55f78535f462617c1b7de5f30634d3953feaf36d1f0d29333af0aeea9e730caa2152ada0ff6788b8ce0207b5344949b7297165da
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 WeTransfer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# AppRevision
|
2
|
+
|
3
|
+
Returns the current application git commit SHA. Will look first in the APP_REVISION
|
4
|
+
environment variable, then in the REVISION file written by Capsitrano, then
|
5
|
+
in the Git history and lastly will return 'unknown' will be returned
|
6
|
+
|
7
|
+
# Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'app_revision'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
AppRevision.current #=> "43ec44d89706ca948daea5124fdcc62694a87f43"
|
23
|
+
```
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/WeTransfer/app_revision.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "app_revision/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "app_revision"
|
8
|
+
spec.version = AppRevision::VERSION
|
9
|
+
spec.authors = ["Julik Tarkhanov"]
|
10
|
+
spec.email = ["me@julik.nl"]
|
11
|
+
|
12
|
+
spec.summary = %q{Finds a way to get at your git commit SHA}
|
13
|
+
spec.description = %q{Finds a way to get at your git commit SHA}
|
14
|
+
spec.homepage = "https://github.com/WeTransfer/app_revision"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
end
|
data/lib/app_revision.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "app_revision/version"
|
2
|
+
|
3
|
+
# Returns the current application git commit SHA. Will look first in the APP_REVISION
|
4
|
+
# environment variable, then in the REVISION file written by Capsitrano, then
|
5
|
+
# in the Git history and lastly will return 'unknown' will be returned
|
6
|
+
module AppRevision
|
7
|
+
ENV_VARS = ['APP_REVISION', 'HEROKU_REVISION']
|
8
|
+
|
9
|
+
# Calls `determine_current` with memoization.
|
10
|
+
def self.current
|
11
|
+
@current ||= determine_current
|
12
|
+
end
|
13
|
+
|
14
|
+
# Performs version detection in the following order:
|
15
|
+
# APP_REVISION -> REVISION file -> git -> "unknown"
|
16
|
+
# and returns the current commit/revision SHA as a String
|
17
|
+
def self.determine_current
|
18
|
+
detected_rev_str = read_from_env || read_from_revision_file || determine_from_git_rev || unknown_revision
|
19
|
+
up_to_newline(detected_rev_str)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.up_to_newline(str)
|
25
|
+
str.scan(/[a-z0-9\-]+/)[0]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.unknown_revision
|
29
|
+
'unknown'
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.determine_from_git_rev
|
33
|
+
cmd_output = `git rev-parse --verify HEAD`.strip
|
34
|
+
return cmd_output if cmd_output =~ /^[a-f\d]{40}$/
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.read_from_env
|
38
|
+
ENV_VARS.each do |envvar|
|
39
|
+
envvar_value = ENV.fetch(envvar, '').strip
|
40
|
+
return envvar_value unless envvar_value.empty?
|
41
|
+
end
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.read_from_revision_file
|
46
|
+
my_directory = File.dirname(__FILE__)
|
47
|
+
my_location = File.split(File.expand_path(my_directory))
|
48
|
+
begin
|
49
|
+
File.read(File.join(my_location + ['REVISION'])).chomp
|
50
|
+
rescue Errno::ENOENT
|
51
|
+
my_location.pop # Remove the last path part and try again
|
52
|
+
if my_location.empty?
|
53
|
+
return nil
|
54
|
+
else
|
55
|
+
retry
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
RSpec.describe AppRevision do
|
2
|
+
it "has a version number" do
|
3
|
+
expect(AppRevision::VERSION).not_to be nil
|
4
|
+
end
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@app_revision_location = AppRevision.method(:current).source_location[0]
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'always provides a string value from .current' do
|
11
|
+
expect(AppRevision.current).to be_kind_of(String)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'is set in the APP_REVISION environment variable on startup' do
|
15
|
+
ENV['APP_REVISION'] = 'some-customized-rev'
|
16
|
+
expect(AppRevision.determine_current).to eq('some-customized-rev')
|
17
|
+
ENV.delete('APP_REVISION')
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
describe 'with each environment variable that can be used' do
|
22
|
+
AppRevision::ENV_VARS.each do |ev|
|
23
|
+
it "only uses the SHA component from #{ev} up to but excluding the newline" do
|
24
|
+
ENV[ev] = "43ec44d89706ca948daea5124fdcc62694a87f43\na85f99a"
|
25
|
+
expect(AppRevision.determine_current).to eq('43ec44d89706ca948daea5124fdcc62694a87f43')
|
26
|
+
ENV.delete(ev)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not use #{ev} if it is empty" do
|
30
|
+
ENV[ev] = " "
|
31
|
+
expect(AppRevision.determine_current).not_to be_empty
|
32
|
+
ENV.delete(ev)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns "unknown" if all version detection methods return nil' do
|
38
|
+
expect(AppRevision).to receive(:read_from_env).and_return(nil)
|
39
|
+
expect(AppRevision).to receive(:read_from_revision_file).and_return(nil)
|
40
|
+
expect(AppRevision).to receive(:determine_from_git_rev).and_return(nil)
|
41
|
+
|
42
|
+
expect(AppRevision.determine_current).to eq('unknown')
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns the contents of the REVISION without the newline' do
|
46
|
+
ENV.delete('APP_REVISION')
|
47
|
+
revision_file_path = File.dirname(File.dirname(@app_revision_location)) + "/REVISION"
|
48
|
+
|
49
|
+
begin
|
50
|
+
File.open(revision_file_path, "w") do |f|
|
51
|
+
f << "43ec44d89706ca948daea5124fdcc62694a87f43\na85f99a"
|
52
|
+
end
|
53
|
+
expect(AppRevision.determine_current).to eq('43ec44d89706ca948daea5124fdcc62694a87f43')
|
54
|
+
ensure
|
55
|
+
File.unlink(revision_file_path)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "app_revision"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app_revision
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julik Tarkhanov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Finds a way to get at your git commit SHA
|
56
|
+
email:
|
57
|
+
- me@julik.nl
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- app_revision.gemspec
|
70
|
+
- lib/app_revision.rb
|
71
|
+
- lib/app_revision/version.rb
|
72
|
+
- spec/app_revision_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/WeTransfer/app_revision
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.7.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Finds a way to get at your git commit SHA
|
98
|
+
test_files: []
|