Permalink
Switch branches/tags
yast-devtools/2_21_9 yast-devtools/2_21_6 yast-devtools/2_21_5 yast-devtools/2_21_4 yast-devtools/2_21_3 yast-devtools/2_21_1 yast-devtools/2_21_0 yast-devtools/2_18_11 yast-devtools/2_18_10 yast-devtools/2_18_9 yast-devtools/2_18_8 yast-devtools/2_18_7 yast-devtools/2_18_6 yast-devtools/2_18_5 yast-devtools/2_18_4 yast-devtools/2_18_3 yast-devtools/2_18_2 yast-devtools/2_18_1 yast-devtools/2_17_6 yast-devtools/2_17_5 yast-devtools/2_17_4 yast-devtools/2_17_3 yast-devtools/2_17_2 yast-devtools/2_17_1 yast-devtools/2_17_0 yast-devtools/2_16_8 yast-devtools/2_16_7 yast-devtools/2_16_4 yast-devtools/2_16_2 yast-devtools/2_16_1 yast-devtools/2_16_0 yast-devtools/2_15_9 yast-devtools/2_15_8 yast-devtools/2_15_7 yast-devtools/2_15_6 yast-devtools/2_15_5 yast-devtools/2_15_4 yast-devtools/2_15_3 yast-devtools/2_15_2 yast-devtools/2_15_0 yast-devtools/2_14_0 yast-devtools/2_13_29 yast-devtools/2_13_28 yast-devtools/2_13_18 yast-devtools/2_13_17 yast-devtools/2_13_16 yast-devtools/2_13_15 yast-devtools/2_13_14 yast-devtools/2_13_13 yast-devtools/2_13_12 yast-devtools/2_13_11 yast-devtools/2_13_10 yast-devtools/2_13_9 yast-devtools/2_13_8 yast-devtools/2_13_7 yast-devtools/2_13_6 yast-devtools/2_13_5 yast-devtools/2_13_4 yast-devtools/2_13_3 yast-devtools/2_13_1 yast-devtools/2_12_12 yast-devtools/2_12_11 yast-devtools/2_12_10 yast-devtools/2_12_9 yast-devtools/2_12_8 yast-devtools/2_12_7 yast-devtools/2_12_6 yast-devtools/2_12_5 yast-devtools/2_12_4 yast-devtools/2_12_3 yast-devtools/2_12_2 yast-devtools/2_12_1 yast-devtools/2_12_0 yast-devtools/2_11_7 yast-devtools/openSUSE-9_3/GM yast-devtools/master/3.1.36 yast-devtools/master/3.1.35 yast-devtools/master/3.1.34 yast-devtools/master/3.1.33 yast-devtools/master/3.1.32 yast-devtools/master/3.1.31 yast-devtools/master/3.1.30 yast-devtools/SLE-10-SP1/2_13_29 yast-devtools/SLE-10-SP1/2_13_27 yast-devtools/SLE-10-SP1/2_13_26 yast-devtools/SLE-10-SP1/2_13_25 yast-devtools/SLE-10-SP1/2_13_24 yast-devtools/SLE-10-SP1/2_13_23 yast-devtools/SLE-10-SP1/2_13_22 yast-devtools/SLE-10-SP1/2_13_21 yast-devtools/SLE-10-SP1/2_13_20 yast-devtools/Code-11-SP2/2_17_8 yast-devtools/Code-11-SP1/2_17_7 v4.0.1 svn/openSUSE-12_1 svn/openSUSE-11_4 svn/openSUSE-11_3 svn/openSUSE-11_2 svn/openSUSE-11_0 svn/openSUSE-10_3
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 132 lines (100 sloc) 3.44 KB
#!/usr/bin/env ruby
# - Create maintenance branch
# - Edit Rakefile to build and submit to corresponding projects
# - Commit and push
require "cheetah"
if ARGV.size < 2
STDERR.puts <<EOS
Bad arguments
First argument: name of the branch
Second argument: name of the target as recognized by yast-rake, see
https://github.com/yast/yast-rake/blob/master/data/targets.yml
second argument is also used for docker tag, just adds '-' before "sp" part
Third argument (optional): source commit, if not specified use master
Examples:
#{File.basename($0)} SLE-12-SP1 sle12sp1 # creates branch for master
#{File.basename($0)} SLE-12-SP1 sle12sp1 abcdef # creates branch from commit abcdef
EOS
exit(1)
end
BRANCH_NAME = ARGV[0]
TARGET = ARGV[1].delete(":")
SOURCE_COMMIT = ARGV[2] || "origin/master"
# by default pass output of commands to stdout and stderr
Cheetah.default_options = { :stdout => STDOUT, :stderr => STDERR }
def project
raise unless @project
@project
end
NAMESPACES_MAPPING = {
"libyui" => "Libyui",
"yast" => "Yast"
}
def project_namespace
raise unless @project
NAMESPACES_MAPPING[@project] || raise("Unknown project #{@project}")
end
def project=(value)
@project = value
end
def check_real_upstream
res = Cheetah.run "git", "remote", "-v", :stdout => :capture
upstream = res.lines.grep(/origin\s*git@github.com:(yast|libyui)/)
if upstream.empty?
raise "This script can work only on upstream clone, where upstream remote is marked as origin"
end
self.project = upstream.first[/origin\s*git@github.com:(yast|libyui)/, 1]
end
def already_exists?
res = Cheetah.run "git", "branch", "-r", :stdout => :capture
res = res.lines
return !res.grep(/origin\/#{BRANCH_NAME}/).empty?
end
def modify_rakefile
raise "Cannot find Rakefile in pwd" unless File.exist?("Rakefile")
lines = File.readlines("Rakefile")
submit_to = "#{project_namespace}::Tasks.submit_to"
new_line = "#{submit_to} :#{TARGET}\n"
line_index = lines.index {|l| l =~ /#{submit_to}/ }
if line_index
lines[line_index] = new_line
else # line is not there yet, so place it below require line
line_index = lines.index {|l| l =~ /^\s*require.*#{project}\/rake/ }
lines.insert(line_index + 1, "\n", new_line)
end
File.write("Rakefile", lines.join(""))
end
def modify_dockerfile
if !File.exist?("Dockerfile")
STDERR.puts "No Dockerfile, skipping its adaptation"
return
end
lines = File.readlines("Dockerfile")
from_index = lines.index { |l| l =~ /^FROM / }
raise "Missing FROM in dockerfile" unless from_index
line = lines[from_index]
docker_tag = ":" + TARGET.sub(/sp/, "-sp")
if line.include?(":") # docker file already use tag
line.sub!(/:.*$/, docker_tag + "\n")
else
line.sub!(/\s*$/, docker_tag + "\n")
end
File.write("Dockerfile", lines.join(""))
end
check_real_upstream
if already_exists?
puts "already exists, skipping"
exit 0
end
#switch to master branch
Cheetah.run "git", "checkout", "master"
#create new branch ( ensure we use the latest non modified pushed version )
Cheetah.run "git", "fetch", "origin"
Cheetah.run "git", "branch", BRANCH_NAME, SOURCE_COMMIT
Cheetah.run "git", "checkout", BRANCH_NAME
modify_rakefile
modify_dockerfile
commit_msg = "adapt Rakefile and Dockerfile for #{BRANCH_NAME}"
Cheetah.run "git", "commit", "-am", commit_msg
Cheetah.run "git", "push", "--set-upstream", "origin", "#{BRANCH_NAME}:#{BRANCH_NAME}"
puts "Maintenance branch properly created"