Resolve PR conflicts in an action?

One of my actions creates a branch, modifies some files on in, commits the changes and creates a PR to a target branch.

The PR has conflicts with the target branch. I want to ignore the conflicts and use the contents in the source branch, not the target branch.

Can I do it from an action?

There are two places I would see it possible, but I am unsure if it is doable at all:

  • in the action that creates the PR, create PR and indicate how conflicts should be resolved (but I found no option for that)
  • create a new action that triggers when PR is created and resolves conflicts there (I would think this is the best approach, but I have no idea about what git magic or github api to use)

Any help will be greatly appreciated, thanks!

It is a limitation that workflow is not triggered for ‘pull_request’ event if conflicts exist. Sorry about that!

There is a similar topic that discusses this: Run actions on Pull Requests with merge conflicts

We really appreciate feedback on how we can make GitHub even better and the best way to report any feature requests is directly to us through our feedback form: https://support.github.com/contact/feedback

Our roadmap is not publicly visible, so we recommend that you keep an eye on the GitHub Blog for the latest announcements about new features.

I have 2 workflow file.
One is test.xml and other is merge.xml

The test.xml run php unit test and if the test successful it will create a pull request to staging branch (the test.xml run in feature branch).

The strange is, if the pull request have conflict, the merge.xml workflow will not triggered. But when the pull request don’t have any conflict, it will run and merge the pull request. Did my xmls are misconfiguration?

Here is the xmls.

Test.xml

name: Test
on:
  push:
    branches-ignore:
      - staging
jobs:
  run-test:
    runs-on: self-hosted
    steps:
       - name: run test
  pullrequest-to-staging:
    needs: [run-test]
    runs-on: self-hosted
    steps:
      - name: Checkout current branch
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Create Pull Request to staging
        uses: repo-sync/pull-request@v2
        with:
          github_token: ${{ secrets.BOT_TOKEN }}
          pr_title: "Pulling ${{ steps.branch_name.outputs.branch }} into staging"
          pr_body: ":crown: *An automated PR*"
          destination_branch: "staging"
          pr_label: "automerge"

merge.xml

name: merge-to-staging
on:
  pull_request:
    branches:
      - staging
jobs:
  merge-to-staging:
    runs-on: self-hosted
    steps:
      - name: Label merge conflicts
        uses: eps1lon/actions-label-merge-conflict@v2.0.0
        with:
          repoToken: "${{ secrets.BOT_TOKEN }}"
          dirtyLabel: "conflicts"
          continueOnMissingPermissions: true
      - name: Merge to staging
        uses: pascalgn/automerge-action@v0.12.0
        env:
          GITHUB_TOKEN: "${{ secrets.BOT_TOKEN }}"