mark_version 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f35e7c74b39b1c809626c10952f61ff295245575
4
+ data.tar.gz: 15bdcf1e538f11949b1ad67066b5fab113a137a9
5
+ SHA512:
6
+ metadata.gz: a8cf25e4603c898e339805a1e24fa4ade50e73bd26afc9f4d4f695029dd03d9a1ae85a98216c158acd0c1c31af192baf3eace958bd9b2566f8615e63ed689b7c
7
+ data.tar.gz: a0a20eb179613d13a763fa63b64b3702a0e9227f7daf160c459959053af7ad2780e156f0a968f48dcc88532129afc8d10c34a33cd6276a00abcc4aedfcc38f86
data/.gitignore ADDED
@@ -0,0 +1,35 @@
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
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Grayden Smith
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # mark_version
2
+ A ruby gem used to track versions of ruby applications and tools
@@ -0,0 +1,118 @@
1
+ class VersionFile
2
+ attr_reader :file_name
3
+
4
+ def initialize(file_name = 'VERSION')
5
+ fail "Version file '#{file_name}' does not exist." unless File.file?(file_name)
6
+ @file_name = file_name
7
+ @version_file = open(file_name, 'r+')
8
+ end
9
+
10
+ def version
11
+ @version_file.rewind
12
+ version = @version_file.readline.chomp
13
+ version
14
+ end
15
+
16
+ def short_version
17
+ return version unless release_candidate?
18
+
19
+ version.split('-')[0]
20
+ end
21
+
22
+ def patch
23
+ fail 'Cannot patch a release candidate, it needs to be released first.' if release_candidate?
24
+ version = version_as_array
25
+ version[2] = (version[2].to_i + 1).to_s
26
+
27
+ write(version.join('.'))
28
+ end
29
+
30
+ def minor
31
+ fail 'Cannot minor increment a release candidate, it needs to be released first.' if release_candidate?
32
+ version = version_as_array
33
+ version[2] = '0'
34
+ version[1] = (version[1].to_i + 1).to_s
35
+
36
+ write(version.join('.'))
37
+ end
38
+
39
+ def major
40
+ fail 'Cannot major increment a release candidate, it needs to be released first.' if release_candidate?
41
+ version = version_as_array
42
+ version[2] = '0'
43
+ version[1] = '0'
44
+ version[0] = (version[0].to_i + 1).to_s
45
+
46
+ write(version.join('.'))
47
+ end
48
+
49
+ def minor_release_candidate
50
+ fail 'Cannot make a releae candidate out of a release candidate. To increment to the next release candidate, invoke "increment_release_candidate".' if release_candidate?
51
+ minor
52
+ write("#{short_version}-RC1")
53
+ end
54
+
55
+ def major_release_candidate
56
+ fail 'Cannot make a releae candidate out of a release candidate. To increment to the next release candidate, invoke "increment_release_candidate".' if release_candidate?
57
+ major
58
+ write("#{version}-RC1")
59
+ end
60
+
61
+ def increment_release_candidate
62
+ fail 'Cannot increment the release candidate version on a non release candidate.' unless release_candidate?
63
+ write("#{short_version}-RC#{next_release_candidate}")
64
+ end
65
+
66
+ def release
67
+ fail 'Cannot release a non release candidate.' unless release_candidate?
68
+ write(short_version)
69
+ end
70
+
71
+ def current_patch_version
72
+ if version.include?('RC')
73
+ version_as_array[2].split('-')[0]
74
+ else
75
+ version_as_array[2]
76
+ end
77
+ end
78
+
79
+ def current_minor_version
80
+ version_as_array[1]
81
+ end
82
+
83
+ def current_major_version
84
+ version_as_array[0]
85
+ end
86
+
87
+ def release_candidate_iteration
88
+ version.split('RC')[1].to_s
89
+ end
90
+
91
+ def release_candidate?
92
+ version.include?('RC')
93
+ end
94
+
95
+ private
96
+
97
+ def version_as_array
98
+ version.split('.')
99
+ end
100
+
101
+ def next_release_candidate
102
+ return 1 unless release_candidate?
103
+
104
+ release_candidate_iteration.to_i + 1
105
+ end
106
+
107
+ def revision
108
+ `git rev-parse --short HEAD`.chomp
109
+ end
110
+
111
+ def write(version)
112
+ @version_file.rewind
113
+ @version_file.puts(version)
114
+ @version_file.print(revision)
115
+ @version_file.rewind
116
+ version
117
+ end
118
+ end
@@ -0,0 +1 @@
1
+ require 'mark_version/version_file.rb'
@@ -0,0 +1,80 @@
1
+ namespace :version do
2
+ def version
3
+ VersionFile.new.version
4
+ end
5
+
6
+ def file_name
7
+ VersionFile.new.file_name
8
+ end
9
+
10
+ def commit
11
+ system("git add #{file_name}")
12
+ system("git commit -m 'To version #{version}'")
13
+ end
14
+
15
+ def tag
16
+ system("git tag #{version} -a -m \"Release version #{version}\"")
17
+ end
18
+
19
+ desc "create a new patch-level (n.n.X) release"
20
+
21
+ task :patch => :environment do
22
+ VersionFile.new.patch
23
+ commit
24
+ tag
25
+ end
26
+
27
+ desc "create a new minor-level (n.X.n) release"
28
+
29
+ task :minor => :environment do
30
+ VersionFile.new.minor
31
+ commit
32
+ tag
33
+ end
34
+
35
+ desc "create a new major-level (X.n.n) release"
36
+
37
+ task :major => :environment do
38
+ VersionFile.new.major
39
+ commit
40
+ tag
41
+ end
42
+
43
+ desc "create a new minor-level (n.X.n-RC1) release candidate"
44
+
45
+ task :minor_release_candidate => :environment do
46
+ VersionFile.new.minor_release_candidate
47
+ commit
48
+ tag
49
+ end
50
+
51
+ desc "create a new major-level (X.n.n-RC1) release candidate"
52
+
53
+ task :major_release_candidate => :environment do
54
+ VersionFile.new.major_release_candidate
55
+ commit
56
+ tag
57
+ end
58
+
59
+ desc "increments the current release candidate (n.n.n-RCX)"
60
+
61
+ task :increment_release_candidate => :environment do
62
+ VersionFile.new.increment_release_candidate
63
+ commit
64
+ tag
65
+ end
66
+
67
+ desc "releases the current release candidate (n.n.n)"
68
+
69
+ task :release => :environment do
70
+ VersionFile.new.release
71
+ commit
72
+ tag
73
+ end
74
+
75
+ desc "print the current version level from the VERSION file"
76
+
77
+ task :show => :environment do
78
+ puts version
79
+ end
80
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'mark_version'
3
+ s.version = '0.0.0'
4
+ s.date = '2015-05-30'
5
+ s.summary = 'A tool for recording the version of a ruby application.'
6
+ s.authors = ['Grayden Smith']
7
+ s.email = 'grayden@tech-vision.ca'
8
+ s.files = `git ls-files`.split($/)
9
+ s.homepage = 'http://graydens.ca'
10
+ s.license = 'MIT'
11
+
12
+ s.add_development_dependency 'rspec', '~> 3.2'
13
+ end
@@ -0,0 +1,2 @@
1
+ 0.9.12
2
+ 42324b
@@ -0,0 +1,306 @@
1
+ require 'mark_version'
2
+
3
+ describe VersionFile do
4
+ let(:file_path) { 'spec/fixtures/version_file.txt' }
5
+
6
+ before(:each) do
7
+ File.write(file_path, "0.9.12\n42324b")
8
+ end
9
+
10
+ def version_file
11
+ VersionFile.new(file_path)
12
+ end
13
+
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
+ it 'is able to get the version file name' do
20
+ expect(version_file.file_name).to eq file_path
21
+ end
22
+
23
+ context 'incrementing the patch version' do
24
+ before(:each) do
25
+ version_file.patch
26
+ end
27
+
28
+ it 'increments patch version' do
29
+ expect(version_file.current_patch_version).to eq '13'
30
+ end
31
+
32
+ it 'keeps the minor version the same' do
33
+ expect(version_file.current_minor_version).to eq '9'
34
+ end
35
+
36
+ it 'keeps the major version the same' do
37
+ expect(version_file.current_major_version).to eq '0'
38
+ end
39
+
40
+ it 'does not be a release candidate' do
41
+ expect(version_file.release_candidate?).not_to be
42
+ end
43
+ end
44
+
45
+ context 'incrementing the minor version' do
46
+ before(:each) do
47
+ version_file.minor
48
+ end
49
+
50
+ it 'resets the patch version' do
51
+ expect(version_file.current_patch_version).to eq '0'
52
+ end
53
+
54
+ it 'increments the minor version' do
55
+ expect(version_file.current_minor_version).to eq '10'
56
+ end
57
+
58
+ it 'does not change the major version' do
59
+ expect(version_file.current_major_version).to eq '0'
60
+ end
61
+
62
+ it 'does not be a release candidate' do
63
+ expect(version_file).not_to be_release_candidate
64
+ end
65
+ end
66
+
67
+ context 'incrementing the major version' do
68
+ before(:each) do
69
+ version_file.major
70
+ end
71
+
72
+ it 'resets the patch version' do
73
+ expect(version_file.current_patch_version).to eq '0'
74
+ end
75
+
76
+ it 'resets the minor version' do
77
+ expect(version_file.current_minor_version).to eq '0'
78
+ end
79
+
80
+ it 'increments major version' do
81
+ expect(version_file.current_major_version).to eq '1'
82
+ end
83
+
84
+ it 'does not be a release candidate' do
85
+ expect(version_file).not_to be_release_candidate
86
+ end
87
+ end
88
+
89
+ context 'creating a minor version release candidate' do
90
+ before(:each) do
91
+ version_file.minor_release_candidate
92
+ end
93
+
94
+ it 'marks the version as a release candidate' do
95
+ expect(version_file).to be_release_candidate
96
+ end
97
+
98
+ it 'resets the patch version' do
99
+ expect(version_file.current_patch_version).to eq '0'
100
+ end
101
+
102
+ it 'increments the minor version' do
103
+ expect(version_file.current_minor_version).to eq '10'
104
+ end
105
+
106
+ it 'does not change the major version' do
107
+ expect(version_file.current_major_version).to eq '0'
108
+ end
109
+
110
+ it 'is at RC iteration 1' do
111
+ expect(version_file.release_candidate_iteration).to eq '1'
112
+ end
113
+
114
+ it 'has RC and the RC version number at the end of the name' do
115
+ expect(version_file.version).to eq '0.10.0-RC1'
116
+ end
117
+ end
118
+
119
+ context 'creating a major version release candidate' do
120
+ before(:each) do
121
+ version_file.major_release_candidate
122
+ end
123
+
124
+ it 'marks the version as a release candidate' do
125
+ expect(version_file).to be_release_candidate
126
+ end
127
+
128
+ it 'resets the patch version' do
129
+ expect(version_file.current_patch_version).to eq '0'
130
+ end
131
+
132
+ it 'increments the minor version' do
133
+ expect(version_file.current_minor_version).to eq '0'
134
+ end
135
+
136
+ it 'does not change the major version' do
137
+ expect(version_file.current_major_version).to eq '1'
138
+ end
139
+
140
+ it 'is at RC iteration 1' do
141
+ expect(version_file.release_candidate_iteration).to eq '1'
142
+ end
143
+
144
+ it 'has RC and the RC version number at the end of the name' do
145
+ expect(version_file.version).to eq '1.0.0-RC1'
146
+ end
147
+ end
148
+
149
+ context 'incrementing a minor version release candidate' do
150
+ before(:each) do
151
+ version_file.minor_release_candidate
152
+ version_file.increment_release_candidate
153
+ end
154
+
155
+ it 'marks the version as a release candidate' do
156
+ expect(version_file).to be_release_candidate
157
+ end
158
+
159
+ it 'resets the patch version' do
160
+ expect(version_file.current_patch_version).to eq '0'
161
+ end
162
+
163
+ it 'increments the minor version' do
164
+ expect(version_file.current_minor_version).to eq '10'
165
+ end
166
+
167
+ it 'does not change the major version' do
168
+ expect(version_file.current_major_version).to eq '0'
169
+ end
170
+
171
+ it 'is at RC iteration 2' do
172
+ expect(version_file.release_candidate_iteration).to eq '2'
173
+ end
174
+
175
+ it 'has RC and the RC version number at the end of the name' do
176
+ expect(version_file.version).to eq '0.10.0-RC2'
177
+ end
178
+ end
179
+
180
+ context 'incrementing a major version release candidate' do
181
+ before(:each) do
182
+ version_file.major_release_candidate
183
+ version_file.increment_release_candidate
184
+ end
185
+
186
+ it 'marks the version as a release candidate' do
187
+ expect(version_file).to be_release_candidate
188
+ end
189
+
190
+ it 'resets the patch version' do
191
+ expect(version_file.current_patch_version).to eq '0'
192
+ end
193
+
194
+ it 'increments the minor version' do
195
+ expect(version_file.current_minor_version).to eq '0'
196
+ end
197
+
198
+ it 'does not change the major version' do
199
+ expect(version_file.current_major_version).to eq '1'
200
+ end
201
+
202
+ it 'is at RC iteration 2' do
203
+ expect(version_file.release_candidate_iteration).to eq '2'
204
+ end
205
+
206
+ it 'has RC and the RC version number at the end of the name' do
207
+ expect(version_file.version).to eq '1.0.0-RC2'
208
+ end
209
+ end
210
+
211
+ context 'releasing a release candidate' do
212
+ context 'minor release candidate' do
213
+ before(:each) do
214
+ version_file.minor_release_candidate
215
+ version_file.release
216
+ end
217
+
218
+ it 'removes the release candidate' do
219
+ expect(version_file).not_to be_release_candidate
220
+ end
221
+
222
+ it 'does not change the patch version' do
223
+ expect(version_file.current_patch_version).to eq '0'
224
+ end
225
+
226
+ it 'does not change the minor version' do
227
+ expect(version_file.current_minor_version).to eq '10'
228
+ end
229
+
230
+ it 'does not change the major version' do
231
+ expect(version_file.current_major_version).to eq '0'
232
+ end
233
+
234
+ it 'goes back to looking like a normal release' do
235
+ expect(version_file.version).to eq '0.10.0'
236
+ end
237
+ end
238
+
239
+ context 'major release candidate' do
240
+ before(:each) do
241
+ version_file.major_release_candidate
242
+ version_file.release
243
+ end
244
+
245
+ it 'removes the release candidate' do
246
+ expect(version_file).not_to be_release_candidate
247
+ end
248
+
249
+ it 'does not change the patch version' do
250
+ expect(version_file.current_patch_version).to eq '0'
251
+ end
252
+
253
+ it 'does not change the minor version' do
254
+ expect(version_file.current_minor_version).to eq '0'
255
+ end
256
+
257
+ it 'does not change the major version' do
258
+ expect(version_file.current_major_version).to eq '1'
259
+ end
260
+
261
+ it 'goes back to looking like a normal release' do
262
+ expect(version_file.version).to eq '1.0.0'
263
+ end
264
+ end
265
+ end
266
+
267
+ context 'error conditions' do
268
+ it 'does not be able to increment the release candidate unless the current version is some kind of release candidate' do
269
+ expect { version_file.increment_release_candidate }.to raise_error
270
+ end
271
+
272
+ it 'does not be able to declare a minor release candidate unless the current version is not a release candidate' do
273
+ version_file.minor_release_candidate
274
+
275
+ expect { version_file.minor_release_candidate }.to raise_error
276
+ end
277
+
278
+ it 'does not be able to declare a minor release candidate unless the current version is not a release candidate' do
279
+ version_file.minor_release_candidate
280
+
281
+ expect { version_file.major_release_candidate }.to raise_error
282
+ end
283
+
284
+ it 'does not be able to increment the patch version on a release candidate' do
285
+ version_file.minor_release_candidate
286
+
287
+ expect { version_file.patch }.to raise_error
288
+ end
289
+
290
+ it 'does not be able to increment the minor version on a release candidate' do
291
+ version_file.minor_release_candidate
292
+
293
+ expect { version_file.minor }.to raise_error
294
+ end
295
+
296
+ it 'does not be able to increment the major version on a release candidate' do
297
+ version_file.minor_release_candidate
298
+
299
+ expect { version_file.major }.to raise_error
300
+ end
301
+
302
+ it 'cannot release a non release candidate' do
303
+ expect { version_file.release }.to raise_error
304
+ end
305
+ end
306
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mark_version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Grayden Smith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description:
28
+ email: grayden@tech-vision.ca
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rspec"
35
+ - LICENSE
36
+ - README.md
37
+ - lib/mark_version.rb
38
+ - lib/mark_version/version_file.rb
39
+ - lib/tasks/mark_version.rake
40
+ - mark_version.gemspec
41
+ - spec/fixtures/version_file.txt
42
+ - spec/version_file_spec.rb
43
+ homepage: http://graydens.ca
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.2.2
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A tool for recording the version of a ruby application.
67
+ test_files: []