-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from yast/sp6_branching
Updated scripts for Git branching
- Loading branch information
Showing
3 changed files
with
190 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ Metrics/CyclomaticComplexity: | |
|
||
Metrics/PerceivedComplexity: | ||
Max: 12 | ||
|
||
Metrics/BlockLength: | ||
Max: 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,49 +12,56 @@ | |
# You might need to edit the configuration below. | ||
# | ||
|
||
############# start of editable values ############ | ||
############# start of configuration values ############ | ||
# usually it should be enough just to edit these few values | ||
|
||
# the new SP version number | ||
SP = "7".freeze | ||
|
||
# bug number used in the *.changes files, | ||
# open a new bug report regarding branching | ||
BUG_NR = "1230201".freeze | ||
|
||
# author + email, written into the changes files | ||
AUTHOR = "Ladislav Slezák <[email protected]>".freeze | ||
|
||
############# end of configuration values ############ | ||
|
||
# previous SP used as the base for the new one | ||
OLD_SP = (SP.to_i - 1).to_s | ||
|
||
# new YaST package versions in master | ||
# WARNING: libyui packages might use different versioning! | ||
NEW_PACKAGE_VERSION = "4.6.0".freeze | ||
NEW_PACKAGE_VERSION = "4.#{SP}.0".freeze | ||
|
||
# some packages use the distro based version (like the skelcds) | ||
NEW_DISTRO_VERSION = "15.6.0".freeze | ||
|
||
# author + email, written into the changes files | ||
AUTHOR = "Josef Reidinger <[email protected]>".freeze | ||
NEW_DISTRO_VERSION = "15.#{SP}.0".freeze | ||
|
||
# change only packages which have this branch defined, | ||
# if there is a brand new package you need to branch it manually | ||
GIT_OLD_BRANCH = "SLE-15-SP5".freeze | ||
GIT_OLD_BRANCH = "SLE-15-SP#{OLD_SP}".freeze | ||
|
||
# new branch to create | ||
GIT_NEW_BRANCH = "SLE-15-SP6".freeze | ||
GIT_NEW_BRANCH = "SLE-15-SP#{SP}".freeze | ||
|
||
# new branch for openSUSE specific packages | ||
GIT_OPENSUSE_NEW_BRANCH = "openSUSE-15_6".freeze | ||
GIT_OPENSUSE_OLD_BRANCH = "openSUSE-15_5".freeze | ||
|
||
# bug number used in the *.changes files, | ||
# open a new bug report regarding branching | ||
BUG_NR = "1208913".freeze | ||
GIT_OPENSUSE_NEW_BRANCH = "openSUSE-15_#{SP}".freeze | ||
GIT_OPENSUSE_OLD_BRANCH = "openSUSE-15_#{OLD_SP}".freeze | ||
|
||
# Rakefile submit target | ||
SUBMIT_TARGET = "sle15sp6".freeze | ||
SUBMIT_TARGET = "sle15sp#{SP}".freeze | ||
|
||
OBS_SUBMIT = <<TEXT | ||
conf.obs_api = "https://api.opensuse.org" | ||
conf.obs_target = "openSUSE_Leap_15.6" | ||
conf.obs_sr_project = "openSUSE:Leap:15.6:Update" | ||
conf.obs_project = "YaST:openSUSE:15.6" | ||
conf.obs_target = "openSUSE_Leap_15.#{SP}" | ||
conf.obs_sr_project = "openSUSE:Leap:15.#{SP}:Update" | ||
conf.obs_project = "YaST:openSUSE:15.#{SP}" | ||
TEXT | ||
.freeze | ||
|
||
# prefix for the Docker image name used in GitHub CI | ||
IMAGE_PATH = "registry.opensuse.org/yast/sle-15/sp6/containers/".freeze | ||
LIBYUI_IMAGE_PATH = "registry.opensuse.org/devel/libraries/libyui/sle-15/sp6/containers/".freeze | ||
|
||
############# end of editable values ############ | ||
IMAGE_PATH = "registry.opensuse.org/yast/sle-15/sp#{SP}/containers/".freeze | ||
LIBYUI_IMAGE_PATH = "registry.opensuse.org/devel/libraries/libyui/sle-15/sp#{SP}/containers/".freeze | ||
|
||
require "optparse" | ||
require_relative "../github_actions/gh_helpers" | ||
|
@@ -169,7 +176,7 @@ def update_changes(_version) | |
------------------------------------------------------------------- | ||
#{TIME_ENTRY} - #{AUTHOR} | ||
- Branch package for SP6 (bsc##{BUG_NR}) | ||
- Branch package for SP#{SP} (bsc##{BUG_NR}) | ||
CHANGES | ||
.freeze | ||
|
@@ -307,6 +314,7 @@ def bump_version(repo) | |
def git_clone(repo, checkout_dir) | ||
if File.directory?(checkout_dir) | ||
Dir.chdir(checkout_dir) do | ||
system("git reset --hard") | ||
system("git pull --rebase") | ||
end | ||
else | ||
|
@@ -371,7 +379,7 @@ def create_branch(client, repo, confirm) | |
# checkout master, merge the maintenance branch and always use current HEAD | ||
system("git checkout master") | ||
# use ours merge strategy as there will be conflicts we want to ignore | ||
system("git merge -s ours -m \"Clean merge of SP6\" #{new_branch}") | ||
system("git merge -s ours -m \"Mark the SP#{SP} branch as merged without any change\" #{new_branch}") | ||
|
||
# push to master, temporarily disable branch protection | ||
with_unprotected(client, repo.full_name, repo.default_branch) do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# This script copies the missing changes from IBS to Git. It is a single purpose | ||
# script shared just for reference when we need to do something similar again. | ||
# | ||
# You need admin access rights to temporarily disable the GitHub branch protection | ||
# and allow direct push without pull requests. | ||
# | ||
|
||
require "shellwords" | ||
require "find" | ||
require "fileutils" | ||
|
||
require_relative "../github_actions/gh_helpers" | ||
|
||
gh_organization = "yast" | ||
|
||
# subdirectory where to clone Git repositories | ||
GIT_CHECKOUT_DIR = "github".freeze | ||
|
||
def git_clone(repo, checkout_dir) | ||
if File.directory?(checkout_dir) | ||
Dir.chdir(checkout_dir) do | ||
system("git reset --hard") | ||
system("git pull --rebase") | ||
end | ||
else | ||
system("git clone #{repo.ssh_url} #{checkout_dir}") | ||
end | ||
end | ||
|
||
def find_file(file, dir) | ||
Find.find(dir) do |path| | ||
return path if File.basename(path) == file | ||
end | ||
|
||
nil | ||
end | ||
|
||
def confirmed? | ||
msg = "\nCommit the change? [N/y] " | ||
print msg | ||
|
||
input = nil | ||
loop do | ||
input = $stdin.gets.strip | ||
break if ["Y", "y", "N", "n", ""].include?(input) | ||
|
||
print "Invalid input#{msg}" | ||
end | ||
|
||
["Y", "y"].include?(input) | ||
end | ||
|
||
client = gh_client | ||
git_repos = gh_repos(client, gh_organization) | ||
removed = [] | ||
|
||
r2 = ["system-role-xen", "yast-slp", "yast-testsuite"] | ||
git_repos.select! { |r| r2.include?(r.name) } | ||
|
||
git_repos.each do |repo| | ||
branches = client.branches(repo.full_name).map(&:name) | ||
next unless branches.include?("SLE-15-SP6") | ||
|
||
# separate the output for each package | ||
puts "\e[32m" + ("-" * 80) + "\e[0m" | ||
puts repo.full_name | ||
|
||
# where to checkout the Git repository | ||
checkout_dir = File.join(GIT_CHECKOUT_DIR, repo.name) | ||
git_clone(repo, checkout_dir) | ||
|
||
Dir.chdir(checkout_dir) do | ||
system("git checkout SLE-15-SP6") | ||
# find the package name, expand the macros, some packages use a macro in the name | ||
end | ||
|
||
pkg = `find #{checkout_dir.shellescape} -name '*.spec' | grep -v /test/ | \ | ||
xargs cat | grep ^Name: | sed -e 's/^Name:\\s*//' | sort | head -n1`.chomp | ||
|
||
# expand the RPM macros when needed | ||
if pkg.include?("%") | ||
pkg = `find #{checkout_dir.shellescape} -name '*.spec' | grep -v /test/ | \ | ||
xargs rpmspec --parse | grep ^Name: | sed -e 's/^Name:\\s*//' | sort | head -n1`.chomp | ||
end | ||
|
||
if pkg.empty? | ||
puts "Package in #{repo.name} not found!" | ||
gets | ||
next | ||
end | ||
|
||
osc_dir = File.join("SUSE:SLE-15-SP6:Update", pkg) | ||
|
||
# checkout the package from IBS | ||
system("osc -A https://api.suse.de co SUSE:SLE-15-SP6:Update #{pkg.shellescape}") if !File.exist?(osc_dir) | ||
|
||
Find.find(osc_dir) do |obs_path| | ||
obs_file = File.basename(obs_path) | ||
|
||
# skip the .osc subdirectory | ||
if File.directory?(obs_path) && obs_file == ".osc" | ||
Find.prune | ||
else | ||
next if File.directory?(obs_path) | ||
|
||
git_path = find_file(obs_file, checkout_dir) | ||
|
||
if git_path | ||
# copy the file | ||
FileUtils.cp(obs_path, git_path, verbose: true) | ||
# ignore the tarballs | ||
elsif !obs_path.include?(".tar.") | ||
warn "File #{obs_file} not found in Git!" | ||
end | ||
end | ||
end | ||
|
||
# show the diff | ||
Dir.chdir(checkout_dir) do | ||
diff = `git --no-pager diff` | ||
|
||
# no change found | ||
next if diff.empty? | ||
|
||
puts diff | ||
next unless confirmed? | ||
|
||
if branches.include?("SLE-15-SP7") | ||
puts "SP7 diff:" | ||
system("git diff SLE-15-SP6..origin/SLE-15-SP7") | ||
next unless confirmed? | ||
end | ||
|
||
# commit the changes | ||
system("git commit -a -m \"Import the changes from the OBS SLE15-SP6 project\"") | ||
|
||
# push the changes (temporarily disable the branch protection) | ||
with_unprotected(client, repo.full_name, "SLE-15-SP6") do | ||
system("git push") | ||
end | ||
|
||
# delete the SP7 branch if it exists (branch it again from the updated SP6 separately) | ||
if branches.include?("SLE-15-SP7") | ||
client.unprotect_branch(repo.full_name, "SLE-15-SP7") | ||
system("git push origin --delete SLE-15-SP7") | ||
|
||
removed.append(repo.name) | ||
end | ||
|
||
end | ||
end | ||
|
||
puts "Removed SP7 branch from #{removed.size} repositories: #{removed.inspect}" |