Skip to content

Commit 796dfa2

Browse files
authored
Merge pull request #430 from github/enterprise-3.8-backport-354-adjust-release-script-to-support-patch-version
Backport 354 for 3.8: Adjusting backup-utils Release Script To Support Patch Versions
2 parents 8fcd8ae + ec181b4 commit 796dfa2

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

script/release

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ GH_REPO = ENV['GH_REPO'] || 'backup-utils'
3131
GH_OWNER = ENV['GH_OWNER'] || 'github'
3232
GH_AUTHOR = ENV['GH_AUTHOR']
3333
DEB_PKG_NAME = 'github-backup-utils'
34-
GH_BASE_BRANCH = ENV['GH_BASE_BRANCH'] || 'master'
34+
GH_BASE_BRANCH = ENV['GH_BASE_BRANCH'] || 'master' # TODO: should we even allow a default or require all params get set explicitly?
35+
GH_STABLE_BRANCH = ""
3536

3637
CHANGELOG_TMPL = '''<%= package_name %> (<%= package_version %>) UNRELEASED; urgency=medium
3738
@@ -137,7 +138,8 @@ def beautify_changes(changes)
137138
end
138139

139140
def changelog
140-
changes = `git log --pretty=oneline origin/stable...origin/#{GH_BASE_BRANCH} --reverse --grep "Merge pull request" | sort -t\# -k2`.lines.map(&:strip)
141+
puts "building changelog by comparing origin/#{GH_STABLE_BRANCH}...origin/#{GH_BASE_BRANCH}"
142+
changes = `git log --pretty=oneline origin/#{GH_STABLE_BRANCH}...origin/#{GH_BASE_BRANCH} --reverse --grep "Merge pull request" | sort -t\# -k2`.lines.map(&:strip)
141143
raise 'Building the changelog failed' if $CHILD_STATUS != 0
142144

143145
changes
@@ -228,12 +230,12 @@ def push_release_branch(version)
228230
end
229231

230232
def update_stable_branch
231-
`git checkout --quiet stable`
233+
`git checkout --quiet #{GH_STABLE_BRANCH}`
232234
unless (out = `git merge --quiet --ff-only origin/#{GH_BASE_BRANCH}`)
233-
warn "Merging #{GH_BASE_BRANCH} into stable failed:\n\n#{out}"
235+
warn "Merging #{GH_BASE_BRANCH} into #{GH_STABLE_BRANCH} failed:\n\n#{out}"
234236
end
235-
unless (out = `git push --quiet origin stable`)
236-
warn "Failed pushing the stable branch:\n\n#{out}"
237+
unless (out = `git push --quiet origin #{GH_STABLE_BRANCH}`)
238+
warn "Failed pushing the #{GH_STABLE_BRANCH} branch:\n\n#{out}"
237239
end
238240
end
239241

@@ -333,9 +335,38 @@ def clean_up(version)
333335
`git branch --quiet -D tmp-packaging >/dev/null 2>&1`
334336
end
335337

338+
def is_base_branch_valid?(branch)
339+
if branch == "master" || branch.match(/^\d+\.\d+-main$/)
340+
return true
341+
else
342+
return false
343+
end
344+
end
345+
346+
def get_stable_branch_name(branch)
347+
## derive the proper stable branch. if the base branch is "master" the stable branch is just "stable"
348+
## if the base branch is a release branch, the stable branch will be "x.y-stable"
349+
result = ""
350+
if branch == "master"
351+
result = "stable"
352+
else
353+
result = branch.gsub(/-main$/, "-stable")
354+
end
355+
356+
result
357+
end
358+
336359
#### All the action starts ####
337360
if $PROGRAM_NAME == __FILE__
338361
begin
362+
## validate base branch. this must either be "master" or a release branch which will match the pattern "x.y-main"
363+
raise "The branch #{GH_BASE_BRANCH} is not valid for releasing backup-utils. branch name must be master or match x.y-main" if !is_base_branch_valid?(GH_BASE_BRANCH)
364+
365+
GH_STABLE_BRANCH = get_stable_branch_name(GH_BASE_BRANCH)
366+
367+
puts "base branch = " + GH_BASE_BRANCH
368+
puts "stable branch = " + GH_STABLE_BRANCH
369+
339370
args = ARGV.dup
340371
dry_run = false
341372
skip_version_bump_check = false
@@ -455,7 +486,7 @@ if $PROGRAM_NAME == __FILE__
455486
puts 'Cleaning up...'
456487
clean_up version
457488

458-
puts 'Updating stable branch...'
489+
puts "Updating #{GH_STABLE_BRANCH} branch..."
459490
update_stable_branch
460491

461492
puts 'Released!'

0 commit comments

Comments
 (0)