build_number 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +41 -0
- data/.semver +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/build_number.gemspec +25 -0
- data/lib/build_number/version.rb +3 -0
- data/lib/build_number.rb +69 -0
- data/spec/build_number_spec.rb +51 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OThiMmExNTkxNzUwZDQ1NzdiNGM3MDJlMTAxMjY5NWRhZGY1YzgzOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWVkZDIzZDk0MWJiOGRlYzcxMzFjZWU2OTk2YzdhMjJmZGE4YTBlMw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTdiZDUyMTc5OGYwYjNhYjNiMGUxM2NkMzdlMDY0MzBlNjQ5MWQwMGMyY2Fh
|
10
|
+
N2YyYzQwMzI4YThkNzliZjJmODFmZWZhODc2ZTNhMDBmZWJiMGU2ZjhkY2Rj
|
11
|
+
ZGQxYTVjMDE3MzU1ODBjZWFlNmZlYzcxNWY4ODYxYTJmOGQ2ZmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZGI1ODQ4MDVhMmI3OTQ3YThiM2VhMGM1ZWIzMjJhMGI3NTMwNmRiYzdiZmNj
|
14
|
+
YzAwY2MzNzQyNzNiM2RlYmFlNGRjNGFhNDZjYmVmYTM5ZDdiYWExNDA2ODg0
|
15
|
+
MGFhZGRhNjkzZjc1MmFhMmM1NWZkMWU0NDY2NWY5MzhhYTkxMmQ=
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
35
|
+
|
36
|
+
# RubyMine files
|
37
|
+
.idea/
|
38
|
+
|
39
|
+
# build number
|
40
|
+
.build_number
|
41
|
+
|
data/.semver
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
build_number (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.3.2)
|
11
|
+
rspec (2.14.1)
|
12
|
+
rspec-core (~> 2.14.0)
|
13
|
+
rspec-expectations (~> 2.14.0)
|
14
|
+
rspec-mocks (~> 2.14.0)
|
15
|
+
rspec-core (2.14.8)
|
16
|
+
rspec-expectations (2.14.5)
|
17
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
18
|
+
rspec-mocks (2.14.6)
|
19
|
+
semver2 (3.3.3)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
x86-mingw32
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
build_number!
|
26
|
+
bundler (~> 1.6)
|
27
|
+
rake
|
28
|
+
rspec
|
29
|
+
semver2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Rob Scaduto
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# build_number
|
2
|
+
|
3
|
+
Creates a `.build_number` file in your current directory which will store and increment the `BUILD_NUMBER`
|
4
|
+
environment variable. This is useful when you want to keep track of build numbers outside of a continuous integration
|
5
|
+
environment.
|
6
|
+
|
7
|
+
If the `BUILD_NUMBER` variable is already set, it will not be incremented.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'build_number'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install build_number
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
In your project's Rakefile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'build_number'
|
29
|
+
BuildNumber.set_env
|
30
|
+
|
31
|
+
# ENV['BUILD_NUMBER'] is now set and incremented for the next build!
|
32
|
+
```
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it ( https://github.com/scardetto/build_number/fork )
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'semver'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'build_number'
|
8
|
+
spec.version = SemVer.find.format '%M.%m.%p'
|
9
|
+
spec.authors = ['Rob Scaduto']
|
10
|
+
spec.email = ['rscaduto@thirdwave.it']
|
11
|
+
spec.summary = %q{Store and increment build numbers}
|
12
|
+
spec.description = %q{Library for storing and incrementing a build number in your local project directory.}
|
13
|
+
spec.homepage = 'http://github.com/scardetto/build_number'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'semver2'
|
25
|
+
end
|
data/lib/build_number.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'build_number/version'
|
2
|
+
|
3
|
+
module BuildNumber
|
4
|
+
FILE_NAME = '.build_number'
|
5
|
+
|
6
|
+
def self.set_env(dir=nil)
|
7
|
+
ENV['BUILD_NUMBER'] = ENV['BUILD_NUMBER'] || increment(dir)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.increment(dir=nil)
|
11
|
+
file = find_or_create_file dir
|
12
|
+
|
13
|
+
read(file).tap do |current|
|
14
|
+
save file, current + 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_or_create_file(dir=nil)
|
19
|
+
dir ||= Dir.pwd
|
20
|
+
file = find_file dir
|
21
|
+
file = create_file dir if file.nil?
|
22
|
+
file
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.read(path)
|
26
|
+
file = File.open(path, 'rb')
|
27
|
+
current = file.read.chomp.to_i
|
28
|
+
file.close
|
29
|
+
current
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.save(path, next_build_number=0)
|
33
|
+
open(path, 'w') { |io| io.write next_build_number.to_s }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def self.find_file(dir=nil)
|
39
|
+
raise "#{dir} is not a directory" unless File.directory? dir
|
40
|
+
file_path = file_name dir
|
41
|
+
|
42
|
+
Dir.chdir dir do
|
43
|
+
until File.exists? file_path do
|
44
|
+
return nil if is_root_path? file_path
|
45
|
+
file_path = parent_path file_path
|
46
|
+
end
|
47
|
+
return file_path
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.is_root_path?(path)
|
52
|
+
File.dirname(path).match(/(\w:\/|\/)$/i)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.parent_path(path)
|
56
|
+
dir = File.join File.dirname(path), '..'
|
57
|
+
File.expand_path file_name(dir)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.create_file(dir=nil)
|
61
|
+
file = file_name(dir)
|
62
|
+
save file
|
63
|
+
file
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.file_name(dir)
|
67
|
+
File.join dir, FILE_NAME
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'build_number'
|
3
|
+
|
4
|
+
describe BuildNumber do
|
5
|
+
before :each do
|
6
|
+
@tmp_dir = Dir.mktmpdir
|
7
|
+
end
|
8
|
+
|
9
|
+
after :each do
|
10
|
+
FileUtils.remove_entry_secure @tmp_dir
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should create a .build_number file when none exists' do
|
14
|
+
path = BuildNumber.find_or_create_file @tmp_dir
|
15
|
+
path.should eq("#{@tmp_dir}/.build_number")
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should find the .build_number file in parent directory' do
|
19
|
+
path = BuildNumber.find_or_create_file @tmp_dir
|
20
|
+
|
21
|
+
nested_dir = "#{File.dirname(path)}/deeply/nested/path"
|
22
|
+
FileUtils.mkdir_p nested_dir
|
23
|
+
BuildNumber.find_or_create_file(nested_dir).should eq(path)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should save and load build number' do
|
27
|
+
build_number = random_build_number
|
28
|
+
path = BuildNumber.find_or_create_file @tmp_dir
|
29
|
+
BuildNumber.save path, build_number
|
30
|
+
BuildNumber.read(path).should eq(build_number)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise when directory does not exist' do
|
34
|
+
expect {
|
35
|
+
BuildNumber.find_or_create_file '/i/hopefully/dont/exist'
|
36
|
+
}.to raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not create a .build_number file if the 'BUILD_NUMBER' env var is already set" do
|
40
|
+
ENV['BUILD_NUMBER'] = random_build_number.to_s
|
41
|
+
BuildNumber.set_env @tmp_dir
|
42
|
+
|
43
|
+
File.exists?("#{@tmp_dir}/.build_number").should be_false
|
44
|
+
ENV['BUILD_NUMBER'] = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def random_build_number
|
48
|
+
rng = Random.new
|
49
|
+
rng.rand(100)
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: build_number
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Scaduto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-24 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: semver2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Library for storing and incrementing a build number in your local project
|
70
|
+
directory.
|
71
|
+
email:
|
72
|
+
- rscaduto@thirdwave.it
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .semver
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- build_number.gemspec
|
85
|
+
- lib/build_number.rb
|
86
|
+
- lib/build_number/version.rb
|
87
|
+
- spec/build_number_spec.rb
|
88
|
+
homepage: http://github.com/scardetto/build_number
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Store and increment build numbers
|
112
|
+
test_files:
|
113
|
+
- spec/build_number_spec.rb
|