sprout 0.7.201-mswin32 → 0.7.203-mswin32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,121 @@
1
+ require 'git'
2
+ require 'sprout/version_file'
3
+
4
+ module Sprout
5
+
6
+ class GitTaskError < StandardError; end
7
+
8
+ # A Rake task for continous integration and automated deployment.
9
+ # This task will automatically load a +version_file+, increment
10
+ # the last digit (revision), create a new tag in Git with the full
11
+ # version number, and push tags to the remote Git repository.
12
+ #
13
+ # To use this task, simply add the following to your rakefile:
14
+ #
15
+ # desc 'Increment revision, tag and push with git'
16
+ # git :tag do |t|
17
+ # t.version_file = 'version.txt'
18
+ # end
19
+ #
20
+
21
+ class GitTask < Rake::Task
22
+ # Path to a plain text file that contains a three-part version number.
23
+ # @see VersionFile
24
+ attr_accessor :version_file
25
+ # Accessor for mocking the git gem.
26
+ attr_accessor :scm
27
+ # The remote branch to use, defaults to 'origin'.
28
+ attr_accessor :remote
29
+ # The local branch to send, defaults to 'master'.
30
+ attr_accessor :branch
31
+ # Message to use when committing after incrementing revision number.
32
+ # Defaults to 'Incremented revision number'.
33
+ attr_accessor :commit_message
34
+
35
+ def initialize(name, app)
36
+ super
37
+ @remote = 'origin'
38
+ @branch = 'master'
39
+ @commit_message = 'Incremented revision number'
40
+ end
41
+
42
+ def version
43
+ @version.to_s
44
+ end
45
+
46
+ def define
47
+ validate
48
+ @version = VersionFile.new(version_file)
49
+ end
50
+
51
+ def execute(*args)
52
+ super
53
+ # Fix numeric comparison....
54
+ while(get_tags.index(@version.to_tag)) do
55
+ @version.increment_revision
56
+ end
57
+ create_tag(@version.to_tag)
58
+ commit
59
+ push
60
+ end
61
+
62
+ def self.define_task(args, &block)
63
+ t = super
64
+ yield t if block_given?
65
+ t.define
66
+ return t
67
+ end
68
+
69
+ private
70
+
71
+ def push
72
+ `git push #{remote} #{branch} --tags`
73
+ end
74
+
75
+ def commit
76
+ `git commit -a -m "#{commit_message}"`
77
+ end
78
+
79
+ def path_to_git
80
+ git = '.git'
81
+ parts = Dir.pwd.split(File::SEPARATOR)
82
+
83
+ while(parts.size > 0) do
84
+ path = parts.join(File::SEPARATOR)
85
+ if(File.exists?(File.join(path, git)))
86
+ return path
87
+ end
88
+ parts.pop
89
+ end
90
+
91
+ return nil
92
+ end
93
+
94
+ def get_tags
95
+ return @scm.tags.collect do |t|
96
+ t.name
97
+ end
98
+ end
99
+
100
+ def create_tag(name)
101
+ @scm.add_tag name
102
+ end
103
+
104
+ def validate
105
+ raise GitTaskError.new('version_file is a required configuration for GitTask') if version_file.nil?
106
+ if(@scm.nil?)
107
+ path = path_to_git
108
+ raise GitTaskError.new("We don't appear to be inside of a git repository") if path.nil?
109
+ @scm = Git.open(path)
110
+ @scm.pull
111
+ end
112
+ end
113
+
114
+ end
115
+
116
+ end
117
+
118
+ # Helper method for definining the git task in a rakefile
119
+ def git(args, &block)
120
+ Sprout::GitTask.define_task(args, &block)
121
+ end
@@ -2,7 +2,7 @@ module Sprout
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 7
5
- TINY = 201
5
+ TINY = 203
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  MAJOR_MINOR = [MAJOR, MINOR].join('.')
@@ -0,0 +1,89 @@
1
+ module Sprout
2
+
3
+ # Used by the GitTask to load, parse and persist Version information
4
+ # related to a project.
5
+ # Expects a file with a 3 digit number, separated by periods like:
6
+ #
7
+ # 3.4.2
8
+ #
9
+ # Create with a path to the file like:
10
+ #
11
+ # version = VersionFile.new('path/Version.txt')
12
+ #
13
+ class VersionFile
14
+
15
+ def initialize(file_path)
16
+ @file_path = file_path
17
+ read_value
18
+ end
19
+
20
+ def value=(value)
21
+ @value = value
22
+ write_value
23
+ end
24
+
25
+ def value
26
+ @value
27
+ end
28
+
29
+ def major_version
30
+ @value.split('.').shift.to_i
31
+ end
32
+
33
+ def minor_version
34
+ @value.split('.')[1].to_i
35
+ end
36
+
37
+ def revision
38
+ @value.split('.').pop.to_i
39
+ end
40
+
41
+ def increment_revision
42
+ self.revision = self.revision + 1
43
+ end
44
+
45
+ def to_s
46
+ @value
47
+ end
48
+
49
+ def to_str
50
+ @value
51
+ end
52
+
53
+ def to_tag
54
+ parts = value.split('.')
55
+ parts[0] = add_leading_zeros(parts[0], 2)
56
+ parts[1] = add_leading_zeros(parts[1], 2)
57
+ parts[2] = add_leading_zeros(parts[2], 3)
58
+ return parts.join('.')
59
+ end
60
+
61
+ private
62
+
63
+ def add_leading_zeros(str, digits)
64
+ (digits - str.size).times do
65
+ str = "0#{str}"
66
+ end
67
+ str
68
+ end
69
+
70
+ def read_value
71
+ File.open(@file_path, 'r') do |file|
72
+ @value = file.read.strip
73
+ end
74
+ end
75
+
76
+ def write_value
77
+ File.open(@file_path, 'r+') do |file|
78
+ file.write @value
79
+ end
80
+ end
81
+
82
+ def revision=(revision)
83
+ parts = @value.split('.')
84
+ parts[2] = revision
85
+ @value = parts.join('.')
86
+ write_value
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.201
4
+ version: 0.7.203
5
5
  platform: mswin32
6
6
  authors:
7
7
  - Luke Bayes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-13 00:00:00 -08:00
12
+ date: 2009-01-14 00:00:00 -08:00
13
13
  default_executable: sprout
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -114,6 +114,7 @@ files:
114
114
  - lib/sprout/simple_resolver.rb
115
115
  - lib/sprout/tasks
116
116
  - lib/sprout/tasks/gem_wrap_task.rb
117
+ - lib/sprout/tasks/git_task.rb
117
118
  - lib/sprout/tasks/library_task.rb
118
119
  - lib/sprout/tasks/sftp_task.rb
119
120
  - lib/sprout/tasks/ssh_task.rb
@@ -122,6 +123,7 @@ files:
122
123
  - lib/sprout/template_resolver.rb
123
124
  - lib/sprout/user.rb
124
125
  - lib/sprout/version.rb
126
+ - lib/sprout/version_file.rb
125
127
  - lib/sprout/zip_util.rb
126
128
  - lib/sprout.rb
127
129
  - doc/Bundle