falkorlib 0.6.19 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +88 -0
- data/.travis.yml +56 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +55 -27
- data/Rakefile +12 -8
- data/Vagrantfile +68 -0
- data/completion/_falkor +55 -7
- data/falkorlib.gemspec +14 -12
- data/lib/falkorlib.rb +22 -21
- data/lib/falkorlib/bootstrap.rb +5 -1
- data/lib/falkorlib/bootstrap/base.rb +385 -693
- data/lib/falkorlib/bootstrap/git.rb +137 -0
- data/lib/falkorlib/bootstrap/latex.rb +186 -0
- data/lib/falkorlib/bootstrap/link.rb +108 -96
- data/lib/falkorlib/bootstrap/ruby.rb +102 -0
- data/lib/falkorlib/cli.rb +82 -26
- data/lib/falkorlib/cli/config.rb +8 -8
- data/lib/falkorlib/cli/link.rb +8 -9
- data/lib/falkorlib/cli/new.rb +25 -39
- data/lib/falkorlib/common.rb +425 -425
- data/lib/falkorlib/config.rb +114 -110
- data/lib/falkorlib/error.rb +27 -16
- data/lib/falkorlib/gem_tasks.rb +12 -11
- data/lib/falkorlib/git.rb +3 -4
- data/lib/falkorlib/git/base.rb +439 -396
- data/lib/falkorlib/git/flow.rb +163 -165
- data/lib/falkorlib/git_tasks.rb +31 -31
- data/lib/falkorlib/loader.rb +1 -1
- data/lib/falkorlib/puppet.rb +3 -5
- data/lib/falkorlib/puppet/base.rb +10 -15
- data/lib/falkorlib/puppet/modules.rb +367 -365
- data/lib/falkorlib/puppet_tasks.rb +11 -8
- data/lib/falkorlib/tasks.rb +51 -54
- data/lib/falkorlib/tasks/gem.rake +42 -43
- data/lib/falkorlib/tasks/gem.rb +12 -11
- data/lib/falkorlib/tasks/git.rake +101 -107
- data/lib/falkorlib/tasks/git.rb +31 -31
- data/lib/falkorlib/tasks/gitflow.rake +131 -141
- data/lib/falkorlib/tasks/puppet.rb +11 -8
- data/lib/falkorlib/tasks/puppet_modules.rake +143 -154
- data/lib/falkorlib/tasks/rspec.rake +94 -59
- data/lib/falkorlib/tasks/yard.rake +35 -39
- data/lib/falkorlib/version.rb +55 -55
- data/lib/falkorlib/versioning.rb +169 -167
- data/spec/falkorlib/bootstrap_helpers_spec.rb +106 -56
- data/spec/falkorlib/bootstrap_latex_spec.rb +145 -0
- data/spec/falkorlib/bootstrap_link_spec.rb +137 -0
- data/spec/falkorlib/bootstrap_ruby_spec.rb +118 -0
- data/spec/falkorlib/bootstrap_spec.rb +112 -129
- data/spec/falkorlib/git_spec.rb +94 -22
- data/spec/falkorlib/gitflow_spec.rb +54 -42
- data/spec/falkorlib/puppet_modules_spec.rb +35 -26
- data/spec/falkorlib/versioning_puppet_module_spec.rb +94 -90
- data/spec/falkorlib_spec.rb +5 -0
- data/spec/spec_helper.rb +88 -47
- data/templates/latex/article-ieee/main.tex.erb +509 -0
- data/templates/latex/article/_abstract.tex.erb +19 -0
- data/templates/latex/article/_acronyms.tex.erb +116 -0
- data/templates/latex/article/_conclusion.tex.erb +25 -0
- data/templates/latex/article/_context.tex.erb +17 -0
- data/templates/latex/article/_experiments.tex.erb +27 -0
- data/templates/latex/article/_implem.tex.erb +17 -0
- data/templates/latex/article/_introduction.tex.erb +39 -0
- data/templates/latex/article/_related_works.tex.erb +19 -0
- data/templates/latex/article/biblio.bib.erb +28 -0
- data/templates/latex/article/template.tex.erb +16 -0
- data/templates/latex/ieee/IEEEtran.bst +2409 -0
- data/templates/latex/ieee/IEEEtran.cls +6347 -0
- data/templates/motd/motd.erb +2 -1
- metadata +82 -2
@@ -26,71 +26,106 @@
|
|
26
26
|
# http://relishapp.com/rspec
|
27
27
|
#
|
28
28
|
require 'rspec/core'
|
29
|
+
require 'rubocop/rake_task'
|
30
|
+
|
31
|
+
RuboCop::RakeTask.new
|
32
|
+
|
33
|
+
# RSpec.configure do |c|
|
34
|
+
# c.fail_fast = true
|
35
|
+
# c.color = true
|
36
|
+
# end
|
37
|
+
|
29
38
|
begin
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
39
|
+
require "rspec/core/rake_task"
|
40
|
+
#specfiles = Dir.glob['spec/**/*_spec.rb']
|
41
|
+
specsuite = {}
|
42
|
+
Dir.glob('spec/**/*_spec.rb').each do |f|
|
43
|
+
File.basename(f) =~ /^([^_]+)_*/
|
44
|
+
specsuite[Regexp.last_match(1)] = [] unless specsuite[Regexp.last_match(1)]
|
45
|
+
specsuite[Regexp.last_match(1)] << f
|
46
|
+
end
|
47
|
+
rspec_opts = [ "--color", "--format d", "--backtrace" ]
|
48
|
+
unless specsuite.empty?
|
49
|
+
#.....................
|
50
|
+
namespace :rspec do
|
51
|
+
#.....................
|
52
|
+
namespace :suite do
|
53
|
+
specsuite.each do |name, _files|
|
54
|
+
########### #{name} ###########
|
55
|
+
desc "Run all specs in #{name} spec suite"
|
56
|
+
RSpec::Core::RakeTask.new(name.to_sym) do |t|
|
57
|
+
t.pattern = "spec/**/#{name}_*spec.rb"
|
58
|
+
t.verbose = false
|
59
|
+
t.rspec_opts = rspec_opts
|
60
|
+
end # task #{name}
|
61
|
+
end
|
62
|
+
end # namespace suite
|
63
|
+
end # namespace rspec
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
desc "Run RSpec code examples '*_spec.rb' from the spec/ directory"
|
68
|
+
RSpec::Core::RakeTask.new(:rspec) do |t|
|
69
|
+
# Glob pattern to match files.
|
70
|
+
#t.pattern = "spec/**/common_*.rb"
|
71
|
+
#t.pattern = "spec/**/versioning_*spec.rb"
|
72
|
+
#t.pattern = "spec/**/puppet*spec.rb"
|
73
|
+
#t.pattern = "spec/**/bootstrap_spec.rb"
|
74
|
+
#t.pattern = "spec/**/git*spec.rb"
|
75
|
+
#t.pattern = "spec/**/error*spec.rb"
|
76
|
+
#t.pattern = "spec/**/config*spec.rb"
|
77
|
+
|
78
|
+
# Whether or not to fail Rake when an error occurs (typically when
|
79
|
+
# examples fail).
|
80
|
+
t.fail_on_error = true
|
81
|
+
|
82
|
+
# A message to print to stderr when there are failures.
|
83
|
+
t.failure_message = nil
|
84
|
+
|
85
|
+
# Use verbose output. If this is set to true, the task will print the
|
86
|
+
# executed spec command to stdout.
|
87
|
+
t.verbose = true
|
88
|
+
|
89
|
+
# Use rcov for code coverage?
|
90
|
+
#t.rcov = false
|
91
|
+
|
92
|
+
# Path to rcov.
|
93
|
+
#t.rcov_path = "rcov"
|
94
|
+
|
95
|
+
# Command line options to pass to rcov. See 'rcov --help' about this
|
96
|
+
#t.rcov_opts = []
|
97
|
+
|
98
|
+
# Command line options to pass to ruby. See 'ruby --help' about this
|
99
|
+
t.ruby_opts = []
|
100
|
+
|
101
|
+
# Path to rspec
|
102
|
+
#t.rspec_path = "rspec"
|
103
|
+
|
104
|
+
# Command line options to pass to rspec. See 'rspec --help' about this
|
105
|
+
#t.rspec_opts = ["--color", "--backtrace"]
|
106
|
+
t.rspec_opts = rspec_opts #["--color", "--format d", "--backtrace"] # "--format d",
|
107
|
+
end
|
108
|
+
rescue LoadError
|
109
|
+
task :spec_test do
|
110
|
+
abort 'rspec is not available. In order to run spec, you must: gem install rspec'
|
111
|
+
end
|
76
112
|
ensure
|
77
|
-
|
78
|
-
|
113
|
+
task :spec => [:spec_test]
|
114
|
+
task :test => [:spec_test]
|
79
115
|
end
|
80
116
|
|
81
117
|
#.....................
|
82
118
|
namespace :setenv do
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
119
|
+
########### code_climate ###########
|
120
|
+
#desc "Set Code Climate token to report rspec results"
|
121
|
+
task :code_climate do |_t|
|
122
|
+
unless FalkorLib.config[:tokens].nil? ||
|
123
|
+
FalkorLib.config[:tokens][:code_climate].nil? ||
|
124
|
+
FalkorLib.config[:tokens][:code_climate].empty?
|
125
|
+
ans = ask(cyan("A Code Climate token is set - Do you want to report on Code Climate the result of the process? (y|N)"), 'No')
|
126
|
+
ENV['CODECLIMATE_REPO_TOKEN'] = FalkorLib.config[:tokens][:code_climate] if ans =~ /y.*/i
|
127
|
+
end
|
128
|
+
end # task code_climate
|
94
129
|
end # namespace set
|
95
130
|
|
96
131
|
task :rspec => 'setenv:code_climate'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
3
|
+
# Time-stamp: <Fri 2016-11-11 15:25 svarrette>
|
4
4
|
################################################################################
|
5
5
|
# Installs a rake task to generate API documentation using yard.
|
6
6
|
#
|
@@ -31,48 +31,44 @@ require "falkorlib"
|
|
31
31
|
|
32
32
|
#.....................
|
33
33
|
namespace :yard do
|
34
|
-
|
35
|
-
|
34
|
+
begin
|
35
|
+
require "yard"
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
########### yard:doc ###########
|
38
|
+
desc "Generate yard documentation"
|
39
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
40
|
+
# Array of options passed to yardoc commandline. See 'yardoc --help' about this
|
41
|
+
t.options = ["--output-dir", "doc/api", "-", "README.md", "CHANGELOG.md", "LICENCE.md"]
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
# Array of ruby source files (and any extra documentation files
|
44
|
+
# separated by '-')
|
45
|
+
t.files = ["lib/**/*.rb"]
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
# A proc to call before running the task
|
48
|
+
# t.before = proc{ }
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
# A proc to call after running the task
|
51
|
+
t.after = proc {
|
52
|
+
puts "\nFull documentation is now generated -- you probably want now to\n\t open doc/api/index.html"
|
53
|
+
}
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
rescue LoadError
|
63
|
-
task :yard do
|
64
|
-
abort 'yard is not available. In order to run yard, you must: gem install yard'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
########### yard:stats ###########
|
69
|
-
desc "Collect statistics as regards yard documentation"
|
70
|
-
task :stats do |t|
|
71
|
-
Dir.chdir(FalkorLib.config.root) do
|
72
|
-
FalkorLib::Common.run %{yard stats --list-undoc}
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
55
|
+
# An optional lambda to run against all objects being generated.
|
56
|
+
# Any object that the lambda returns false for will be excluded
|
57
|
+
# from documentation.
|
58
|
+
# t.verifier = lambda{|obj| true}
|
59
|
+
end
|
77
60
|
|
61
|
+
rescue LoadError
|
62
|
+
task :yard do
|
63
|
+
abort 'yard is not available. In order to run yard, you must: gem install yard'
|
64
|
+
end
|
65
|
+
end
|
78
66
|
|
67
|
+
########### yard:stats ###########
|
68
|
+
desc "Collect statistics as regards yard documentation"
|
69
|
+
task :stats do |_t|
|
70
|
+
Dir.chdir(FalkorLib.config.root) do
|
71
|
+
FalkorLib::Common.run %(yard stats --list-undoc)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/falkorlib/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
3
|
+
# Time-stamp: <Sat 2016-11-12 02:37 svarrette>
|
4
4
|
################################################################################
|
5
5
|
# @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
6
6
|
#
|
@@ -9,68 +9,68 @@
|
|
9
9
|
|
10
10
|
module FalkorLib #:nodoc:
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# Management of the current version of the library
|
13
|
+
# @see falkorlib/tasks/versioning.rake
|
14
|
+
module Version
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# Change the MAJOR, MINOR and PATCH constants below
|
17
|
+
# to adjust the version of the FalkorLib gem
|
18
|
+
#
|
19
|
+
# MAJOR: Defines the major version
|
20
|
+
# MINOR: Defines the minor version
|
21
|
+
# PATCH: Defines the patch version
|
22
|
+
MAJOR, MINOR, PATCH = 0, 7, 0
|
23
23
|
|
24
|
-
|
24
|
+
module_function
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
## Returns the minor version ( small release based off of multiple patches )
|
32
|
-
def minor
|
33
|
-
MINOR
|
34
|
-
end
|
26
|
+
## Returns the major version ( big release based off of multiple minor releases )
|
27
|
+
def major
|
28
|
+
MAJOR
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
## Returns the minor version ( small release based off of multiple patches )
|
32
|
+
def minor
|
33
|
+
MINOR
|
34
|
+
end
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
## Returns the patch version ( updates, features and (crucial) bug fixes )
|
37
|
+
def patch
|
38
|
+
PATCH
|
39
|
+
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# def bump_version(oldversion, level)
|
50
|
-
# major = minor = patch = 0
|
51
|
-
# if oldversion =~ /^(\d+)\.(\d+)\.(\d+)$/
|
52
|
-
# major = $1.to_i
|
53
|
-
# minor = $2.to_i
|
54
|
-
# patch = $3.to_i
|
55
|
-
# end
|
56
|
-
# case level
|
57
|
-
# when ':major'
|
58
|
-
# major += 1
|
59
|
-
# minor = 0
|
60
|
-
# patch = 0
|
61
|
-
# when ':minor'
|
62
|
-
# minor += 1
|
63
|
-
# patch = 0
|
64
|
-
# when ':patch'
|
65
|
-
# patch += 1
|
66
|
-
# end
|
67
|
-
# version = [major, minor, patch].compact.join('.')
|
68
|
-
# end
|
41
|
+
## @return the full version string
|
42
|
+
def to_s
|
43
|
+
[MAJOR, MINOR, PATCH].join('.')
|
69
44
|
end
|
70
45
|
|
71
|
-
#
|
72
|
-
|
73
|
-
|
46
|
+
# ## Return a new version number based on
|
47
|
+
# # @param oldversion the old version (format: x.y.z)
|
48
|
+
# # @param level the level of bumping (either :major, :minor, :patch)
|
49
|
+
# def bump_version(oldversion, level)
|
50
|
+
# major = minor = patch = 0
|
51
|
+
# if oldversion =~ /^(\d+)\.(\d+)\.(\d+)$/
|
52
|
+
# major = $1.to_i
|
53
|
+
# minor = $2.to_i
|
54
|
+
# patch = $3.to_i
|
55
|
+
# end
|
56
|
+
# case level
|
57
|
+
# when ':major'
|
58
|
+
# major += 1
|
59
|
+
# minor = 0
|
60
|
+
# patch = 0
|
61
|
+
# when ':minor'
|
62
|
+
# minor += 1
|
63
|
+
# patch = 0
|
64
|
+
# when ':patch'
|
65
|
+
# patch += 1
|
66
|
+
# end
|
67
|
+
# version = [major, minor, patch].compact.join('.')
|
68
|
+
# end
|
69
|
+
|
70
|
+
end
|
74
71
|
|
72
|
+
# Shorter version of the Gem's VERSION
|
73
|
+
VERSION = Version.to_s
|
75
74
|
|
75
|
+
end
|
76
76
|
|
data/lib/falkorlib/versioning.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
3
|
+
# Time-stamp: <Wed 2016-11-09 00:28 svarrette>
|
4
4
|
################################################################################
|
5
5
|
# @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
6
6
|
#
|
@@ -10,184 +10,186 @@ require 'json'
|
|
10
10
|
|
11
11
|
module FalkorLib #:nodoc:
|
12
12
|
|
13
|
-
|
13
|
+
module Config
|
14
|
+
# Default configuration for Versioning Management
|
15
|
+
module Versioning
|
16
|
+
|
17
|
+
# Versioning Management defaults
|
18
|
+
DEFAULTS = {
|
19
|
+
:default => '0.0.1',
|
20
|
+
:levels => %w(major minor patch),
|
21
|
+
:type => 'file',
|
22
|
+
:source => {
|
23
|
+
'file' => {
|
24
|
+
:filename => 'VERSION'
|
25
|
+
},
|
26
|
+
'gem' => {
|
27
|
+
:filename => 'lib/falkorlib/version.rb',
|
28
|
+
:getmethod => 'FalkorLib::Version.to_s',
|
29
|
+
#:setmethod => 'FalkorLib::Version.set',
|
30
|
+
#:pattern => '^(\s*)MAJOR\s*,\s*MINOR,\s*PATCH\s*=\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)'
|
31
|
+
},
|
32
|
+
'puppet_module' => {
|
33
|
+
:filename => 'metadata.json'
|
34
|
+
},
|
35
|
+
'tag' => {
|
36
|
+
:suffix => 'v'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
14
40
|
|
15
|
-
# Default configuration for Versioning Management
|
16
|
-
module Versioning
|
17
|
-
# Versioning Management defaults
|
18
|
-
DEFAULTS = {
|
19
|
-
:default => '0.0.1',
|
20
|
-
:levels => [ 'major', 'minor', 'patch' ],
|
21
|
-
:type => 'file',
|
22
|
-
:source => {
|
23
|
-
'file' => {
|
24
|
-
:filename => 'VERSION'
|
25
|
-
},
|
26
|
-
'gem' => {
|
27
|
-
:filename => 'lib/falkorlib/version.rb',
|
28
|
-
:getmethod => 'FalkorLib::Version.to_s',
|
29
|
-
#:setmethod => 'FalkorLib::Version.set',
|
30
|
-
#:pattern => '^(\s*)MAJOR\s*,\s*MINOR,\s*PATCH\s*=\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)'
|
31
|
-
},
|
32
|
-
'puppet_module' => {
|
33
|
-
:filename => 'metadata.json'
|
34
|
-
},
|
35
|
-
'tag' => {
|
36
|
-
:suffix => 'v'
|
37
|
-
},
|
38
|
-
}
|
39
|
-
}
|
40
|
-
end
|
41
41
|
end
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
module_function
|
44
|
+
# Semantic Versioning Management
|
45
|
+
# @see falkorlib/tasks/versioning.rake
|
46
|
+
module Versioning
|
47
47
|
|
48
|
-
|
49
|
-
def major(version)
|
50
|
-
res = 0
|
51
|
-
res = $1 if version =~ /^\s*(\d+)\.\d+\.\d+/
|
52
|
-
res
|
53
|
-
end
|
48
|
+
module_function
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
50
|
+
## extract the major part of the version
|
51
|
+
def major(version)
|
52
|
+
res = 0
|
53
|
+
res = Regexp.last_match(1) if version =~ /^\s*(\d+)\.\d+\.\d+/
|
54
|
+
res
|
55
|
+
end
|
61
56
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
57
|
+
## extract the minor part of the version
|
58
|
+
def minor(version)
|
59
|
+
res = 0
|
60
|
+
res = Regexp.last_match(1) if version =~ /^\s*\d+\.(\d+)\.\d+/
|
61
|
+
res
|
62
|
+
end
|
68
63
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def get_version(rootdir = Dir.pwd, options = {})
|
76
|
-
version = options[:default] ? options[:default] : FalkorLib.config[:versioning][:default]
|
77
|
-
type = options[:type] ? options[:type] : FalkorLib.config[:versioning][:type]
|
78
|
-
source = options[:source] ? options[:source] : FalkorLib.config[:versioning][:source][ type ]
|
79
|
-
case type
|
80
|
-
when 'file'
|
81
|
-
versionfile = File.join( rootdir, source[:filename] )
|
82
|
-
version = File.read( versionfile ).chomp if File.exist? ( versionfile )
|
83
|
-
when 'gem'
|
84
|
-
getmethod = source[:getmethod ]
|
85
|
-
version = eval( getmethod ) unless (getmethod.nil? || getmethod.empty?)
|
86
|
-
when 'puppet_module'
|
87
|
-
jsonfile = File.join( rootdir, source[:filename] )
|
88
|
-
metadata = JSON.parse( IO.read( jsonfile ) )
|
89
|
-
version = metadata["version"]
|
90
|
-
end
|
91
|
-
version
|
92
|
-
end
|
64
|
+
## extract the patch part of the version
|
65
|
+
def patch(version)
|
66
|
+
res = 0
|
67
|
+
res = Regexp.last_match(1) if version =~ /^\s*\d+\.\d+\.(\d+)/
|
68
|
+
res
|
69
|
+
end
|
93
70
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
metadata = JSON.parse( IO.read( versionfile ) )
|
122
|
-
metadata["version"] = version
|
123
|
-
File.open(versionfile,"w") do |f|
|
124
|
-
f.write JSON.pretty_generate( metadata )
|
125
|
-
end
|
126
|
-
#exit 1
|
127
|
-
end
|
128
|
-
if FalkorLib::Git.init?(rootdir)
|
129
|
-
filelist = FalkorLib::Git.list_files( rootdir )
|
130
|
-
Dir.chdir( rootdir ) do
|
131
|
-
next if source[:filename].nil?
|
132
|
-
unless filelist.include?( source[:filename] )
|
133
|
-
warning "The version file #{source[:filename]} is not part of the Git repository"
|
134
|
-
answer = ask("Adding the file to the repository? (Y|n)", 'Yes')
|
135
|
-
next if answer =~ /n.*/i
|
136
|
-
exit_status = FalkorLib::Git.add(versionfile, "Adding the version file '#{source[:filename]}', inialized to the '#{version}' version" )
|
137
|
-
next
|
138
|
-
end
|
139
|
-
run %{
|
140
|
-
git diff #{source[:filename]}
|
141
|
-
}
|
142
|
-
answer = ask(cyan("=> Commit the changes of the version file to the repository? (Y|n)"), 'Yes')
|
143
|
-
next if answer =~ /n.*/i
|
144
|
-
run %{
|
145
|
-
git commit -s -m "bump to version '#{version}'" #{source[:filename]}
|
146
|
-
}
|
147
|
-
exit_status = $?.to_i
|
148
|
-
# if (type == 'gem' && File.exists?(File.join(rootdir, 'Gemfile')) )
|
149
|
-
# run %{
|
150
|
-
# sleep 2
|
151
|
-
# bundle update falkorlib
|
152
|
-
# git commit -s -m "Update Gemfile.lock accordingly" Gemfile.lock
|
153
|
-
# } if command?( 'bundle' )
|
154
|
-
# end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
exit_status
|
158
|
-
end
|
71
|
+
######
|
72
|
+
# Get the current version
|
73
|
+
# Supported options:
|
74
|
+
# * :default [string] default version
|
75
|
+
# * :type in ['file','gem','puppet_module'] type of versionning mechanism
|
76
|
+
# * :source [Hash] information on the way to retrieve the information
|
77
|
+
def get_version(path = Dir.pwd, options = {})
|
78
|
+
rootdir = normalized_path(path)
|
79
|
+
version = (options[:default]) ? options[:default] : FalkorLib.config[:versioning][:default]
|
80
|
+
type = (options[:type]) ? options[:type] : FalkorLib.config[:versioning][:type]
|
81
|
+
source = (options[:source]) ? options[:source] : FalkorLib.config[:versioning][:source][ type ]
|
82
|
+
puts "type = '#{type}'"
|
83
|
+
case type
|
84
|
+
when 'file'
|
85
|
+
versionfile = File.join( rootdir, source[:filename] )
|
86
|
+
puts "versionfile = '#{versionfile}'"
|
87
|
+
version = File.read( versionfile ).chomp if File.exist?( versionfile )
|
88
|
+
when 'gem'
|
89
|
+
getmethod = source[:getmethod ]
|
90
|
+
version = eval( getmethod ) unless (getmethod.nil? || getmethod.empty?)
|
91
|
+
when 'puppet_module'
|
92
|
+
jsonfile = File.join( rootdir, source[:filename] )
|
93
|
+
metadata = JSON.parse( IO.read( jsonfile ) )
|
94
|
+
version = metadata["version"]
|
95
|
+
end
|
96
|
+
version
|
97
|
+
end
|
159
98
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
99
|
+
######
|
100
|
+
# Set the version
|
101
|
+
# Supported options:
|
102
|
+
# * :type in ['file','gem','puppet_module'] type of versionning mechanism
|
103
|
+
# * :source [Hash] information on the way to retrieve the information
|
104
|
+
def set_version(version, rootdir = Dir.pwd, options = {})
|
105
|
+
exit_status = 0
|
106
|
+
type = (options[:type]) ? options[:type] : FalkorLib.config[:versioning][:type]
|
107
|
+
source = (options[:source]) ? options[:source] : FalkorLib.config[:versioning][:source][ type ]
|
108
|
+
versionfile = File.join( rootdir, source[:filename] ) unless source[:filename].nil?
|
109
|
+
major, minor, patch = major(version), minor(version), patch(version)
|
110
|
+
#tocommit = ""
|
111
|
+
case type
|
112
|
+
when 'file'
|
113
|
+
info "writing version changes in #{source[:filename]}"
|
114
|
+
File.open(versionfile, 'w') { |f| f.puts version } #if File.exist? ( versionfile )
|
115
|
+
when 'gem'
|
116
|
+
info "=> writing version changes in #{source[:filename]}"
|
117
|
+
File.open(versionfile, 'r+') do |f|
|
118
|
+
text = f.read
|
119
|
+
text.gsub!(/^(\s*)MAJOR\s*,\s*MINOR,\s*PATCH\s*=\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(.*)$/,
|
120
|
+
'\1' + "MAJOR, MINOR, PATCH = #{major}, #{minor}, #{patch}" + '\5')
|
121
|
+
f.rewind
|
122
|
+
f.write(text)
|
182
123
|
end
|
183
|
-
|
184
|
-
|
185
|
-
|
124
|
+
when 'puppet_module'
|
125
|
+
info "=> writing version changes in #{source[:filename]}"
|
126
|
+
metadata = JSON.parse( IO.read( versionfile ) )
|
127
|
+
metadata["version"] = version
|
128
|
+
File.open(versionfile, "w") do |f|
|
129
|
+
f.write JSON.pretty_generate( metadata )
|
186
130
|
end
|
187
|
-
#
|
188
|
-
|
131
|
+
#exit 1
|
132
|
+
end
|
133
|
+
if FalkorLib::Git.init?(rootdir)
|
134
|
+
filelist = FalkorLib::Git.list_files( rootdir )
|
135
|
+
Dir.chdir( rootdir ) do
|
136
|
+
next if source[:filename].nil?
|
137
|
+
unless filelist.include?( source[:filename] )
|
138
|
+
warning "The version file #{source[:filename]} is not part of the Git repository"
|
139
|
+
answer = ask("Adding the file to the repository? (Y|n)", 'Yes')
|
140
|
+
next if answer =~ /n.*/i
|
141
|
+
exit_status = FalkorLib::Git.add(versionfile, "Adding the version file '#{source[:filename]}', inialized to the '#{version}' version" )
|
142
|
+
next
|
143
|
+
end
|
144
|
+
run %( git diff #{source[:filename]} )
|
145
|
+
answer = ask(cyan("=> Commit the changes of the version file to the repository? (Y|n)"), 'Yes')
|
146
|
+
next if answer =~ /n.*/i
|
147
|
+
run %( git commit -s -m "bump to version '#{version}'" #{source[:filename]} )
|
148
|
+
exit_status = $?.to_i
|
149
|
+
# if (type == 'gem' && File.exists?(File.join(rootdir, 'Gemfile')) )
|
150
|
+
# run %{
|
151
|
+
# sleep 2
|
152
|
+
# bundle update falkorlib
|
153
|
+
# git commit -s -m "Update Gemfile.lock accordingly" Gemfile.lock
|
154
|
+
# } if command?( 'bundle' )
|
155
|
+
# end
|
189
156
|
end
|
157
|
+
end
|
158
|
+
exit_status
|
159
|
+
end
|
160
|
+
|
161
|
+
## Return a new version number based on
|
162
|
+
# @param oldversion the old version (format: x.y.z)
|
163
|
+
# @param level the level of bumping (either :major, :minor, :patch)
|
164
|
+
def bump(oldversion, level)
|
165
|
+
major = minor = patch = 0
|
166
|
+
if oldversion =~ /^(\d+)\.(\d+)\.(\d+)$/
|
167
|
+
major = Regexp.last_match(1).to_i
|
168
|
+
minor = Regexp.last_match(2).to_i
|
169
|
+
patch = Regexp.last_match(3).to_i
|
170
|
+
end
|
171
|
+
case level.to_sym
|
172
|
+
when :major
|
173
|
+
major += 1
|
174
|
+
minor = 0
|
175
|
+
patch = 0
|
176
|
+
when :minor
|
177
|
+
minor += 1
|
178
|
+
patch = 0
|
179
|
+
when :patch
|
180
|
+
patch += 1
|
181
|
+
end
|
182
|
+
version = [major, minor, patch].compact.join('.')
|
183
|
+
version
|
184
|
+
end
|
185
|
+
|
186
|
+
# for rspec
|
187
|
+
module Gem
|
188
|
+
end
|
189
|
+
# for rspec
|
190
|
+
module Puppet
|
191
|
+
end
|
190
192
|
|
191
|
-
|
193
|
+
end # module
|
192
194
|
|
193
195
|
end
|