Class: Reissue::Task
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Reissue::Task
- Includes:
- Gem
- Defined in:
- lib/reissue/rake.rb
Instance Attribute Summary collapse
-
#changelog_file ⇒ Object
The path to the changelog file.
-
#commit ⇒ Object
Whether to commit the changes.
-
#commit_finalize ⇒ Object
Whether to commit the finalize change to the changelog.
-
#description ⇒ Object
A description of the main task.
-
#name ⇒ Object
The name of the main task and the namespace for the other tasks.
-
#push_finalize ⇒ Object
Whether to branch and push the changes.
-
#push_reissue ⇒ Object
Whether to push the changes when a new version is created.
- #updated_paths ⇒ Object
-
#version_file ⇒ Object
The path to the version file.
-
#version_limit ⇒ Object
The number of versions to retain in the changelog file.
-
#version_redo_proc ⇒ Object
A proc that can be used to create the new version string.
Class Method Summary collapse
Instance Method Summary collapse
- #define ⇒ Object
- #finalize_with_branch? ⇒ Boolean
-
#initialize(name = :reissue) ⇒ Task
constructor
A new instance of Task.
- #push_finalize? ⇒ Boolean
- #push_reissue? ⇒ Boolean
- #reissue_version_with_branch? ⇒ Boolean
Constructor Details
#initialize(name = :reissue) ⇒ Task
Returns a new instance of Task.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/reissue/rake.rb', line 63 def initialize(name = :reissue) @name = name @description = "Prepare the code for work on a new version." @version_file = nil @updated_paths = [] @changelog_file = "CHANGELOG.md" @commit = true @commit_finalize = true @push_finalize = false @version_limit = 2 @version_redo_proc = nil @push_reissue = :branch end |
Instance Attribute Details
#changelog_file ⇒ Object
The path to the changelog file.
32 33 34 |
# File 'lib/reissue/rake.rb', line 32 def changelog_file @changelog_file end |
#commit ⇒ Object
Whether to commit the changes. Default: true.
42 43 44 |
# File 'lib/reissue/rake.rb', line 42 def commit @commit end |
#commit_finalize ⇒ Object
Whether to commit the finalize change to the changelog. Default: true.
45 46 47 |
# File 'lib/reissue/rake.rb', line 45 def commit_finalize @commit_finalize end |
#description ⇒ Object
A description of the main task.
20 21 22 |
# File 'lib/reissue/rake.rb', line 20 def description @description end |
#name ⇒ Object
The name of the main task and the namespace for the other tasks.
17 18 19 |
# File 'lib/reissue/rake.rb', line 17 def name @name end |
#push_finalize ⇒ Object
Whether to branch and push the changes. Default: :branch. Requires commit_finialize to be true.
Set this to false to disable pushing. Set this to true to push to the current branch. Set this to :branch to push to a new branch.
53 54 55 |
# File 'lib/reissue/rake.rb', line 53 def push_finalize @push_finalize end |
#push_reissue ⇒ Object
Whether to push the changes when a new version is created. Default: :branch. Requires commit to be true.
Set this to false to disable pushing. Set this to true to push to the current branch. Set this to :branch to push to a new branch.
61 62 63 |
# File 'lib/reissue/rake.rb', line 61 def push_reissue @push_reissue end |
#updated_paths ⇒ Object
37 38 39 |
# File 'lib/reissue/rake.rb', line 37 def updated_paths Array(@updated_paths) end |
#version_file ⇒ Object
The path to the version file. Required.
23 24 25 |
# File 'lib/reissue/rake.rb', line 23 def version_file @version_file end |
#version_limit ⇒ Object
The number of versions to retain in the changelog file. Defaults to 2.
26 27 28 |
# File 'lib/reissue/rake.rb', line 26 def version_limit @version_limit end |
#version_redo_proc ⇒ Object
A proc that can be used to create the new version string.
29 30 31 |
# File 'lib/reissue/rake.rb', line 29 def version_redo_proc @version_redo_proc end |
Class Method Details
.create(name = :reissue, &block) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/reissue/rake.rb', line 8 def self.create name = :reissue, &block task = new name task.instance_eval(&block) if block raise "No Reissue task.version_file specified" unless task.version_file task.define task end |
Instance Method Details
#define ⇒ Object
93 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/reissue/rake.rb', line 93 def define desc description task name, [:segment] do |task, args| segment = args[:segment] || "patch" new_version = Reissue.call(segment:, version_file:, version_limit:, version_redo_proc:) if defined?(Bundler) Bundler.with_unbundled_env do system("bundle install") end end system("git add -u") if updated_paths.any? system("git add #{updated_paths.join(" ")}") end = "Bump version to #{new_version}" if commit if reissue_version_with_branch? Rake::Task["#{name}:branch"].invoke("reissue/#{new_version}") end system("git commit -m '#{}'") Rake::Task["#{name}:push"].invoke if push_reissue? else system("echo '#{}'") end new_version end desc "Reformat the changelog file to ensure it is correctly formatted." task "#{name}:reformat", [:version_limit] do |task, args| version_limit = if args[:version_limit].nil? self.version_limit else args[:version_limit].to_i end Reissue.reformat(changelog_file, version_limit:) end desc "Finalize the changelog for an unreleased version to set the release date." task "#{name}:finalize", [:date] do |task, args| date = args[:date] || Time.now.strftime("%Y-%m-%d") version, date = Reissue.finalize(date, changelog_file:) = "Finalize the changelog for version #{version} on #{date}" if commit_finalize Rake::Task["#{name}:branch"].invoke("reissue/#{version}") if finalize_with_branch? system("git add -u") system("git commit -m '#{}'") Rake::Task["#{name}:push"].invoke if push_finalize? else system("echo '#{}'") end end desc "Create a new branch for the next version." task "#{name}:branch", [:branch] do |task, args| raise "No branch name specified" unless args[:branch] system("git checkout -b #{args[:branch]}") end desc "Push the current branch to the remote repository." task "#{name}:push" do system("git push origin HEAD") end end |
#finalize_with_branch? ⇒ Boolean
77 78 79 |
# File 'lib/reissue/rake.rb', line 77 def finalize_with_branch? push_finalize == :branch end |
#push_finalize? ⇒ Boolean
81 82 83 |
# File 'lib/reissue/rake.rb', line 81 def push_finalize? !!push_finalize end |
#push_reissue? ⇒ Boolean
89 90 91 |
# File 'lib/reissue/rake.rb', line 89 def push_reissue? !!push_reissue end |
#reissue_version_with_branch? ⇒ Boolean
85 86 87 |
# File 'lib/reissue/rake.rb', line 85 def reissue_version_with_branch? push_reissue == :branch end |