Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2a7a517
Remove unused `repository_dispatch` trigger
henrymercer Mar 17, 2022
b386fd4
Parameterize release branch workflow over source and target branches
henrymercer Mar 17, 2022
81827d3
Use the person triggering the release workflow as the conductor
henrymercer Mar 17, 2022
ccda44c
Handle missing author information when generating changelog
henrymercer Mar 17, 2022
33f749f
Set up `main -> v2`, `v2 -> v1`, and `v2 -> main` merges
henrymercer Mar 17, 2022
d76b182
Add functionality for `v2 -> v1` backports
henrymercer Mar 17, 2022
4b465cb
Dump environment and GitHub context
henrymercer Mar 22, 2022
b8f3a37
Fix exception when there are no commits to merge
henrymercer Mar 22, 2022
124e7d9
Stop versioning the runner
henrymercer Mar 22, 2022
5fb01dd
Avoid commits with duplicate names during v2 to v1 backport
henrymercer Mar 22, 2022
bd4757c
Update the changelog and version number in a single commit
henrymercer Mar 22, 2022
1668e0a
Only mention merging the mergeback PR in the checklist when relevant
henrymercer Mar 22, 2022
0b037b4
Add merging the v1 release PR to the checklist
henrymercer Mar 23, 2022
f143182
Add "Update dependencies" label to v1 release PR
henrymercer Mar 23, 2022
3359990
Avoid conflicts by reverting 1.x version num commit from last v1 release
henrymercer Mar 23, 2022
da7944b
Update release process doc
henrymercer Mar 24, 2022
9d26fe0
Use source branch and target branch names consistently
henrymercer Mar 25, 2022
bed132d
Use a more restrictive `sed` pattern
henrymercer Mar 25, 2022
d0bd808
Expose a more restrictive interface to the release script
henrymercer Mar 25, 2022
f784647
Merge branch 'main' into henrymercer/update-release-process
henrymercer Mar 25, 2022
044f112
Update branch protection instructions
henrymercer Mar 25, 2022
839aa81
Merge branch 'main' into henrymercer/update-release-process
henrymercer Mar 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expose a more restrictive interface to the release script
Give the release script modes rather
than source and target branches
  • Loading branch information
henrymercer committed Mar 25, 2022
commit d0bd80897cc2d55a455a7d86d0c81f7056064b79
64 changes: 35 additions & 29 deletions .github/update-release-branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

"""

# Value of the mode flag for a v1 release
V1_MODE = 'v1-release'

# Value of the mode flag for a v2 release
V2_MODE = 'v2-release'

# Name of the remote
ORIGIN = 'origin'

Expand All @@ -30,7 +36,7 @@ def branch_exists_on_remote(branch_name):
return run_git('ls-remote', '--heads', ORIGIN, branch_name).strip() != ''

# Opens a PR from the given branch to the target branch
def open_pr(repo, all_commits, source_branch_short_sha, new_branch_name, source_branch, target_branch, conductor, is_v2_to_v1_backport, labels):
def open_pr(repo, all_commits, source_branch_short_sha, new_branch_name, source_branch, target_branch, conductor, is_v2_release, labels):
# Sort the commits into the pull requests that introduced them,
# and any commits that don't have a pull request
pull_requests = []
Expand Down Expand Up @@ -79,7 +85,7 @@ def open_pr(repo, all_commits, source_branch_short_sha, new_branch_name, source_
body.append(' - [ ] The CHANGELOG includes all relevant, user-facing changes since the last release.')
body.append(' - [ ] There are no unexpected commits being merged into the ' + target_branch + ' branch.')
body.append(' - [ ] The docs team is aware of any documentation changes that need to be released.')
if not is_v2_to_v1_backport:
if is_v2_release:
body.append(' - [ ] The mergeback PR is merged back into ' + source_branch + ' after this PR is merged.')
body.append(' - [ ] The v1 release PR is merged after this PR is merged.')

Expand Down Expand Up @@ -181,48 +187,48 @@ def main():
help='The nwo of the repository, for example github/codeql-action.'
)
parser.add_argument(
'--source-branch',
type=str,
required=True,
help='The branch being merged from, typically "main" for a v2 release or "v2" for a v1 release.'
)
parser.add_argument(
'--target-branch',
'--mode',
type=str,
required=True,
help='The branch being merged into, typically "v2" for a v2 release or "v1" for a v1 release.'
choices=[V2_MODE, V1_MODE],
help=f"Which release to perform. '{V2_MODE}' uses main as the source branch and v2 as the target branch. " +
f"'{V1_MODE}' uses v2 as the source branch and v1 as the target branch."
)
parser.add_argument(
'--conductor',
type=str,
required=True,
help='The GitHub handle of the person who is conducting the release process.'
)
parser.add_argument(
'--perform-v2-to-v1-backport',
action='store_true',
help='Pass this flag if this release is a backport from v2 to v1.'
)

args = parser.parse_args()

if args.mode == V2_MODE:
source_branch = 'main'
target_branch = 'v2'
elif args.mode == V1_MODE:
source_branch = 'v2'
target_branch = 'v1'
else:
raise ValueError(f"Unexpected value for release mode: '{args.mode}'")

repo = Github(args.github_token).get_repo(args.repository_nwo)
version = get_current_version()

if args.perform_v2_to_v1_backport:
if args.mode == V1_MODE:
# Change the version number to a v1 equivalent
version = get_current_version()
version = f'1{version[1:]}'

# Print what we intend to go
print('Considering difference between ' + args.source_branch + ' and ' + args.target_branch)
source_branch_short_sha = run_git('rev-parse', '--short', ORIGIN + '/' + args.source_branch).strip()
print('Current head of ' + args.source_branch + ' is ' + source_branch_short_sha)
print('Considering difference between ' + source_branch + ' and ' + target_branch)
source_branch_short_sha = run_git('rev-parse', '--short', ORIGIN + '/' + source_branch).strip()
print('Current head of ' + source_branch + ' is ' + source_branch_short_sha)

# See if there are any commits to merge in
commits = get_commit_difference(repo=repo, source_branch=args.source_branch, target_branch=args.target_branch)
commits = get_commit_difference(repo=repo, source_branch=source_branch, target_branch=target_branch)
if len(commits) == 0:
print('No commits to merge from ' + args.source_branch + ' to ' + args.target_branch)
print('No commits to merge from ' + source_branch + ' to ' + target_branch)
return

# The branch name is based off of the name of branch being merged into
Expand All @@ -240,7 +246,7 @@ def main():
# Create the new branch and push it to the remote
print('Creating branch ' + new_branch_name)

if args.perform_v2_to_v1_backport:
if args.mode == V1_MODE:
# If we're performing a backport, start from the v1 branch
print(f'Creating {new_branch_name} from the {ORIGIN}/v1 branch')
run_git('checkout', '-b', new_branch_name, f'{ORIGIN}/v1')
Expand All @@ -267,8 +273,8 @@ def main():
else:
print(' Nothing to revert.')

print(f'Merging {ORIGIN}/{args.source_branch} into the release prep branch')
run_git('merge', f'{ORIGIN}/{args.source_branch}', '--no-edit')
print(f'Merging {ORIGIN}/{source_branch} into the release prep branch')
run_git('merge', f'{ORIGIN}/{source_branch}', '--no-edit')

# Migrate the package version number from a v2 version number to a v1 version number
print(f'Setting version number to {version}')
Expand All @@ -286,7 +292,7 @@ def main():
# If we're performing a standard release, there won't be any new commits on the target branch,
# as these will have already been merged back into the source branch. Therefore we can just
# start from the source branch.
run_git('checkout', '-b', new_branch_name, f'{ORIGIN}/{args.source_branch}')
run_git('checkout', '-b', new_branch_name, f'{ORIGIN}/{source_branch}')

print('Updating changelog')
update_changelog(version)
Expand All @@ -303,11 +309,11 @@ def main():
commits,
source_branch_short_sha,
new_branch_name,
source_branch=args.source_branch,
target_branch=args.target_branch,
source_branch=source_branch,
target_branch=target_branch,
conductor=args.conductor,
is_v2_to_v1_backport=args.perform_v2_to_v1_backport,
labels=['Update dependencies'] if args.perform_v2_to_v1_backport else [],
is_v2_release=args.mode == V2_MODE,
labels=['Update dependencies'] if args.mode == V1_MODE else [],
)

if __name__ == '__main__':
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/update-release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ jobs:
python .github/update-release-branch.py \
--github-token ${{ secrets.GITHUB_TOKEN }} \
--repository-nwo ${{ github.repository }} \
--source-branch main \
--target-branch v2 \
--mode release-v2 \
--conductor ${GITHUB_ACTOR}

- name: Update v1 release branch
Expand All @@ -59,7 +58,5 @@ jobs:
python .github/update-release-branch.py \
--github-token ${{ secrets.GITHUB_TOKEN }} \
--repository-nwo ${{ github.repository }} \
--source-branch v2 \
--target-branch v1 \
--conductor ${GITHUB_ACTOR} \
--perform-v2-to-v1-backport
--mode release-v1 \
--conductor ${GITHUB_ACTOR}