forked from sbadia/puppet-gitlab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
96 lines (81 loc) · 2.22 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
NAME = 'puppet-gitlab'
TDIR = File.expand_path(File.dirname(__FILE__))
require 'puppetlabs_spec_helper/rake_tasks'
def get_version
if File.read(File.join(TDIR, 'Modulefile')) =~ /(\d+)\.(\d+)\.(\d+)/
return [$1.to_i, $2.to_i, $3.to_i].compact.join('.')
end
end # def:: get_version
def bump_version(level)
version_txt = get_version
if version_txt =~ /(\d+)\.(\d+)\.(\d+)/
major = $1.to_i
minor = $2.to_i
patch = $3.to_i
end
case level
when :major
major += 1
minor = 0
patch = 0
when :minor
minor += 1
patch = 0
when :patch
patch += 1
end
new_version = [major,minor,patch].compact.join('.')
v = File.read(File.join(TDIR,'Modulefile')).chomp
v.gsub!(/(\d+)\.(\d+)\.(\d+)/,"#{new_version}")
File.open(File.join(TDIR,'Modulefile'), 'w') do |file|
file.puts v
end
end # def:: bump_version(level)
namespace :module do
desc "New #{NAME} GIT release (v#{get_version})"
task :release do
sh "git tag #{get_version} -m \"New release: #{get_version}\""
sh "git push --tag"
end
namespace :bump do
desc "Bump #{NAME} by a major version"
task :major do
bump_version(:major)
end
desc "Bump #{NAME} by a minor version"
task :minor do
bump_version(:minor)
end
desc "Bump #{NAME} by a patch version"
task :patch do
bump_version(:patch)
end
end
namespace :check do
desc 'Check erb template syntax'
task :erb do
file=ARGV.values_at(Range.new(ARGV.index('check:erb')+1,-1))
exec "erb -x -T '-' #{file} | ruby -c"
end
desc "Check pp file syntax (return nothing if ok)"
task :pp do
file=ARGV.values_at(Range.new(ARGV.index('check:pp')+1,-1))
exec "puppet parser validate \"#{file}\""
end
desc "Check puppet syntax"
task :syntax do
file=ARGV.values_at(Range.new(ARGV.index('check:syntax')+1,-1))
exec "puppet-lint \"#{file}\""
end
end
desc "Build #{NAME} module (in a clean env) Please use this for puppetforge"
task :build do
exec "rsync -rv --exclude-from=#{TDIR}/.forgeignore . /tmp/puppet-gitlab"
exec "cd /tmp/puppet-gitlab;puppet module build"
end
end
task(:default).clear
task :default => :spec