Skip to content

Commit

Permalink
Merge pull request #58 from yast/create_maintenance_branch_script
Browse files Browse the repository at this point in the history
Create maintenance branch script
  • Loading branch information
jreidinger committed Sep 4, 2014
2 parents 60a07ec + 9ab8380 commit f774014
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
6 changes: 6 additions & 0 deletions package/yast2-devtools.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Thu Sep 4 13:19:11 UTC 2014 - jreidinger@suse.com

- add tool for easy creation of maintenance branches to ytools
- 3.1.22

-------------------------------------------------------------------
Thu Sep 4 12:18:27 UTC 2014 - mvidner@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-devtools.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-devtools
Version: 3.1.21
Version: 3.1.22
Release: 0
Url: http://github.com/yast/yast-devtools

Expand Down
2 changes: 1 addition & 1 deletion ytools/yast2/Makefile.am
Expand Up @@ -17,6 +17,6 @@ vimsyntax_DATA = ycp.vim
vimftdir = $(prefix)/share/vim/site/ftdetect
vimft_DATA = ycp_filetype.vim

client_DATA = ycp2yml.rb
client_DATA = ycp2yml.rb create_maintenance_branch.rb

EXTRA_DIST = $(pkgdata_SCRIPTS) $(emacs_DATA) $(vimsyntax_DATA) $(vimft_DATA) $(client_DATA)
91 changes: 91 additions & 0 deletions ytools/yast2/create_maintenance_branch.rb
@@ -0,0 +1,91 @@
#!/usr/bin/env ruby

# - Create maintenance branch BRANCH_NAME
# - Edit Rakefile to build and submit to corresponding projects
# - Commit and push

# constants for tuning script to create desired branch
BRANCH_NAME="SLE-12-GA"
USE_IBS=true
DEVEL_PROJECT="Devel:YaST:SLE-12"
TARGET_PROJECT="SUSE:SLE-12:GA"
BUILD_TARGET="SLE-12"

# start of non-configuration part
CONF_OPTIONS = {
"obs_project" => DEVEL_PROJECT,
"obs_sr_project" => TARGET_PROJECT,
"obs_target" => BUILD_TARGET,
"obs_api" => USE_IBS ? "https://api.suse.de/" : "https://api.opensuse.org"
}

require "cheetah"

# by default pass output of commands to stdout and stderr
Cheetah.default_options = { :stdout => STDOUT, :stderr => STDERR }

def check_real_upstream
res = Cheetah.run "git", "remote", "-v", :stdout => :capture
if res.grep(/origin\s*git@github.com:yast/).empty?
raise "This script can work only on upstream clone, where upstream remote is marked as origin"
end
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")
conf_line = lines.grep(/Yast::Tasks.configuration do/).first
if conf_line
conf_var = conf_line[/do \|\s*(\S+)\s*\|/, 1]
line_index = lines.index(conf_line)
else
line_index = 2
conf_var = "conf"
conf_line = "Yast::Tasks.configuration do |#{conf_var}|\n"
lines.insert(line_index, conf_line, "end\n")
end

CONF_OPTIONS.each do |key, value|
config_line = lines.grep(/#{conf_var}\.#{key}\s*=/).first
new_line = " #{conf_var}.#{key} = #{value.inspect}\n"
if config_line
lines[lines.index[config_line]] = new_line
else
lines.insert(line_index + 1, new_line)
end
end

File.write("Rakefile", 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, "origin/master"
Cheetah.run "git", "checkout", BRANCH_NAME

modify_rakefile

commit_msg = "adapt Rakefile to submit to correct build service project in maintenance branch #{BRANCH_NAME}"

Cheetah.run "git", "commit", "-m", commit_msg, "Rakefile"

Cheetah.run "git", "push", "--set-upstream", "origin", BRANCH_NAME

puts "Maintenance branch properly created"

0 comments on commit f774014

Please sign in to comment.