mark_version 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mark_version/VERSION +1 -0
- data/.rspec +1 -0
- data/lib/mark_version.rb +5 -2
- data/lib/mark_version/git.rb +73 -0
- data/lib/mark_version/mark_version_cli.rb +14 -44
- data/lib/mark_version/mark_version_config.rb +82 -0
- data/lib/mark_version/project.rb +57 -0
- data/lib/mark_version/version_file.rb +11 -8
- data/mark_version.gemspec +4 -1
- data/spec/fixtures/.mark_version/CONFIG +0 -0
- data/spec/fixtures/.mark_version/LOCAL_CONFIG +1 -0
- data/spec/git_spec.rb +27 -0
- data/spec/mark_version_config_spec.rb +41 -0
- data/spec/project_spec.rb +146 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/version_file_spec.rb +45 -5
- metadata +39 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bd23ab2a35e9fb968a4277dd60cf63a32f115a9
|
4
|
+
data.tar.gz: 9bd454eaa3cb167fcdac60e8b4f1eb0b4ba800cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b667cae79ff60d3f801ffd36a996259ee976bf31dde5a5692dce78aa50c48f1e2d56608dc83ea7ce7d819f5e902e935bf5ea2f9347d89a624ea72599c789875c
|
7
|
+
data.tar.gz: fe8ce74967dd0f39ecbe20376041163f6969a0cce0a90cef552a131a1b8b375907503f896dd2d8caf759da4dc188b1833246119621a67ff15c8a2d0c92bbed28
|
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/.rspec
CHANGED
data/lib/mark_version.rb
CHANGED
@@ -1,2 +1,5 @@
|
|
1
|
-
require 'mark_version/version_file
|
2
|
-
require 'mark_version/mark_version_cli
|
1
|
+
require 'mark_version/version_file'
|
2
|
+
require 'mark_version/mark_version_cli'
|
3
|
+
require 'mark_version/git'
|
4
|
+
require 'mark_version/project'
|
5
|
+
require 'mark_version/mark_version_config'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Git
|
2
|
+
def self.branch
|
3
|
+
`git rev-parse --abbrev-ref HEAD`.chomp
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.ahead_of_version_by(branch)
|
7
|
+
`git rev-list #{self.last_version_commit}..#{branch} --count`.chomp
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.ahead_of_version?(branch)
|
11
|
+
self.ahead_of_version_by(branch).to_i > 0
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.current_ahead_of_version?
|
15
|
+
ahead_of_version?('HEAD')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.current_ahead_by
|
19
|
+
ahead_of_version_by('HEAD')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.ahead_of_release_by
|
23
|
+
`git rev-list #{closest_release_branch}..HEAD --count`.chomp
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.ahead_of_branch_by(branch)
|
27
|
+
`git rev-list #{branch}..HEAD --count`.chomp
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.closest_release_branch
|
31
|
+
branch = nil
|
32
|
+
distance = nil
|
33
|
+
|
34
|
+
MarkVersionConfig.new.release_branches.each do |branch|
|
35
|
+
if distance.nil? || ahead_of_branch_by(branch) < distance
|
36
|
+
branch = branch
|
37
|
+
distance = ahead_of_branch_by(branch)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
branch || 'master'
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.on_release_branch?
|
45
|
+
MarkVersionConfig.new.release_branches.include?(branch)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.short_hash
|
49
|
+
`git rev-parse --short HEAD`.chomp
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.last_version_commit
|
53
|
+
`git log --format="%h" .mark_version/VERSION | head -n 1`.chomp
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.commit_and_tag(version)
|
57
|
+
commit(version)
|
58
|
+
tag(version)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.commit(version)
|
62
|
+
`git add .mark_version/VERSION`
|
63
|
+
`git commit -m "To version #{version}"`
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.tag(version)
|
67
|
+
`git tag #{version} -a -m "Release version #{version}"`
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.push
|
71
|
+
`git push origin --tags`
|
72
|
+
end
|
73
|
+
end
|
@@ -5,81 +5,51 @@ class MarkVersionCli < Thor
|
|
5
5
|
|
6
6
|
desc 'init', 'initialize the project to start tracking it\'s version'
|
7
7
|
def init
|
8
|
-
|
9
|
-
commit
|
10
|
-
tag
|
8
|
+
Project.init
|
11
9
|
end
|
12
10
|
|
13
11
|
desc 'patch', 'create a new patch-level (n.n.X) release'
|
14
12
|
def patch
|
15
|
-
|
16
|
-
commit
|
17
|
-
tag
|
13
|
+
Project.patch
|
18
14
|
end
|
19
15
|
|
20
16
|
desc 'minor', 'create a new minor-level (n.X.n) release'
|
21
17
|
def minor
|
22
|
-
|
23
|
-
commit
|
24
|
-
tag
|
18
|
+
Project.minor
|
25
19
|
end
|
26
20
|
|
27
21
|
desc 'major', 'create a new major-level (X.n.n) release'
|
28
22
|
def major
|
29
|
-
|
30
|
-
commit
|
31
|
-
tag
|
23
|
+
Project.major
|
32
24
|
end
|
33
25
|
|
34
26
|
desc 'minor_release_candidate', 'create a new minor-level (n.X.n-RC1) release candidate'
|
35
27
|
def minor_release_candidate
|
36
|
-
|
37
|
-
commit
|
38
|
-
tag
|
28
|
+
Project.minor_release_candidate
|
39
29
|
end
|
40
30
|
|
41
31
|
desc 'major_release_candidate', 'create a new major-level (X.n.n-RC1) release candidate'
|
42
32
|
def major_release_candidate
|
43
|
-
|
44
|
-
commit
|
45
|
-
tag
|
33
|
+
Project.major_release_candidate
|
46
34
|
end
|
47
35
|
|
48
36
|
desc 'increment_release_candidate', 'increments the current release candidate (n.n.n-RCX)'
|
49
37
|
def increment_release_candidate
|
50
|
-
|
51
|
-
commit
|
52
|
-
tag
|
38
|
+
Project.increment_release_candidate
|
53
39
|
end
|
54
40
|
|
55
41
|
desc 'release', 'releases the current release candidate (n.n.n)'
|
56
42
|
def release
|
57
|
-
|
58
|
-
commit
|
59
|
-
tag
|
43
|
+
Project.release
|
60
44
|
end
|
61
45
|
|
62
46
|
desc 'show', "print the current version level from the VERSION file"
|
47
|
+
option :dev, type: :boolean
|
63
48
|
def show
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
def version
|
69
|
-
VersionFile.new.version
|
49
|
+
if options[:dev]
|
50
|
+
puts Project.dev_version
|
51
|
+
else
|
52
|
+
puts Project.version
|
70
53
|
end
|
71
|
-
|
72
|
-
def file_name
|
73
|
-
VersionFile.new.file_name
|
74
|
-
end
|
75
|
-
|
76
|
-
def commit
|
77
|
-
system("git add #{file_name}")
|
78
|
-
system("git commit -m 'To version #{version}'")
|
79
|
-
end
|
80
|
-
|
81
|
-
def tag
|
82
|
-
system("git tag #{version} -a -m \"Release version #{version}\"")
|
83
|
-
end
|
84
|
-
}
|
54
|
+
end
|
85
55
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class MarkVersionConfig
|
4
|
+
attr_reader :base_folder_name
|
5
|
+
|
6
|
+
def initialize(base_folder_name = '.mark_version')
|
7
|
+
@base_folder_name = base_folder_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def init
|
11
|
+
f1 = open(project_config_file, 'w')
|
12
|
+
f1.puts('{ }')
|
13
|
+
f1.close
|
14
|
+
f2 = open(local_config_file, 'w')
|
15
|
+
f2.puts('{ }')
|
16
|
+
f2.close
|
17
|
+
end
|
18
|
+
|
19
|
+
def project_config_file
|
20
|
+
"#{base_folder_name}/CONFIG"
|
21
|
+
end
|
22
|
+
|
23
|
+
def local_config_file
|
24
|
+
"#{base_folder_name}/LOCAL_CONFIG"
|
25
|
+
end
|
26
|
+
|
27
|
+
def release_branches
|
28
|
+
project_configs['release_branches'] || []
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_release_branch(branch)
|
32
|
+
configs = project_configs
|
33
|
+
|
34
|
+
configs['release_branches'] = [] if configs['release_branches'].nil?
|
35
|
+
|
36
|
+
configs['release_branches'] << branch
|
37
|
+
|
38
|
+
write_project(configs)
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_release_branch(branch)
|
42
|
+
configs = project_configs
|
43
|
+
|
44
|
+
return false if configs['release_branches'].nil?
|
45
|
+
|
46
|
+
configs['release_branches'] = configs['release_branches'] - [branch]
|
47
|
+
|
48
|
+
write_project(configs)
|
49
|
+
end
|
50
|
+
|
51
|
+
def auto_push?
|
52
|
+
local_configs['auto_push']
|
53
|
+
end
|
54
|
+
|
55
|
+
def set_auto_push(set)
|
56
|
+
configs = local_configs
|
57
|
+
|
58
|
+
configs['auto_push'] = set
|
59
|
+
|
60
|
+
write_local(configs)
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def local_configs
|
66
|
+
content = File.read(local_config_file) rescue ''
|
67
|
+
JSON.parse(content) rescue {}
|
68
|
+
end
|
69
|
+
|
70
|
+
def write_local(configs)
|
71
|
+
File.write(local_config_file, configs.to_json)
|
72
|
+
end
|
73
|
+
|
74
|
+
def project_configs
|
75
|
+
content = File.read(project_config_file) rescue ''
|
76
|
+
JSON.parse(content) rescue {}
|
77
|
+
end
|
78
|
+
|
79
|
+
def write_project(configs)
|
80
|
+
File.write(project_config_file, configs.to_json)
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Project
|
2
|
+
def self.init
|
3
|
+
Dir.mkdir('.mark_version')
|
4
|
+
VersionFile.new.init
|
5
|
+
MarkVersionConfig.new.init
|
6
|
+
commit_and_tag
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.patch
|
10
|
+
VersionFile.new.patch
|
11
|
+
commit_and_tag
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.minor
|
15
|
+
VersionFile.new.minor
|
16
|
+
commit_and_tag
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.major
|
20
|
+
VersionFile.new.major
|
21
|
+
commit_and_tag
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.minor_release_candidate
|
25
|
+
VersionFile.new.minor_release_candidate
|
26
|
+
commit_and_tag
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.major_release_candidate
|
30
|
+
VersionFile.new.major_release_candidate
|
31
|
+
commit_and_tag
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.increment_release_candidate
|
35
|
+
VersionFile.new.increment_release_candidate
|
36
|
+
commit_and_tag
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.release
|
40
|
+
VersionFile.new.release
|
41
|
+
commit_and_tag
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.version
|
45
|
+
VersionFile.new.version
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.dev_version
|
49
|
+
VersionFile.new.dev_version
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.commit_and_tag
|
53
|
+
Git.commit(VersionFile.new.version)
|
54
|
+
Git.tag(VersionFile.new.version)
|
55
|
+
Git.push if MarkVersionConfig.new.auto_push?
|
56
|
+
end
|
57
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class VersionFile
|
2
2
|
attr_reader :file_name
|
3
3
|
|
4
|
-
def initialize(file_name =
|
5
|
-
@file_name = file_name
|
4
|
+
def initialize(file_name = "#{MarkVersionConfig.new.base_folder_name}/VERSION")
|
5
|
+
@file_name = "#{file_name}"
|
6
6
|
end
|
7
7
|
|
8
8
|
def init
|
@@ -10,7 +10,6 @@ class VersionFile
|
|
10
10
|
@version_file = open(file_name, 'w')
|
11
11
|
@version_file.rewind
|
12
12
|
@version_file.puts('0.0.0')
|
13
|
-
@version_file.print(revision)
|
14
13
|
@version_file.rewind
|
15
14
|
@version_file.close
|
16
15
|
version
|
@@ -22,9 +21,18 @@ class VersionFile
|
|
22
21
|
|
23
22
|
def version
|
24
23
|
fail "Version file '#{file_name}' does not exist." unless file_exists?
|
24
|
+
|
25
25
|
@version_file = open(file_name, 'r+')
|
26
26
|
version = @version_file.readline.chomp
|
27
27
|
@version_file.close
|
28
|
+
|
29
|
+
version
|
30
|
+
end
|
31
|
+
|
32
|
+
def dev_version
|
33
|
+
return "#{version}.#{Git.branch}+#{Git.ahead_of_release_by}" unless Git.on_release_branch?
|
34
|
+
return "#{version}+#{Git.current_ahead_by}" if Git.current_ahead_of_version?
|
35
|
+
|
28
36
|
version
|
29
37
|
end
|
30
38
|
|
@@ -119,15 +127,10 @@ class VersionFile
|
|
119
127
|
release_candidate_iteration.to_i + 1
|
120
128
|
end
|
121
129
|
|
122
|
-
def revision
|
123
|
-
`git rev-parse --short HEAD`.chomp
|
124
|
-
end
|
125
|
-
|
126
130
|
def write(version)
|
127
131
|
fail "Version file '#{file_name}' does not exist." unless file_exists?
|
128
132
|
@version_file = open(file_name, 'r+')
|
129
133
|
@version_file.puts(version)
|
130
|
-
@version_file.print(revision)
|
131
134
|
@version_file.close
|
132
135
|
version
|
133
136
|
end
|
data/mark_version.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mark_version'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.3.0'
|
4
4
|
s.date = '2015-05-30'
|
5
5
|
s.summary = 'A tool for recording the version of a ruby application.'
|
6
6
|
s.authors = ['Grayden Smith']
|
@@ -10,5 +10,8 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.homepage = 'http://graydens.ca'
|
11
11
|
s.license = 'MIT'
|
12
12
|
|
13
|
+
s.add_dependency 'json', '~> 1.8'
|
14
|
+
|
15
|
+
s.add_development_dependency 'thor', '~> 0.19'
|
13
16
|
s.add_development_dependency 'rspec', '~> 3.2'
|
14
17
|
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "auto_push": true }
|
data/spec/git_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mark_version'
|
2
|
+
|
3
|
+
describe Git do
|
4
|
+
around(:each) do |e|
|
5
|
+
Dir.mkdir('spec/fixtures/dummy_project') unless Dir.exists?('spec/fixtures/dummy_project')
|
6
|
+
Dir.chdir('spec/fixtures/dummy_project') do
|
7
|
+
`git init`
|
8
|
+
`touch hi`
|
9
|
+
`git add .`
|
10
|
+
`git commit -m "initial commit"`
|
11
|
+
end
|
12
|
+
|
13
|
+
Dir.chdir('spec/fixtures/dummy_project') do
|
14
|
+
e.run
|
15
|
+
end
|
16
|
+
|
17
|
+
FileUtils.rm_rf('spec/fixtures/dummy_project')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'retrieves the current git repository branch' do
|
21
|
+
expect(Git.branch).to eq('master')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'provides a short commit hash' do
|
25
|
+
expect(Git.short_hash).to match(/[a-f0-9]{7}/)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'mark_version'
|
2
|
+
|
3
|
+
describe MarkVersionConfig do
|
4
|
+
let(:folder_path) { 'spec/fixtures/.mark_version' }
|
5
|
+
let(:config) { described_class.new('spec/fixtures/.mark_version') }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
File.write("#{folder_path}/LOCAL_CONFIG", '{ "auto_push": true }')
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
File.write("#{folder_path}/CONFIG", '')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'retrieves that the local environment should push tags' do
|
16
|
+
expect(config.auto_push?).to eq(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sets the local config to not push tags' do
|
20
|
+
config.set_auto_push(false)
|
21
|
+
expect(config.auto_push?).to eq(false)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'adds a release branch' do
|
25
|
+
config.add_release_branch('master')
|
26
|
+
expect(config.release_branches).to eq ['master']
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'removes a release branch' do
|
30
|
+
config.add_release_branch('master')
|
31
|
+
config.add_release_branch('stable')
|
32
|
+
|
33
|
+
config.remove_release_branch('master')
|
34
|
+
|
35
|
+
expect(config.release_branches).to eq ['stable']
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns false when there are no release branches to remove' do
|
39
|
+
expect(config.remove_release_branch('master')).to eq(false)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'mark_version'
|
2
|
+
|
3
|
+
describe Project do
|
4
|
+
around(:each) do |e|
|
5
|
+
Dir.mkdir('spec/fixtures/dummy_project') unless Dir.exists?('spec/fixtures/dummy_project')
|
6
|
+
Dir.chdir('spec/fixtures/dummy_project') do
|
7
|
+
`git init`
|
8
|
+
`touch hi`
|
9
|
+
`git add hi`
|
10
|
+
`git commit -m "initial commit"`
|
11
|
+
end
|
12
|
+
|
13
|
+
Dir.chdir('spec/fixtures/dummy_project') do
|
14
|
+
e.run
|
15
|
+
end
|
16
|
+
|
17
|
+
FileUtils.rm_rf('spec/fixtures/dummy_project')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'initializes a project with version 0.0.0' do
|
21
|
+
described_class.init
|
22
|
+
|
23
|
+
expect(described_class.version).to eq('0.0.0')
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'initialized project' do
|
27
|
+
before(:each) do
|
28
|
+
described_class.init
|
29
|
+
MarkVersionConfig.new.add_release_branch('master')
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'on a release branch' do
|
33
|
+
it 'shows a project version' do
|
34
|
+
expect(described_class.version).to be
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when creating a patch' do
|
38
|
+
before(:each) do
|
39
|
+
described_class.patch
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'increments the project patch number' do
|
43
|
+
expect(described_class.version).to eq('0.0.1')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when adding a minor version' do
|
48
|
+
before(:each) do
|
49
|
+
described_class.minor
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'increments the project minor number' do
|
53
|
+
expect(described_class.version).to eq('0.1.0')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when adding a major version' do
|
58
|
+
before(:each) do
|
59
|
+
described_class.major
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'increments the project major number' do
|
63
|
+
expect(described_class.version).to eq('1.0.0')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'creating a minor release candidate' do
|
68
|
+
before(:each) do
|
69
|
+
described_class.minor_release_candidate
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'increments the project minor number and marks it as a release candidate' do
|
73
|
+
expect(described_class.version).to eq('0.1.0-RC1')
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'then incrementing a release candidate' do
|
77
|
+
before(:each) do
|
78
|
+
described_class.increment_release_candidate
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'increments the release candidate number' do
|
82
|
+
expect(described_class.version).to eq('0.1.0-RC2')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'then releasing the project' do
|
87
|
+
before(:each) do
|
88
|
+
described_class.release
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'changes the version to released' do
|
92
|
+
expect(described_class.version).to eq('0.1.0')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'creating a major release candidate' do
|
98
|
+
before(:each) do
|
99
|
+
described_class.major_release_candidate
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'increments the project major number and marks it as a release candidate' do
|
103
|
+
expect(described_class.version).to eq('1.0.0-RC1')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'then adding a commit' do
|
108
|
+
before(:each) do
|
109
|
+
`touch hello`
|
110
|
+
`git add .`
|
111
|
+
`git commit -m "second commit"`
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'keeps the same default version' do
|
115
|
+
expect(described_class.version).to eq('0.0.0')
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'shows details in the dev version' do
|
119
|
+
expect(described_class.dev_version).to eq('0.0.0+1')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'off of a release branch' do
|
125
|
+
before(:each) do
|
126
|
+
`git checkout -b feature1 2> /dev/null`
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'provides a dev version that shows the current branch plus 0' do
|
130
|
+
expect(described_class.dev_version).to eq('0.0.0.feature1+0')
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'then adding a commit' do
|
134
|
+
before(:each) do
|
135
|
+
`touch hello`
|
136
|
+
`git add .`
|
137
|
+
`git commit -m "second commit"`
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'provides a dev version that shows progress down the release branch' do
|
141
|
+
expect(described_class.dev_version).to eq('0.0.0.feature1+1')
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/version_file_spec.rb
CHANGED
@@ -5,21 +5,61 @@ describe VersionFile do
|
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
File.write(file_path, "0.9.12\n42324b")
|
8
|
+
allow(Git).to receive(:current_ahead_of_version?).and_return(false)
|
9
|
+
allow(Git).to receive(:on_release_branch?).and_return(true)
|
8
10
|
end
|
9
11
|
|
10
12
|
def version_file
|
11
13
|
VersionFile.new(file_path)
|
12
14
|
end
|
13
15
|
|
14
|
-
it 'gets the current version from the file' do
|
15
|
-
# versions should be in format: i.e. '0.9.12'
|
16
|
-
expect(version_file.version).to match(/^\d+\.\d+.\d+/)
|
17
|
-
end
|
18
|
-
|
19
16
|
it 'is able to get the version file name' do
|
20
17
|
expect(version_file.file_name).to eq file_path
|
21
18
|
end
|
22
19
|
|
20
|
+
describe 'the current version' do
|
21
|
+
context 'when at the current version' do
|
22
|
+
it 'gets the current dev version from the file' do
|
23
|
+
expect(version_file.dev_version).to eq('0.9.12')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'gets the current version from the file' do
|
27
|
+
expect(version_file.version).to eq('0.9.12')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'when ahead of the current version' do
|
32
|
+
before(:each) do
|
33
|
+
allow(Git).to receive(:current_ahead_of_version?).and_return(true)
|
34
|
+
allow(Git).to receive(:current_ahead_by).and_return(4)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'the dev version shows the number of commits that have been added since the last version' do
|
38
|
+
expect(version_file.dev_version).to eq('0.9.12+4')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'the version shows the basic semantic version number' do
|
42
|
+
expect(version_file.version).to eq('0.9.12')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when on a feature branch' do
|
47
|
+
before(:each) do
|
48
|
+
allow(Git).to receive(:on_release_branch?).and_return(false)
|
49
|
+
allow(Git).to receive(:ahead_of_release_by).and_return(7)
|
50
|
+
allow(Git).to receive(:branch).and_return('feature_in_dev')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'shows the current feature branch and the number of commits that have been added to it' do
|
54
|
+
expect(version_file.dev_version).to eq('0.9.12.feature_in_dev+7')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'the version shows the basic semantic version number' do
|
58
|
+
expect(version_file.version).to eq('0.9.12')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
23
63
|
context 'incrementing the patch version' do
|
24
64
|
before(:each) do
|
25
65
|
version_file.patch
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mark_version
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grayden Smith
|
@@ -10,6 +10,34 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.19'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.19'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rspec
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -32,15 +60,25 @@ extensions: []
|
|
32
60
|
extra_rdoc_files: []
|
33
61
|
files:
|
34
62
|
- ".gitignore"
|
63
|
+
- ".mark_version/VERSION"
|
35
64
|
- ".rspec"
|
36
65
|
- LICENSE
|
37
66
|
- README.md
|
38
67
|
- bin/version
|
39
68
|
- lib/mark_version.rb
|
69
|
+
- lib/mark_version/git.rb
|
40
70
|
- lib/mark_version/mark_version_cli.rb
|
71
|
+
- lib/mark_version/mark_version_config.rb
|
72
|
+
- lib/mark_version/project.rb
|
41
73
|
- lib/mark_version/version_file.rb
|
42
74
|
- mark_version.gemspec
|
75
|
+
- spec/fixtures/.mark_version/CONFIG
|
76
|
+
- spec/fixtures/.mark_version/LOCAL_CONFIG
|
43
77
|
- spec/fixtures/version_file.txt
|
78
|
+
- spec/git_spec.rb
|
79
|
+
- spec/mark_version_config_spec.rb
|
80
|
+
- spec/project_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
44
82
|
- spec/version_file_spec.rb
|
45
83
|
homepage: http://graydens.ca
|
46
84
|
licenses:
|