Skip to content

Conversation

@izaitsevfb
Copy link
Contributor

@izaitsevfb izaitsevfb commented Jan 25, 2024

Changes

  • introduce --check-mergeability trymerge flag that attempts to merge PR locally, using the same merge logic as the mergebot, but requires just a read-only GITHUB_TOKEN and git repo.
  • change mergeability workflow to utilize the new --check-mergeability logic

Alternatives considered

Rewrite https://github.com/pytorch/test-infra/actions/workflows/pr-dependencies-check.yml to correctly support partially merged ghstacks.

That would be a slightly better approach, but ROI is lower, as it requires reimplementing trymerge logic and additional effort to consolidate the codebase (trymerge lives in pytorch repo).

pr-dependencies-check.yml still produces human-readable results for partially merged ghstack prs (even if it falsely reports them as non-mergeable).

Instead of introducing new trymerge flag, use existing flags, including --dry-run.

That didn't work, as no combination of existing flags skips the rule checks and ROCKSET lookups.

Testing

  1. Manual testing trymerge.py --check-mergeability on the regular and ghstack PRs:
export GITHUB_TOKEN=
export GIT_REPO_DIR=`pwd`
export GITHUB_REPOSITORY=pytorch/pytorch
export GIT_REMOTE_URL=https://github.com/pytorch/pytorch


# Test 1 (2 prs, 1 is closed)
python3 ../pytorch/.github/scripts/trymerge.py --check-mergeability  117862
Skipping 1 of 2 PR (#117859) as its already been merged

echo $?
0

# Test 2 (3 prs, 1 is closed)
python3 ../pytorch/.github/scripts/trymerge.py --check-mergeability  118125
Skipping 1 of 3 PR (#117859) as its already been merged

echo $?
0

# Test 3 (3 prs, intentional conflicts introduced into `main`):

python3 ../pytorch/.github/scripts/trymerge.py --check-mergeability  118125
Skipping 1 of 3 PR (#117859) as its already been merged
stdout:
Auto-merging torch/_inductor/ir.py
Auto-merging torch/_inductor/lowering.py
CONFLICT (content): Merge conflict in torch/_inductor/lowering.py
error: could not apply 66ba5b8792f... Realize inputs to DynamicScalar before unwrapping 
...
RuntimeError: Command `git -C /Users/ivanzaitsev/pytorch2 cherry-pick -x 66ba5b8792fa076c4e512d920651e5b6b7e466f4` returned non-zero exit code 1
  1. Workflow run:
    https://github.com/pytorch/pytorch/actions/runs/7660736172/job/20878651852?pr=118258
image image

@izaitsevfb izaitsevfb requested a review from a team as a code owner January 25, 2024 02:11
@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Jan 25, 2024
@pytorch-bot
Copy link

pytorch-bot bot commented Jan 25, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/118258

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 38636cf with merge base b10b082 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@izaitsevfb izaitsevfb marked this pull request as draft January 25, 2024 02:12
@izaitsevfb izaitsevfb force-pushed the fix-ghstack-mergeability-check branch 6 times, most recently from e60bd69 to 026aab8 Compare January 25, 2024 21:34
@izaitsevfb izaitsevfb marked this pull request as ready for review January 25, 2024 21:50
@izaitsevfb izaitsevfb requested review from PaliC and huydhn January 25, 2024 21:50
… PR locally, using the same rules as the mergebot

* change mergeability workflow to utilize the new --check-mergeability logic
@izaitsevfb izaitsevfb force-pushed the fix-ghstack-mergeability-check branch from 026aab8 to 2aab17d Compare January 25, 2024 23:28
Copy link
Contributor

@PaliC PaliC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some naming nits, but otherwise lgtm

@izaitsevfb
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jan 26, 2024
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

gh_remove_label(
org, project, args.pr_num, MERGE_IN_PROGRESS_LABEL, args.dry_run
)
if not args.check_mergeability:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I see, it would always reach this part with not args.check_mergeability, so the if statement is kind of redundant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. For some reason I thought the try block starts earlier.

# and check if the following files were changed:
# .github/workflows/check_mergeability_ghstack.yml
# .github/scripts/trymerge.py
FILES_CHANGED=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
Copy link
Contributor

@huydhn huydhn Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine, but in case you need more complex logic (in bash :P), there are many GHA ready made to get the list of change files in a PR, i.e. https://github.com/tj-actions/changed-files

Copy link
Contributor Author

@izaitsevfb izaitsevfb Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already tried that action :)

Its description is a bit confusing, what it actually does, is checking the locally modified files, rather than the changest of the PR.

pr.merge_changes(
repo,
branch="main",
skip_mandatory_checks=True,
Copy link
Contributor

@huydhn huydhn Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: IMO, having 2 params called skip_mandatory_checks and skip_all_rule_checks is a bit weird as the latter's name implies that it subsumes the former. For example, in this call, setting skip_mandatory_checks to True or False doesn't matter. I don't want it to give the impression that skip_all_rule_checks is an option to bring in a bigger force merge hammer. It's more like a different kind of --dry-run like what you call out in the description. So, may be a different name is more apt, i.e. check_mergability_mode

izaitsevfb added a commit to pytorch/test-infra that referenced this pull request Jan 26, 2024
…st (#4907)

In pytorch/pytorch#118258 mergeability check job was renamed to
`ghstack-mergeability-check`. This PR updates flakiness exclusion
accordingly.
get_ghstack_prs(repo, pr) # raises error if out of sync
pr.merge_changes(
repo,
branch="main",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please please please don't hardcode default branch name, as pr has get_default_branch() property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants