Skip to content

Commit 649b276

Browse files
committed
Helper to update version branches like 4-0-dev
1 parent 2b53466 commit 649b276

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

Rakefile

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,33 @@ namespace :dev do
152152
end
153153

154154
namespace :git do
155+
desc 'create version branch'
156+
task :create_version_branch do
157+
unless ENV['BRANCH'] && ENV['VERSION']
158+
puts "Please specify a branch and a version .e.g"
159+
puts "BRANCH='4-0-dev' VERSION='4.0.0.pre' rake git:create_version_branch"
160+
exit(1)
161+
end
162+
163+
branch = ENV['BRANCH']
164+
version = ENV['VERSION']
165+
166+
each_project do |project|
167+
if system("git show-branch #{branch} > /dev/null 2>&1")
168+
sh "git checkout #{branch}"
169+
else
170+
sh "git checkout -b #{branch} main"
171+
end
172+
173+
update_maintenance_branch(true)
174+
update_version_file(project, version)
175+
176+
sh "git add ."
177+
sh "git ci -m 'Update version to #{version}'"
178+
end
179+
force_update(branch, nil)
180+
end
181+
155182
{ :status => nil, :push => nil, :reset => '--hard', :diff => nil }.each do |command, options|
156183
desc "git #{command} on all the repos"
157184
task command => :clone do
@@ -295,8 +322,13 @@ namespace :ci do
295322
Dir.mkdir(dirname)
296323
end
297324

298-
def update_maintenance_branch
299-
File.write("./maintenance-branch", BASE_BRANCH) unless File.exist?('./maintenance-branch')
325+
def update_maintenance_branch(override = false)
326+
File.write("./maintenance-branch", BASE_BRANCH) if override || !File.exist?('./maintenance-branch')
327+
end
328+
329+
def update_version_file(repo, version)
330+
full_file_name = ReposPath.join(repo, "lib/#{repo.gsub('-','/')}/version.rb")
331+
full_file_name.write(full_file_name.read.gsub(/(STRING = ['"])(.*)(['"])/, "STRING = '#{version}'"))
300332
end
301333

302334
def run_if_exists(script_file)

0 commit comments

Comments
 (0)