Class: Sprout::GitTask
- Inherits:
-
Rake::Task
- Object
- Rake::Task
- Sprout::GitTask
- Defined in:
- lib/sprout/tasks/git_task.rb
Overview
A Rake task for continous integration and automated deployment. This task will automatically load a version_file, increment the last digit (revision), create a new tag in Git with the full version number, and push tags to the remote Git repository.
To use this task, simply add the following to your rakefile:
desc 'Increment revision, tag and push with git'
git :tag do |t|
t.version_file = 'version.txt'
end
Instance Attribute Summary collapse
-
#branch ⇒ Object
The local branch to send, defaults to ‘master’.
-
#commit_message ⇒ Object
Message to use when committing after incrementing revision number.
-
#remote ⇒ Object
The remote branch to use, defaults to ‘origin’.
-
#version_file ⇒ Object
Path to a plain text file that contains a three-part version number.
Class Method Summary collapse
Instance Method Summary collapse
- #define ⇒ Object
- #execute(*args) ⇒ Object
-
#initialize(name, app) ⇒ GitTask
constructor
A new instance of GitTask.
-
#scm ⇒ Object
Will open on path if no SCM exists yet.
-
#scm=(scm) ⇒ Object
Accessor for mocking the git gem.
- #version ⇒ Object
Constructor Details
#initialize(name, app) ⇒ GitTask
Returns a new instance of GitTask.
32 33 34 35 36 37 |
# File 'lib/sprout/tasks/git_task.rb', line 32 def initialize(name, app) super @remote = 'origin' @branch = 'master' = 'Incremented revision number' end |
Instance Attribute Details
#branch ⇒ Object
The local branch to send, defaults to ‘master’.
27 28 29 |
# File 'lib/sprout/tasks/git_task.rb', line 27 def branch @branch end |
#commit_message ⇒ Object
Message to use when committing after incrementing revision number. Defaults to ‘Incremented revision number’.
30 31 32 |
# File 'lib/sprout/tasks/git_task.rb', line 30 def end |
#remote ⇒ Object
The remote branch to use, defaults to ‘origin’.
25 26 27 |
# File 'lib/sprout/tasks/git_task.rb', line 25 def remote @remote end |
#version_file ⇒ Object
Path to a plain text file that contains a three-part version number.
23 24 25 |
# File 'lib/sprout/tasks/git_task.rb', line 23 def version_file @version_file end |
Class Method Details
.define_task(args) {|t| ... } ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sprout/tasks/git_task.rb', line 59 def self.define_task(args, &block) begin require 'git' rescue LoadError => e puts "You need to install the 'git' gem. Try running: sudo gem install git" raise e end t = super yield t if block_given? t.define return t end |
Instance Method Details
#define ⇒ Object
43 44 45 46 |
# File 'lib/sprout/tasks/git_task.rb', line 43 def define validate @version = VersionFile.new(version_file) end |
#execute(*args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sprout/tasks/git_task.rb', line 48 def execute(*args) super # Fix numeric comparison.... while(.index(@version.to_tag)) do @version.increment_revision end create_tag(@version.to_tag) commit push end |
#scm ⇒ Object
Will open on path if no SCM exists yet.
78 79 80 81 82 83 84 85 86 |
# File 'lib/sprout/tasks/git_task.rb', line 78 def scm if(@scm.nil?) path = path_to_git raise GitTaskError.new("We don't appear to be inside of a git repository") if path.nil? @scm = Git.open(path) end @scm end |
#scm=(scm) ⇒ Object
Accessor for mocking the git gem.
73 74 75 |
# File 'lib/sprout/tasks/git_task.rb', line 73 def scm=(scm) @scm = scm end |
#version ⇒ Object
39 40 41 |
# File 'lib/sprout/tasks/git_task.rb', line 39 def version @version.to_s end |