rake-n-bake 1.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.
@@ -0,0 +1,26 @@
1
+ require 'term/ansicolor'
2
+
3
+ class RakeNBake
4
+ class DependencyChecker
5
+ include Term::ANSIColor
6
+
7
+ def initialize dependencies
8
+ @dependencies = Array(dependencies)
9
+ end
10
+
11
+ def check silent = false
12
+ @results = @dependencies.each_with_object({}) do |dep, results|
13
+ results[dep] = system "which #{dep} >/dev/null"
14
+ unless silent
15
+ results[dep] ? print(".".green) : print("F".red)
16
+ end
17
+ end
18
+ end
19
+
20
+ def missing
21
+ @results ||= check(true)
22
+ @results.select{|_, present| present == false}.keys
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'rake'
4
+
5
+ lib = File.expand_path("../lib", File.dirname(__FILE__))
6
+ Dir.glob("#{lib}/*.rb").each{|l| require l}
7
+
8
+ dir = File.expand_path("../tasks", File.dirname(__FILE__))
9
+ Dir.glob("#{dir}/*.rake").each { |r| import r}
@@ -0,0 +1,62 @@
1
+ require 'semver'
2
+ class RakeNBake
3
+ class SemverVersioning
4
+ def self.current_version
5
+ if File.exist? SemVer.file_name
6
+ SemVer.find
7
+ else
8
+ version = SemVer.new
9
+ version.save SemVer.file_name
10
+ version
11
+ end
12
+ end
13
+
14
+ def self.inc_major
15
+ v = current_version
16
+ v.major = v.major.to_i + 1
17
+ v.minor = '0'
18
+ v.patch = '0'
19
+ v.save
20
+ end
21
+
22
+ def self.inc_minor
23
+ v = current_version
24
+ v.minor = v.minor.to_i + 1
25
+ v.patch = '0'
26
+ v.save
27
+ end
28
+
29
+ def self.inc_patch
30
+ v = current_version
31
+ v.patch = v.patch.to_i + 1
32
+ v.save
33
+ end
34
+
35
+ def self.prerelease s
36
+ v = current_version
37
+ v.special = s
38
+ v.save
39
+ end
40
+
41
+ def self.inc_prerelease s
42
+ inc_major
43
+ v = current_version
44
+ v.special = s
45
+ v.save
46
+ end
47
+
48
+ def self.release
49
+ v = current_version
50
+ v.special = ''
51
+ v.save
52
+ end
53
+
54
+ def self.tag
55
+ v = current_version.to_s
56
+ `git add .semver && git commit -m 'Increment version to #{v}' && git tag #{v}`
57
+ branch = `git symbolic-ref HEAD`[%r{.*/(.*)}, 1]
58
+ puts "To push the new tag, use 'git push origin #{branch} --tags'"
59
+ end
60
+ end
61
+ end
62
+
data/lib/version.rb ADDED
@@ -0,0 +1,64 @@
1
+ class RakeNBake
2
+ class Version
3
+ HISTORY_FILE = "history.rdoc"
4
+ def self.current_history history_file
5
+ unless File.exists? history_file
6
+ File.open history_file, "w" do |f|
7
+ f.puts "== 0.0.0 (#{Time.now.strftime "%d %B %Y"})"
8
+ end
9
+ end
10
+ File.read history_file
11
+ end
12
+
13
+ def self.latest_version
14
+ latest_version_string = current_history(HISTORY_FILE)[/== ([\d\.]*)/, 1] || "0.0.0"
15
+ @latest_version ||= latest_version_string.split(".").map(&:to_i)
16
+ def @latest_version.to_s
17
+ join "."
18
+ end
19
+ @latest_version
20
+ end
21
+
22
+ def self.update_to version
23
+ add_history_header version
24
+ update_gem version if gem?
25
+ commit version
26
+ tag version
27
+ branch = `git symbolic-ref HEAD`[%r{.*/(.*)}, 1]
28
+ puts "To push the new tag, use 'git push origin #{branch} --tags'"
29
+ end
30
+
31
+ def self.add_history_header(version, history_file = HISTORY_FILE)
32
+ history = current_history history_file
33
+ File.open history_file, "w" do |f|
34
+ f.puts "== #{version} (#{Time.now.strftime "%d %B %Y"})"
35
+ f.puts
36
+ f.print history
37
+ end
38
+ puts "Added version to history.rdoc"
39
+ end
40
+
41
+ def self.update_gem version
42
+ path = Dir.glob('*.gemspec').first
43
+ text = File.read path
44
+ File.open(path, "w") do |file|
45
+ file.puts text.sub(/(.*version\s*=\s*)(['|"].*['|"])/, "\\1'#{version}'")
46
+ end
47
+ puts "Added version to .gemfile"
48
+ end
49
+
50
+ def self.commit version
51
+ `git add . && git commit -m 'increment version to #{version}'`
52
+ puts "Committed change"
53
+ end
54
+
55
+ def self.tag version
56
+ `git tag #{version}`
57
+ puts "Tagged with #{version}"
58
+ end
59
+
60
+ def self.gem?
61
+ !Dir.glob('*.gemspec').empty?
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rake-n-bake"
7
+ spec.version = '1.0.0'
8
+ spec.authors = ["Richard Vickerstaff", "Adam Whittingham"]
9
+ spec.email = ["m3akq@btinternet.com", "adam.whittingham@gmail.com"]
10
+ spec.description = "Common rake tasks, baked to perfection and ready to serve!"
11
+ spec.summary = "Common rake tasks, baked to perfection and ready to serve!"
12
+ spec.homepage = "https://github.com/RichardVickerstaff/rake-n-bake"
13
+ spec.license = "MIT"
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.require_paths = ["lib","tasks"]
16
+
17
+ spec.add_runtime_dependency "rake", "~> 10"
18
+ spec.add_runtime_dependency "term-ansicolor", "~> 1.3"
19
+ end
data/spec/.keep ADDED
File without changes
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'term/ansicolor'
3
+ include Term::ANSIColor
4
+
5
+ describe RakeNBake::DependencyChecker do
6
+
7
+ # Note that this test will fail if you, somehow, have this insane string define on your path
8
+ let(:missing) {'jajfjfjosojfnbje3nknq'}
9
+ let(:present) {'rspec'}
10
+ let(:list){ [present, missing] }
11
+
12
+ subject{RakeNBake::DependencyChecker.new list}
13
+
14
+ describe '#check' do
15
+ before { $stdout = StringIO.new }
16
+
17
+ it 'returns a hash of dependencies => presence' do
18
+ result = subject.check
19
+ expect(result).to eq({present => true, missing => false})
20
+ end
21
+
22
+ it 'prints a dot for dependencies which are present' do
23
+ expect{subject.check}.to output(/\./).to_stdout
24
+ end
25
+
26
+ it 'prints a F for missing dependencies' do
27
+ expect{subject.check}.to output(/F/).to_stdout
28
+ end
29
+
30
+ it 'can be run without printing anything out' do
31
+ expect{subject.check(true)}.to_not output.to_stdout
32
+ end
33
+ end
34
+
35
+ describe '#missing_from' do
36
+ it 'returns only missing dependencies' do
37
+ expect(subject.missing).to eq [missing]
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe RakeNBake::SemverVersioning do
5
+ let(:version) {
6
+ {
7
+ major: '1',
8
+ minor: '2',
9
+ patch: '3',
10
+ special: '',
11
+ metadata: ''
12
+ }
13
+ }
14
+ before(:all) do
15
+ if File.exist? File.join(File.dirname(__FILE__), '../.semver')
16
+ @current_semver_file = File.read(File.join(File.dirname(__FILE__), '../.semver'), force: true)
17
+ end
18
+ end
19
+
20
+ after(:all) do
21
+ if @current_semver_file
22
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), @current_semver_file, force: true)
23
+ end
24
+ end
25
+ before do
26
+ FileUtils.rm(File.join(File.dirname(__FILE__), '../.semver'), force: true)
27
+ end
28
+ after do
29
+ FileUtils.rm(File.join(File.dirname(__FILE__), '../.semver'), force: true)
30
+ end
31
+ describe '#current_version' do
32
+ context 'when there is no .semver file' do
33
+ it 'returns the current version' do
34
+ expect(described_class.current_version.to_s).to eq 'v0.0.0'
35
+ end
36
+ end
37
+
38
+ context 'when there is a .semver file' do
39
+ before do
40
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(version))
41
+ end
42
+
43
+ it 'returns the current version' do
44
+ expect(described_class.current_version.to_s).to eq 'v1.2.3'
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'inc_major' do
50
+ before do
51
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(version))
52
+ end
53
+ it 'increases major and resets minor and patch' do
54
+ described_class.inc_major
55
+ expect(described_class.current_version.to_s).to eq 'v2.0.0'
56
+ end
57
+ end
58
+
59
+ describe 'inc_minor' do
60
+ before do
61
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(version))
62
+ end
63
+ it 'increases minor and resets patch' do
64
+ described_class.inc_minor
65
+ expect(described_class.current_version.to_s).to eq 'v1.3.0'
66
+ end
67
+ end
68
+
69
+ describe 'inc_patch' do
70
+ before do
71
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(version))
72
+ end
73
+ it 'increases minor and resets patch' do
74
+ described_class.inc_patch
75
+ expect(described_class.current_version.to_s).to eq 'v1.2.4'
76
+ end
77
+ end
78
+
79
+ describe 'prerelease' do
80
+ before do
81
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(version))
82
+ end
83
+ it 'sets the prerelease to the supplied string' do
84
+ described_class.prerelease 'something'
85
+ expect(described_class.current_version.to_s).to eq 'v1.2.3-something'
86
+ end
87
+ end
88
+
89
+ describe 'inc_prerelease' do
90
+ before do
91
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(version))
92
+ end
93
+ it 'increments major version and sets the prerelease to the supplied string' do
94
+ described_class.inc_prerelease 'something'
95
+ expect(described_class.current_version.to_s).to eq 'v2.0.0-something'
96
+ end
97
+ end
98
+
99
+ describe 'release' do
100
+ before do
101
+ v = version
102
+ v[:special] = "a string"
103
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(v))
104
+ end
105
+ it 'removes the prerelease' do
106
+ described_class.release
107
+ expect(described_class.current_version.to_s).to eq 'v1.2.3'
108
+ end
109
+ end
110
+
111
+ describe 'tag' do
112
+ before do
113
+ File.write(File.join(File.dirname(__FILE__), '../.semver'), YAML.dump(version))
114
+ end
115
+ it 'tags with the curren semver release and outputs push instructions' do
116
+ expect(Object).to receive(:`).with("git add .semver && git commit -m 'Increment version to v1.2.3' && git tag v1.2.3")
117
+ expect(Object).to receive(:`).with('git symbolic-ref HEAD').and_return 'refs/heads/master'
118
+ expect(Object).to receive(:puts).with("To push the new tag, use 'git push origin master --tags'")
119
+ described_class.tag
120
+ end
121
+ end
122
+ end
123
+
@@ -0,0 +1,11 @@
1
+ require 'simplecov'
2
+ require 'timecop'
3
+ require 'tempfile'
4
+
5
+ SimpleCov.start do
6
+ add_filter '/vendor/'
7
+ add_filter '/spec/'
8
+ coverage_dir 'log/coverage/spec'
9
+ end
10
+
11
+ require_relative '../lib/rake_n_bake'
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ describe RakeNBake::Version do
4
+ before do
5
+ allow(described_class).to receive(:`)
6
+ allow(described_class).to receive(:puts)
7
+ end
8
+
9
+ describe '.current_history' do
10
+ let(:tmp_file) { Tempfile.new(['history','.rdoc']) }
11
+
12
+ context 'when there is a history file' do
13
+ before do
14
+ allow(File).to receive(:read).and_return 'history'
15
+ allow(File).to receive(:exists?).and_return true
16
+ end
17
+
18
+ it 'returns the current history file' do
19
+ expect(described_class.current_history(tmp_file.path)).to eq 'history'
20
+ end
21
+ end
22
+
23
+ context 'when there is no history file' do
24
+ before do
25
+ allow(File).to receive(:exists?).and_return false
26
+ end
27
+
28
+ it 'creates a history file at version 0.0.0' do
29
+ expect(described_class.current_history(tmp_file.path)).to match(/\= 0.0.0 /)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '.latest_version' do
35
+ before do
36
+ allow(File).to receive(:read).and_return "== 1.2.3 (16 July 2014)\n * Change version tack so it can update gem version"
37
+ end
38
+
39
+ context 'there is no version'do
40
+ it 'returns a version of [0,0,0]' do
41
+ allow(File).to receive(:read).and_return ""
42
+ expect(described_class.latest_version).to eq [1,2,3]
43
+ end
44
+ end
45
+
46
+ context 'there is a version' do
47
+ it 'returns the latest version' do
48
+ expect(described_class.latest_version).to eq [1,2,3]
49
+ end
50
+ end
51
+
52
+ it 'defines the .to_s of the latest version'do
53
+ expect(described_class.latest_version.to_s).to eq "1.2.3"
54
+ end
55
+ end
56
+
57
+ describe '.gem?' do
58
+ context 'the project is a gem' do
59
+ before do
60
+ allow(Dir).to receive(:glob).and_return ['a gem spec']
61
+ end
62
+
63
+ it 'returns true' do
64
+ expect(described_class.gem?).to eq true
65
+ end
66
+ end
67
+
68
+ context 'the project is not a gem' do
69
+ before do
70
+ allow(Dir).to receive(:glob).and_return []
71
+ end
72
+
73
+ it 'returns false' do
74
+ expect(described_class.gem?).to eq false
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '.update_gem' do
80
+ let(:tmp_file) { Tempfile.new(['rake-n-bake','.gemspec']) }
81
+
82
+ before do
83
+ gemspec = <<-GEM
84
+ Gem::Specification.new do |spec|
85
+ spec.name = "rake-n-bake"
86
+ spec.version = '0.0.5'
87
+ spec.authors = ["Richard Vickerstaff", "Adam Whittingham"]
88
+ end
89
+ GEM
90
+ tmp_file.write gemspec
91
+ tmp_file.rewind
92
+ allow(Dir).to receive(:glob).and_return [tmp_file.path]
93
+ end
94
+
95
+ it 'updates the gem version' do
96
+ t = Time.local(2014, 7, 16)
97
+ Timecop.travel(t) do
98
+ described_class.update_gem 'foo'
99
+ expect(File.read(tmp_file)).to match(/.*version\s*= 'foo'/)
100
+ end
101
+ end
102
+
103
+ it 'outputs a message to the user' do
104
+ expect(described_class).to receive(:puts).with 'Added version to .gemfile'
105
+ described_class.update_gem 'foo'
106
+ end
107
+ end
108
+
109
+ describe '.update_to' do
110
+ before do
111
+ allow(described_class).to receive(:`).and_return "refs/heads/master"
112
+ end
113
+
114
+ it 'updates the version' do
115
+ expect(described_class).to receive(:add_history_header).with 'foo'
116
+ expect(described_class).to receive(:update_gem).with 'foo'
117
+ expect(described_class).to receive(:commit).with 'foo'
118
+ expect(described_class).to receive(:tag).with 'foo'
119
+ expect(described_class).to receive(:`).with 'git symbolic-ref HEAD'
120
+ expect(described_class).to receive(:puts).with "To push the new tag, use 'git push origin master --tags'"
121
+ described_class.update_to 'foo'
122
+ end
123
+ end
124
+
125
+ describe '.add_history_header' do
126
+ let(:tmp_file) { Tempfile.new('foo').path }
127
+
128
+ it 'adds the new headre to the history.rdoc' do
129
+ t = Time.local(2014, 7, 16)
130
+ Timecop.travel(t) do
131
+ described_class.add_history_header 'foo', tmp_file
132
+ expect(File.read tmp_file).to eq "== foo (16 July 2014)\n\n"
133
+ end
134
+ end
135
+
136
+ it 'outputs a message to the user' do
137
+ expect(described_class).to receive(:puts).with 'Added version to history.rdoc'
138
+ described_class.add_history_header 'foo', tmp_file
139
+ end
140
+ end
141
+
142
+ describe '.commit' do
143
+ it 'commits all changes' do
144
+ expect(described_class).to receive(:`).with "git add . && git commit -m 'increment version to foo'"
145
+ described_class.commit 'foo'
146
+ end
147
+
148
+ it 'outputs a message to the user' do
149
+ expect(described_class).to receive(:puts).with 'Committed change'
150
+ described_class.commit 'foo'
151
+ end
152
+ end
153
+
154
+ describe '.tag' do
155
+ it 'it tags the commit with the new version' do
156
+ expect(described_class).to receive(:`).with 'git tag foo'
157
+ described_class.tag 'foo'
158
+ end
159
+
160
+ it 'outputs a message to the user' do
161
+ expect(described_class).to receive(:puts).with 'Tagged with foo'
162
+ described_class.tag 'foo'
163
+ end
164
+ end
165
+ end