toki 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -11
- data/bin/git-release +174 -0
- data/changelog +13 -0
- data/lib/toki.rb +48 -0
- data/lib/toki/version.rb +1 -1
- data/project +1 -0
- data/test/test_toki.rb +63 -0
- data/toki.gemspec +2 -2
- data/version +1 -0
- metadata +10 -6
data/README.md
CHANGED
@@ -35,10 +35,10 @@ class Example
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# any mri version of ruby that is 1.9 or later
|
38
|
-
when_ruby :version => /^((?!1\.[0-8]).*?)
|
38
|
+
when_ruby :engine => 'ruby', :version => /^((?!1\.[0-8]).*?)$/ do
|
39
39
|
# also class methods can be defined
|
40
40
|
def self.ping
|
41
|
-
"
|
41
|
+
"gnop"
|
42
42
|
end
|
43
43
|
# applied only if ruby 1.9.x or later; overwrites array_to_string method
|
44
44
|
# ruby 2.0.0 # => "123"
|
@@ -48,13 +48,16 @@ class Example
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# applied only if version and patchlevel matches
|
51
|
-
when_ruby :version
|
51
|
+
when_ruby :version => '1.8.7', :patchlevel => '371' do; end
|
52
52
|
|
53
53
|
# applied only if engine and version matches
|
54
|
-
when_ruby :engine
|
55
|
-
when_ruby :engine
|
56
|
-
when_ruby :engine
|
57
|
-
when_ruby :engine
|
54
|
+
when_ruby :engine => 'ruby', :version => '1.8.7' do; end
|
55
|
+
when_ruby :engine => 'jruby', :jruby_version => '1.7.6' do; end
|
56
|
+
when_ruby :engine => 'macruby', :macruby_version => '0.12' do; end
|
57
|
+
when_ruby :engine => 'rbx', :rbx_version => '2.1.1' do; end
|
58
|
+
when_ruby :engine => 'maglev', :maglev_version => '1.1RC1' do; end
|
59
|
+
when_ruby :engine => 'ironruby', :ironruby_version => '1.1.3' do; end
|
60
|
+
when_ruby :engine => 'kiji', :kiji_version => '0.11' do; end
|
58
61
|
|
59
62
|
# applied only if platform matches; :windows, :osx, :linux, :unix, :unknown
|
60
63
|
when_ruby :platform => :linux do; end
|
@@ -65,18 +68,21 @@ class Example
|
|
65
68
|
when_jruby_version '1.7.6' do; end
|
66
69
|
when_macruby_version '0.12' do; end
|
67
70
|
when_rbx_version '2.1.1' do; end
|
71
|
+
when_maglev_version '1.1RC1' do; end
|
72
|
+
when_ironruby_version '1.1.3' do; end
|
73
|
+
when_kiji_version '0.11' do; end
|
68
74
|
when_ruby_patchlevel '371' do; end
|
69
75
|
when_ruby_engine 'rbx' do; end
|
70
76
|
when_platform :osx do; end
|
71
77
|
|
72
78
|
end
|
73
79
|
|
74
|
-
# 1.8.7
|
75
|
-
puts Example.ping # =>
|
80
|
+
# MRI 1.8.7
|
81
|
+
puts Example.ping # => "pong"
|
76
82
|
puts Example.new.array_to_string # => "123"
|
77
83
|
|
78
|
-
# 2.0.0
|
79
|
-
puts Example.ping # =>
|
84
|
+
# MRI 2.0.0
|
85
|
+
puts Example.ping # => "gnop"
|
80
86
|
puts Example.new.array_to_string # => "123"
|
81
87
|
```
|
82
88
|
|
@@ -87,3 +93,28 @@ puts Example.new.array_to_string # => "123"
|
|
87
93
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
88
94
|
4. Push to the branch (`git push origin my-new-feature`)
|
89
95
|
5. Create new Pull Request
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
Copyright (c) 2013 Jussi Koljonen
|
100
|
+
|
101
|
+
MIT License
|
102
|
+
|
103
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
104
|
+
a copy of this software and associated documentation files (the
|
105
|
+
"Software"), to deal in the Software without restriction, including
|
106
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
107
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
108
|
+
permit persons to whom the Software is furnished to do so, subject to
|
109
|
+
the following conditions:
|
110
|
+
|
111
|
+
The above copyright notice and this permission notice shall be
|
112
|
+
included in all copies or substantial portions of the Software.
|
113
|
+
|
114
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
115
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
116
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
117
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
118
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
119
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
120
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/git-release
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# -*- warn-indent: true -*-
|
4
|
+
require 'time'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
bump_version = true
|
8
|
+
old_version = nil
|
9
|
+
new_version = nil
|
10
|
+
|
11
|
+
def git_config_value(tag)
|
12
|
+
`/usr/bin/env git config --get-all #{tag}`.chop
|
13
|
+
end
|
14
|
+
|
15
|
+
def git_rev_parse(command)
|
16
|
+
`git rev-parse #{command}`.chop
|
17
|
+
end
|
18
|
+
|
19
|
+
def exec(command)
|
20
|
+
system("/usr/bin/env #{command}")
|
21
|
+
end
|
22
|
+
|
23
|
+
def git_directory
|
24
|
+
git_rev_parse('--git-dir')
|
25
|
+
end
|
26
|
+
|
27
|
+
def git_toplevel_directory
|
28
|
+
git_rev_parse('--show-toplevel')
|
29
|
+
end
|
30
|
+
|
31
|
+
def commit_message
|
32
|
+
File.read(File.join(git_directory, 'COMMIT_EDITMSG')).split("\n").select do | line |
|
33
|
+
line !~ /^#/
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_changelog(message)
|
38
|
+
changelog_file = File.join(git_toplevel_directory, 'changelog')
|
39
|
+
if File.exists?(changelog_file)
|
40
|
+
changelog = message + "\n" + File.read(changelog_file)
|
41
|
+
add_file = false
|
42
|
+
else
|
43
|
+
changelog = message
|
44
|
+
add_file = true
|
45
|
+
end
|
46
|
+
# write changelog file
|
47
|
+
File.open(changelog_file, 'w') do | file |
|
48
|
+
file << changelog
|
49
|
+
end
|
50
|
+
# add file to git repository
|
51
|
+
if add_file
|
52
|
+
`git add #{changelog_file}`
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def version_number
|
57
|
+
File.read(File.join(git_toplevel_directory, 'version')).gsub(/[\n\r]/, '')
|
58
|
+
end
|
59
|
+
|
60
|
+
def bump_version(version, release_type)
|
61
|
+
# parse current version number
|
62
|
+
version = version.split('.').map(&:to_i)
|
63
|
+
# major.minor.patch(.build)
|
64
|
+
while version.size < 3
|
65
|
+
version << 0
|
66
|
+
end
|
67
|
+
case release_type
|
68
|
+
when :major
|
69
|
+
# major.0.0
|
70
|
+
version[0] = version[0].succ
|
71
|
+
version[1] = 0
|
72
|
+
version[2] = 0
|
73
|
+
when :minor
|
74
|
+
# major.minor.0
|
75
|
+
version[1] = version[1].succ
|
76
|
+
version[2] = 0
|
77
|
+
when :patch
|
78
|
+
# major.minor.patch
|
79
|
+
version[2] = version[2].succ
|
80
|
+
else
|
81
|
+
abort "Unsupported release type #{release_type.inspect}"
|
82
|
+
end
|
83
|
+
# version as string
|
84
|
+
version = version.join('.')
|
85
|
+
# update version file
|
86
|
+
File.open('version', 'w') do | file |
|
87
|
+
file << version
|
88
|
+
end
|
89
|
+
# return new version number
|
90
|
+
version
|
91
|
+
end
|
92
|
+
|
93
|
+
def read_project_name
|
94
|
+
File.read(File.join(git_toplevel_directory, 'project'))
|
95
|
+
end
|
96
|
+
|
97
|
+
# main
|
98
|
+
arguments = ARGV
|
99
|
+
|
100
|
+
# collect filenames
|
101
|
+
files = ARGV.select{| argument | argument !~ /^-/ }.join(' ')
|
102
|
+
release_type = []
|
103
|
+
@version_bump = nil
|
104
|
+
|
105
|
+
OptionParser.new do | opts |
|
106
|
+
opts.banner = "Project versioning, changelog creation and release automation tool"
|
107
|
+
opts.define_head "Usage: #{ File.basename($0) } <files> [options]"
|
108
|
+
opts.on('--major', "Performs a major release; bumps up major version number") do
|
109
|
+
release_type << :major
|
110
|
+
end
|
111
|
+
opts.on('--minor', "Performs a minor release; bumps up minor version number") do
|
112
|
+
release_type << :minor
|
113
|
+
end
|
114
|
+
opts.on('--patch', "Performs a patch release; bumps up patch number (default)") do
|
115
|
+
release_type << :patch
|
116
|
+
end
|
117
|
+
opts.on('-h', '--help', "Prints the synopsis and a list of the most commonly used commands") { puts opts; exit }
|
118
|
+
opts.parse!
|
119
|
+
if files.size == 0 && release_type.empty?
|
120
|
+
puts opts
|
121
|
+
exit
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# only bump version if no files given but release_type is set
|
126
|
+
if (files.empty? && !release_type.empty?)
|
127
|
+
project_name = read_project_name
|
128
|
+
old_version = version_number
|
129
|
+
new_version = bump_version(old_version, release_type.first)
|
130
|
+
files = [File.join(git_toplevel_directory, 'version')]
|
131
|
+
bump_version = false
|
132
|
+
end
|
133
|
+
|
134
|
+
# git commit; write a commit message
|
135
|
+
if exec("git commit #{files}")
|
136
|
+
|
137
|
+
case release_type.size
|
138
|
+
when 0
|
139
|
+
release_type = :patch
|
140
|
+
when 1
|
141
|
+
release_type = release_type.first
|
142
|
+
else
|
143
|
+
abort "Error: Multiple release types added #{release_type.map(&:inspect).join(', ')}"
|
144
|
+
end
|
145
|
+
|
146
|
+
project_name = read_project_name
|
147
|
+
|
148
|
+
if bump_version
|
149
|
+
old_version = version_number
|
150
|
+
new_version = bump_version(old_version, release_type)
|
151
|
+
end
|
152
|
+
|
153
|
+
puts "Updating #{project_name} version from #{old_version} to #{new_version}"
|
154
|
+
|
155
|
+
# create a release note
|
156
|
+
release_note = "#{Time.now.to_s} #{git_config_value('user.name')} <#{git_config_value('user.email')}>\n\n"
|
157
|
+
release_note << " * #{project_name} version #{new_version} changes:\n\n"
|
158
|
+
release_note << commit_message.collect{| line | " * #{line}" }.join("\n")
|
159
|
+
release_note << "\n"
|
160
|
+
|
161
|
+
# add release note to changelog
|
162
|
+
update_changelog(release_note)
|
163
|
+
|
164
|
+
updated_files = [
|
165
|
+
File.join(git_toplevel_directory, 'version'),
|
166
|
+
File.join(git_toplevel_directory, 'changelog')
|
167
|
+
]
|
168
|
+
|
169
|
+
# add changelog entry to commit; use same commit message
|
170
|
+
unless exec("git commit #{files} #{updated_files.join(' ')} --amend -C #{git_rev_parse('HEAD')}")
|
171
|
+
abort "Failed to perform commit"
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
data/changelog
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Sun Oct 27 12:42:47 +0200 2013 Jussi Koljonen <jussi.koljonen@gmail.com>
|
2
|
+
|
3
|
+
* Toki version 0.0.2 changes:
|
4
|
+
|
5
|
+
* Added support to MagLev, IronRuby and Kiji
|
6
|
+
* Added license to README.md
|
7
|
+
|
8
|
+
Sat Oct 26 02:02:56 2013 +0300 Jussi Koljonen <jussi.koljonen@gmail.com>
|
9
|
+
|
10
|
+
* Toki version 0.0.1 changes:
|
11
|
+
|
12
|
+
* Initial release
|
13
|
+
* Supports MRI, JRuby, MacRuby, RBX
|
data/lib/toki.rb
CHANGED
@@ -15,6 +15,12 @@ module Toki
|
|
15
15
|
when_macruby_version(value)
|
16
16
|
when :rbx_version
|
17
17
|
when_rbx_version(value)
|
18
|
+
when :maglev_version
|
19
|
+
when_maglev_version(value)
|
20
|
+
when :ironruby_version
|
21
|
+
when_ironruby_version(value)
|
22
|
+
when :kiji_version
|
23
|
+
when_kiji_version(value)
|
18
24
|
when :engine
|
19
25
|
when_ruby_engine(value)
|
20
26
|
when :patchlevel
|
@@ -69,6 +75,48 @@ module Toki
|
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
78
|
+
# MAGLEV_VERSION
|
79
|
+
def when_maglev_version(pattern, &block)
|
80
|
+
if defined?(MAGLEV_VERSION)
|
81
|
+
if pattern_matches_with?(MAGLEV_VERSION, pattern)
|
82
|
+
apply_behaviour(&block)
|
83
|
+
else
|
84
|
+
false
|
85
|
+
end
|
86
|
+
else
|
87
|
+
# MAGLEV_VERSION not defined
|
88
|
+
false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# IRONRUBY_VERSION
|
93
|
+
def when_ironruby_version(pattern, &block)
|
94
|
+
if defined?(IRONRUBY_VERSION)
|
95
|
+
if pattern_matches_with?(IRONRUBY_VERSION, pattern)
|
96
|
+
apply_behaviour(&block)
|
97
|
+
else
|
98
|
+
false
|
99
|
+
end
|
100
|
+
else
|
101
|
+
# IRONRUBY_VERSION not defined
|
102
|
+
false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# KIJI_VERSION
|
107
|
+
def when_kiji_version(pattern, &block)
|
108
|
+
if defined?(KIJI_VERSION)
|
109
|
+
if pattern_matches_with?(KIJI_VERSION, pattern)
|
110
|
+
apply_behaviour(&block)
|
111
|
+
else
|
112
|
+
false
|
113
|
+
end
|
114
|
+
else
|
115
|
+
# KIJI_VERSION not defined
|
116
|
+
false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
72
120
|
# RUBY_VERSION
|
73
121
|
def when_ruby_version(pattern, &block)
|
74
122
|
if pattern_matches_with?(RUBY_VERSION, pattern)
|
data/lib/toki/version.rb
CHANGED
data/project
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Toki
|
data/test/test_toki.rb
CHANGED
@@ -92,6 +92,69 @@ class TestToki < Test::Unit::TestCase
|
|
92
92
|
Object.send(:remove_const, :MACRUBY_VERSION) unless macruby_version_defined
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_maglev_version
|
96
|
+
unless (maglev_version_defined = defined?(MAGLEV_VERSION))
|
97
|
+
Object.const_set(:MAGLEV_VERSION, '1.1RC1')
|
98
|
+
end
|
99
|
+
klass = Class.new do
|
100
|
+
extend Toki
|
101
|
+
def hello
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
when_ruby :maglev_version => '1.1RC1' do
|
105
|
+
def hello
|
106
|
+
"world"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
instance = klass.new
|
111
|
+
assert_equal "world", instance.hello
|
112
|
+
ensure
|
113
|
+
Object.send(:remove_const, :MAGLEV_VERSION) unless maglev_version_defined
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_ironruby_version
|
117
|
+
unless (ironruby_version_defined = defined?(IRONRUBY_VERSION))
|
118
|
+
Object.const_set(:IRONRUBY_VERSION, '1.1.3')
|
119
|
+
end
|
120
|
+
klass = Class.new do
|
121
|
+
extend Toki
|
122
|
+
def hello
|
123
|
+
nil
|
124
|
+
end
|
125
|
+
when_ruby :ironruby_version => '1.1.3' do
|
126
|
+
def hello
|
127
|
+
"world"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
instance = klass.new
|
132
|
+
assert_equal "world", instance.hello
|
133
|
+
ensure
|
134
|
+
Object.send(:remove_const, :IRONRUBY_VERSION) unless ironruby_version_defined
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_kiji_version
|
138
|
+
unless (kiji_version_defined = defined?(KIJI_VERSION))
|
139
|
+
Object.const_set(:KIJI_VERSION, '0.11')
|
140
|
+
end
|
141
|
+
klass = Class.new do
|
142
|
+
extend Toki
|
143
|
+
def hello
|
144
|
+
nil
|
145
|
+
end
|
146
|
+
when_ruby :kiji_version => '0.11' do
|
147
|
+
def hello
|
148
|
+
"world"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
instance = klass.new
|
153
|
+
assert_equal "world", instance.hello
|
154
|
+
ensure
|
155
|
+
Object.send(:remove_const, :KIJI_VERSION) unless kiji_version_defined
|
156
|
+
end
|
157
|
+
|
95
158
|
def test_ruby_patchlevel
|
96
159
|
klass = Class.new do
|
97
160
|
extend Toki
|
data/toki.gemspec
CHANGED
@@ -7,11 +7,11 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = %q{Toki is a DSL that helps you to implement Ruby version, patchlevel, engine and platform specific code}
|
8
8
|
gem.summary = %q{Toki is a DSL that helps you to implement Ruby version, patchlevel, engine and platform specific code}
|
9
9
|
gem.homepage = "https://github.com/juskoljo/toki"
|
10
|
-
|
11
10
|
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
11
|
+
gem.executables = [] # gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
13
|
gem.name = "toki"
|
15
14
|
gem.require_paths = ["lib"]
|
16
15
|
gem.version = Toki::VERSION
|
16
|
+
gem.license = 'MIT'
|
17
17
|
end
|
data/version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jussi Koljonen
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-10-
|
18
|
+
date: 2013-10-27 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Toki is a DSL that helps you to implement Ruby version, patchlevel, engine and platform specific code
|
@@ -33,13 +33,17 @@ files:
|
|
33
33
|
- LICENSE
|
34
34
|
- README.md
|
35
35
|
- Rakefile
|
36
|
+
- bin/git-release
|
37
|
+
- changelog
|
36
38
|
- lib/toki.rb
|
37
39
|
- lib/toki/version.rb
|
40
|
+
- project
|
38
41
|
- test/test_toki.rb
|
39
42
|
- toki.gemspec
|
43
|
+
- version
|
40
44
|
homepage: https://github.com/juskoljo/toki
|
41
|
-
licenses:
|
42
|
-
|
45
|
+
licenses:
|
46
|
+
- MIT
|
43
47
|
post_install_message:
|
44
48
|
rdoc_options: []
|
45
49
|
|