Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error messages #415

Open
korthout opened this issue Mar 1, 2024 · 4 comments
Open

Improve the error messages #415

korthout opened this issue Mar 1, 2024 · 4 comments
Labels
enhancement New feature or request prio: next Planning to work on this issue next

Comments

@korthout
Copy link
Owner

korthout commented Mar 1, 2024

Is your feature request related to a problem? Please describe.
Most comments by the action for errors are unclear, unhelpful, and appear to come from nowhere.

Example no permission to push to repo:

Git push to origin failed for case5-backport-target with exitcode 1

Describe the solution you'd like
Error messages should be clear about what was attempted, what went wrong, and what can be done to recover. For example:

Backport-action failed to generate a pull request cherry-picking these changes (workflow run). Tried to push branch backport-x-to-y, but not permitted to push to this repo.

You can use a Personal Access Token (PAT) with repo scope as the token input of the actions/checkout-action step to permit pushing to the repo.

Describe alternatives you've considered
..

Additional context
Some other example errors:

Not permitted to create pull request:

Resource not accessible by integration

Unable to cherry-pick

This error is clear about what happened, what went wrong, and how to recover. However, it still appears to come out of nowhere. A link to the workflow run would help.

Backport failed for stable/8.2, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin stable/8.2
git worktree add -d .worktree/backport-16634-to-stable/8.2 origin/stable/8.2
cd .worktree/backport-16634-to-stable/8.2
git switch --create backport-16634-to-stable/8.2
git cherry-pick -x a472372cdb055835682b13515442139655126034 02910366c2d4aff900c41a4dfd8de1f0e926dfae
@korthout korthout added the enhancement New feature or request label Mar 1, 2024
@korthout korthout added the prio: next Planning to work on this issue next label Mar 21, 2024
@ggwpez
Copy link

ggwpez commented Aug 27, 2024

I have this problem as well, where the bot just comments that something went wrong after i successfully merged the backport. To me it looks like everything went well:

Screenshot 2024-08-27 at 13 55 03

@ggwpez
Copy link

ggwpez commented Aug 27, 2024

PS: It is probably of how am using target_branches. In our repo we dont really want the developer to having to specify all the branches that they should backport in.
But specifying a label filter and target_branches at the same time seems to still try and backport even the backports again - which fails.

Could it be possible to have labels that dont require a regex matchgroup but rather only serve as a tag to trigger for all target_branches?

@korthout
Copy link
Owner Author

korthout commented Aug 27, 2024

@ggwpez It looks like your workflow is trying to backport the changes a second time. The merged PR's base to backport is the same as the selected target branch. This may lead to conflicts during cherry-picking, which explains why you'd see this error.

That's a bug, as backport-action could always exclude this unique case. There's no reason to port changes that were just merged to a branch again to that same branch. To verify that this happened, I'd be interested to see the workflow run logs, particularly the lines regarding:

Determining target branches..

While we should eventually resolve that as a separate bug, you could work around this by excluding PRs that directly target your target branch.

Something like:

    # Only backport to my_target_branch, if PR did not just merge something to it
    if: >
      github.event.pull_request.merged &&
      github.event.pull_request.base.ref != 'my_target_branch'
    steps:
      - uses: actions/checkout@v4
      - uses: korthout/backport-action@v3
        with:
          target_branches: my_target_branch

Could it be possible to have labels that dont require a regex matchgroup but rather only serve as a tag to trigger for all target_branches?

You could also try this. You can use a similar condition checking for specific labels. It may be useful to split up the different usages into separate workflows then:

  • one workflow to backport using a label with capture group when that's needed
  • one workflow to backport to a specific branch/branches when a specific label is used

Hope it helps, and let me know if you run into issues. Feel free to open a bug if you encounter new issues.

@ggwpez
Copy link

ggwpez commented Aug 28, 2024

Thanks for taking a look, your workaround with excluding the base.ref works. It seems to indeed end up with an empty commit while trying to backport the backport. I did not realize that it is using the workflow file from the stable branch instead of master. Full error log:

Details

Run korthout/backport-action@v3
  with:
    target_branches: stable[2](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:2)407
    merge_commits: skip
    github_token: ***
    label_pattern: A4-needs-backport
    pull_description: Backport #${pull_number} into `${target_branch}` (cc @${pull_author}).
  
    pull_title: [${target_branch}] Backport #${pull_number}
  
    branch_name: backport-${pull_number}-to-${target_branch}
    cherry_picking: auto
    copy_assignees: false
    copy_milestone: false
    copy_requested_reviewers: false
    experimental: {
    "conflict_resolution": "fail"
  }
  
    github_workspace: /home/runner/work/debug/debug
Retrieve pull request data for #85
Check whether pull request 85 is merged
Determining target branches...
Detected labels on PR: A[3](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:3)-backport
label 'A3-backport' doesn't match `label_pattern` 'A[4](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:4)-needs-backport'
Found target branches in labels: 
Found target branches in `target_branches` input: stable2407
Exclude pull request's headref from target branches: backport-84-to-stable2407
Determined target branches: stable2407
Fetching all the commits from the pull request: 2
git fetch --depth=2 origin refs/pull/8[5](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:5)/head
From https://github.com/ggwpez/debug
 * branch            refs/pull/85/head -> FETCH_HEAD
Retrieving the commits from pull request 85
PR was merged using a squash or a rebase. Choosing squash strategy.
git fetch --depth=2 origin +1[6](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:6)4f1c6a4799a307be59dfc2ae9c298995a1e133:refs/remotes/origin/164f1c6a4[7](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:7)99a307be59dfc2ae9c298995a1e133
From https://github.com/ggwpez/debug
 * [new ref]         164f1c6a4799a307be59dfc2ae9c29[8](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:8)[9](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:9)95a1e133 -> origin/164f1c6a4799a307be59dfc2ae9c298995a1e133
Found commits to backport: 164f1c6a4799a307be59dfc2ae9c298995a1e133
Checking the merged pull request for merge commits
git rev-list --merges 164f1c6a4799a307be59dfc2ae9c298995a1e[13](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:13)3^..164f1c6a4799a307be59dfc2ae9c298995a1e133
Encountered 0 merge commits
Will cherry-pick the following commits: [16](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:16)4f1c6a4799a307be59dfc2ae9c298995a1e133
Will copy labels matching undefined. Found matching labels: 
Backporting to target branch 'stable2407...'
git fetch --depth=1 origin stable2407
From https://github.com/ggwpez/debug
 * branch            stable[24](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:25)07 -> FETCH_HEAD
Start backport to backport-85-to-stable2407
git switch -c backport-85-to-stable2407 origin/stable2407
Switched to a new branch 'backport-85-to-stable2407'
git cherry-pick -x 164f1c6a4799a307be59dfc2ae9c298995a1e133
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

    git commit --allow-empty

Otherwise, please use 'git cherry-pick --skip'
git cherry-pick --abort
Backport failed for `stable2407`, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.
``bash
git fetch origin stable2407
git worktree add -d .worktree/backport-85-to-stable2407 origin/stable2407
cd .worktree/backport-85-to-stable2407
git switch --create backport-85-to-stable2407
git cherry-pick -x 164f1c6a4799a307be59dfc2ae9c[29](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:30)8995a1e133
``
Create comment: Backport failed for `stable2407`, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.
``bash
git fetch origin stable2407
git worktree add -d .worktree/backport-85-to-stable2407 origin/stable2407
cd .worktree/backport-85-to-stable2407
git switch --create backport-85-to-stable2407
git cherry-pick -x 164f1c6a4799a[30](https://github.com/ggwpez/debug/actions/runs/10595239845/job/29360562571#step:3:31)7be59dfc2ae9c298995a1e133
``

For future readers, this is the workflow that am currently using:

Details

name: Backport into stable

on:
  pull_request_target:
    types: [ closed, labeled ]
  issue_comment:
    types: [ created ]
permissions:
  contents: write # so it can comment
  pull-requests: write # so it can create pull requests
jobs:
  backport:
    name: Backport pull request
    runs-on: ubuntu-latest

    # Excluding CI action user id `97796249`:
    if: >
      ( !startsWith(github.event.pull_request.base.ref, 'stable') ) &&
      ((
        github.event_name == 'pull_request_target' &&
        github.event.pull_request.merged &&
        contains(github.event.pull_request.labels.*.name, 'A4-needs-backport')
      ) || (
        github.event_name == 'issue_comment' &&
        github.event.issue.pull_request &&
        github.event.comment.user.id != 97796249 &&
        (
          startsWith(github.event.comment.body, '/backport') ||
          contains(toJson(github.event.comment.body), '\n/backport')
        )
      ))
    steps:
      - uses: actions/checkout@v4
      - name: Create backport pull requests
        uses: korthout/backport-action@v3
        id: backport
        with:
          target_branches: stable2407 stable2410
          merge_commits: skip
          github_token: ${{ secrets.GITHUB_TOKEN }}
          pull_description: |
            Backport #${pull_number} into `${target_branch}` (cc @${pull_author}).

            <!--
              # To be used by other automation, do not modify:
              original-pr-number: #${pull_number}
            -->
          pull_title: |
            [${target_branch}] Backport #${pull_number}

      - if: ${{ steps.backport.outputs.created_pull_numbers != '' }}
        uses: actions/github-script@v7
        with:
          script: |
            const pullNumbers = '${{ steps.backport.outputs.created_pull_numbers }}'.split(' ');
            
            for (const pullNumber of pullNumbers) {
              await github.rest.issues.addLabels({
                issue_number: parseInt(pullNumber),
                owner: context.repo.owner,
                repo: context.repo.repo,
                labels: ['A3-backport']
              });
              console.log(`Added A3-backport label to PR #${pullNumber}`);
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request prio: next Planning to work on this issue next
Projects
None yet
Development

No branches or pull requests

2 participants