Skip to content

Commit

Permalink
ARROW-16664: [CI][Release] Create verify release Pull Request automat…
Browse files Browse the repository at this point in the history
…ically (#13511)

Authored-by: Raúl Cumplido <raulcumplido@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
raulcd committed Jul 6, 2022
1 parent c6c6373 commit 6c4261e
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 13 deletions.
60 changes: 59 additions & 1 deletion dev/archery/archery/crossbow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def submit(obj, tasks, groups, params, job_prefix, config_path, arrow_version,

# Override the detected repo url / remote, branch and sha - this aims to
# make release procedure a bit simpler.
# Note, that the target resivion's crossbow templates must be
# Note, that the target revision's crossbow templates must be
# compatible with the locally checked out version of crossbow (which is
# in case of the release procedure), because the templates still
# contain some business logic (dependency installation, deployments)
Expand Down Expand Up @@ -155,6 +155,64 @@ def submit(obj, tasks, groups, params, job_prefix, config_path, arrow_version,
click.echo('Pushed job identifier is: `{}`'.format(job.branch))


@crossbow.command()
@click.option('--base-branch', default="master",
help='Set base branch for the PR.')
@click.option('--create-pr', is_flag=True, default=False,
help='Create GitHub Pull Request')
@click.option('--github-token', envvar='ARROW_GITHUB_API_TOKEN',
help='OAuth token to create PR and comments in the arrow repo')
@click.option('--head-branch', default=None,
help='Give the branch name explicitly, e.g. release-9.0.0-rc0')
@click.option('--pr-body', default=None,
help='Set body for the PR.')
@click.option('--pr-title', default=None,
help='Set title for the PR.')
@click.option('--remote', default=None,
help='Set GitHub remote explicitly, which is going to be used '
'for the PR. Note, that no validation happens '
'locally. Examples: https://github.com/apache/arrow or '
'https://github.com/raulcd/arrow.')
@click.option('--rc', default=None,
help='Relase Candidate number.')
@click.option('--version', default=None,
help='Release version.')
@click.option('--verify-binaries', is_flag=True, default=False,
help='Trigger the verify binaries jobs')
@click.option('--verify-source', is_flag=True, default=False,
help='Trigger the verify source jobs')
@click.option('--verify-wheels', is_flag=True, default=False,
help='Trigger the verify wheels jobs')
@click.pass_obj
def verify_release_candidate(obj, base_branch, create_pr, github_token,
head_branch, pr_body, pr_title, remote,
rc, version, verify_binaries, verify_source,
verify_wheels):
# The verify-release-candidate command will create a PR (or find one)
# and add the verify-rc* comment to trigger the verify tasks

# Redefine Arrow repo to use the correct arrow remote.
arrow = Repo(path=obj['arrow'].path, remote_url=remote)
response = arrow.github_pr(title=pr_title, head=head_branch,
base=base_branch, body=pr_body,
github_token=github_token,
create=create_pr)

# If we want to trigger any verification job we add a comment to the PR.
verify_flags = [verify_source, verify_binaries, verify_wheels]
if any(verify_flags):
command = "@github-actions crossbow submit"
verify_groups = ["verify-rc-source",
"verify-rc-binaries", "verify-rc-wheels"]
job_groups = ""
for flag, group in zip(verify_flags, verify_groups):
if flag:
job_groups += f" --group {group}"
response.create_comment(
f"{command} {job_groups} --param " +
f"release={version} --param rc={rc}")


@crossbow.command()
@click.argument('task', required=True)
@click.option('--config-path', '-c',
Expand Down
18 changes: 18 additions & 0 deletions dev/archery/archery/crossbow/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,24 @@ def github_overwrite_release_assets(self, tag_name, target_commitish,
'Unsupported upload method {}'.format(method)
)

def github_pr(self, title, head, base="master", body=None,
github_token=None, create=False):
github_token = github_token or self.github_token
repo = self.as_github_repo(github_token=github_token)
if create:
return repo.create_pull(title=title, base=base, head=head,
body=body)
else:
# Retrieve open PR for base and head.
# There should be a single open one with that title.
for pull in repo.pull_requests(state="open", head=head,
base=base):
if title in pull.title:
return pull
raise CrossbowError(
f"Pull request with Title: {title} not found"
)


class Queue(Repo):

Expand Down
18 changes: 18 additions & 0 deletions dev/release/02-source.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set -e
: ${SOURCE_DEFAULT:=1}
: ${SOURCE_RAT:=${SOURCE_DEFAULT}}
: ${SOURCE_UPLOAD:=${SOURCE_DEFAULT}}
: ${SOURCE_PR:=${SOURCE_DEFAULT}}
: ${SOURCE_VOTE:=${SOURCE_DEFAULT}}

SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
Expand All @@ -37,6 +38,8 @@ version=$1
rc=$2

tag=apache-arrow-${version}
maint_branch=maint-${version}
release_candidate_branch="release-${version}-rc${rc_number}"
tagrc=${tag}-rc${rc}
rc_url="https://dist.apache.org/repos/dist/dev/arrow/${tagrc}"

Expand Down Expand Up @@ -123,6 +126,21 @@ if [ ${SOURCE_UPLOAD} -gt 0 ]; then
echo ""
fi

# Create Pull Request and Crossbow comment to run verify source tasks
if [ ${SOURCE_PR} -gt 0 ]; then
archery crossbow verify-release-candidate \
--base-branch=${maint_branch} \
--create-pr \
--github-token=${ARROW_GITHUB_API_TOKEN} \
--head-branch=${release_candidate_branch} \
--pr-body="PR to verify Release Candidate" \
--pr-title="WIP: [Release] Verify ${release_candidate_branch}" \
--remote=https://github.com/apache/arrow \
--rc=${rc} \
--verify-source \
--version=${version}
fi

if [ ${SOURCE_VOTE} -gt 0 ]; then
echo "The following draft email has been created to send to the"
echo "dev@arrow.apache.org mailing list"
Expand Down
16 changes: 4 additions & 12 deletions docs/source/developers/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ generated properly.
- Have the build requirements for cpp and c_glib installed.
- Set the JIRA_USERNAME and JIRA_PASSWORD environment variables
- Set the ARROW_GITHUB_API_TOKEN environment variable to automatically create the verify release Pull Request.
- Install ``en_US.UTF-8`` locale. You can confirm available locales by ``locale -a``.
- Install Python 3 as python
- Create dev/release/.env from dev/release/.env.example. See the comments in dev/release/.env.example how to set each variable.
Expand Down Expand Up @@ -150,13 +151,15 @@ Create the Release Candidate branch from the updated maintenance branch
# Push the release tag (for RC1 or later the --force flag is required)
git push -u apache apache-arrow-<version>
# Push the release candidate branch in order to trigger verification jobs later
git push -u apache release-<version>-rc<rc-number>
Build source and binaries and submit them
-----------------------------------------

.. code-block::
# Build the source release tarball
# Build the source release tarball and create Pull Request with verification tasks
dev/release/02-source.sh <version> <rc-number>
# Submit binary tasks using crossbow, the command will output the crossbow build id
Expand Down Expand Up @@ -187,17 +190,6 @@ Verify the Release

.. code-block::
# Automatically verify the Release Candidate
#
# 1. Push the Release Candidate's branch to the fork
git push --set-upstream origin release-<version>-rc<rc-number>
# 2. Open a pull request from the Release Candidate's branch to the maintenance branch
# https://github.com/apache/arrow/compare/maint-<version>...<fork-github-username>:release-<version>-rc<rc-number>
# 3. Create a comment for the pull request to trigger the automatized crossbow verification tasks
# @github-actions crossbow submit --group verify-rc-source --group verify-rc-binaries --group verify-rc-wheels --param release=<version> --param rc=<rc-number>
#
# See https://github.com/apache/arrow/pull/10126 as an example.
# Once the automatic verification has passed merge the Release Candidate's branch to the maintenance branch
git checkout maint-<version>
git merge release-<version>-rc<rc-number>
Expand Down

0 comments on commit 6c4261e

Please sign in to comment.