Skip to content

Commit

Permalink
apacheGH-39996: [Archery] Fix Crossbow build on a PR from a fork's ma…
Browse files Browse the repository at this point in the history
…in branch

Instead of doing an intermediate bare clone, just fix the locally created branch name when fetching.

Amended from PR apache#39997, which wasn't sufficient (the `git fetch` that works for me doesn't seem to work on GHA).
  • Loading branch information
pitrou committed Feb 12, 2024
1 parent 30f6fdb commit 3dcf932
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/comment_bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
ARROW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROSSBOW_GITHUB_TOKEN: ${{ secrets.CROSSBOW_GITHUB_TOKEN }}
run: |
archery trigger-bot \
archery --debug trigger-bot \
--event-name ${{ github.event_name }} \
--event-payload ${{ github.event_path }}
Expand Down
30 changes: 15 additions & 15 deletions dev/archery/archery/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ def crossbow(obj, crossbow):
obj['crossbow_repo'] = crossbow


def _clone_arrow_and_crossbow(dest, crossbow_repo, arrow_repo_url,
pr_number, pr_branch):
def _clone_arrow_and_crossbow(dest, crossbow_repo, arrow_repo_url, pr_number):
"""
Clone the repositories and initialize crossbow objects.
Expand All @@ -335,23 +334,25 @@ def _clone_arrow_and_crossbow(dest, crossbow_repo, arrow_repo_url,
Filesystem path to clone the repositories to.
crossbow_repo : str
GitHub repository name, like kszucs/crossbow.
pull_request : pygithub.PullRequest
Object containing information about the pull request the comment bot
was triggered from.
arrow_repo_url : str
Target Apache Arrow repository's clone URL, such as
"https://github.com/apache/arrow.git".
pr_number : int
Target PR number.
"""
bare_arrow_path = dest / 'arrow_bare'
arrow_path = dest / 'arrow'
queue_path = dest / 'crossbow'

# we use unique branch name instead of fork's branch name to avoid
# branch name conflict such as 'main' (GH-39996)
local_branch = f'archery/pr-{pr_number}'
# 1. clone arrow and checkout the PR's branch
pr_ref = f'pull/{pr_number}/head:{pr_branch}'
# we do a bare clone of upstream arrow to avoid issues when the PR is
# submitted from a fork's main branch (GH-39996)
git.clone('--bare', arrow_repo_url, str(bare_arrow_path))
# fetch the PR's branch into the bare clone
git.fetch('origin', pr_ref, git_dir=bare_arrow_path)
# clone and checkout the PR's branch into a full local repo
git.clone(f'--branch={pr_branch}', bare_arrow_path, arrow_path)
pr_ref = f'pull/{pr_number}/head:{local_branch}'
git.clone('--no-checkout', arrow_repo_url, str(arrow_path))
# fetch the PR's branch into the clone
git.fetch('origin', pr_ref, git_dir=arrow_path)
# checkout the PR's branch into the clone
git.checkout(local_branch, git_dir=arrow_path)

# 2. clone crossbow repository
crossbow_url = 'https://github.com/{}'.format(crossbow_repo)
Expand Down Expand Up @@ -391,7 +392,6 @@ def submit(obj, tasks, groups, params, arrow_version, wait):
crossbow_repo=crossbow_repo,
arrow_repo_url=pull_request.base.repo.clone_url,
pr_number=pull_request.number,
pr_branch=pull_request.head.ref,
)
# load available tasks configuration and groups from yaml
config = Config.load_yaml(arrow.path / "dev" / "tasks" / "tasks.yml")
Expand Down

0 comments on commit 3dcf932

Please sign in to comment.