peter-evans / create-pull-request

A GitHub action to create a pull request for changes to your repository in the actions workspace
MIT License
2.14k stars 422 forks source link

Cant create pull request in remote repository with "remote" changes #990

Closed oliverabclabs closed 2 years ago

oliverabclabs commented 2 years ago

Subject of the issue

From my backend repo I push changes to the frontend repo using another action. This works fine. But I cannot seem to create a PR using this action from that branch. I assume this is because the changes are not local, they only exist remotely in the feature branch-111. Shouldnt it be possible to create a PR then?

I get:

Branch 'branch-111' no longer differs from base branch 'dev'

In short: I want to create a PR in a remote repository from a branch 'branch-111' to dev and they already differ.

Steps to reproduce

I have the following workflow snippet in backend repo (code is obfuscated for privacy reasons)

      - name: Pushes types to 
        uses: foobar/copy_file_to_another_repo_action@main
        env:
          API_TOKEN_GITHUB: ${{ secrets.PAT }}
        with:
          source_file: 'dist/dto-type-declarations.ts'
          destination_repo: 'foobar/frontendrepo'
          destination_folder: 'src/models'
          destination_branch_create: 'branch-111'
          destination_branch_create_origin: 'dev'
          user_email: 'bot@github.action'
          user_name: 'github_bot'
          commit_message: 'Backend Push Event'

      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          repository: foobar/frontendrepo
          ref: branch-111
          path: blablabla

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          branch: branch-111
          base: dev
          title: 'Blabla'
          body: |
            Blbal
            - Blabla
          labels: |
            automated pr
          draft: true
          path: blablabla

Any help is very much appreciated!

peter-evans commented 2 years ago

Hi @oliverabclabs

This action can create pull requests in remote repositories without you needing to commit to the remote repository first.

      # Checkout the remote repo with a `repo` scoped PAT
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.PAT }}
          repository: owner/repo
          ref: dev

      # Make changes to pull request here

      - uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.PAT }}
          branch: branch-111

To make the changes what I would recommend is to create an artifact of dist/dto-type-declarations.ts using upload-artifact. You can do this in a prerequisite job to the job where you create the pull request. Then in the second job where you create the pull request, use download-artifact to place the file exactly where you want it in the remote repo file structure.

AraHaan commented 2 years ago

Don't need to even do that, if on windows one can use robocopy to copy the file into the destination folder in the other repository, or if on any other OS than windows you can copy it using cp. The cp option could work for windows as well though.

AraHaan commented 2 years ago

Hi @oliverabclabs

This action can create pull requests in remote repositories without you needing to commit to the remote repository first.

      # Checkout the remote repo with a `repo` scoped PAT
      - uses: actions/checkout@v2
        with:
          token: ${{ secrets.PAT }}
          repository: owner/repo
          ref: dev

      # Make changes to pull request here

      - uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.PAT }}
          branch: branch-111

To make the changes what I would recommend is to create an artifact of dist/dto-type-declarations.ts using upload-artifact. You can do this in a prerequisite job to the job where you create the pull request. Then in the second job where you create the pull request, use download-artifact to place the file exactly where you want it in the remote repo file structure.

@peter-evans what if the repo is a public one, we we skip the PAT then?

peter-evans commented 2 years ago

@AraHaan No, you still need a PAT for public repos in the scenario I described, but I think you can use the public_repo scope instead of repo.

lucashimizu commented 2 years ago

Branch 'branch-111' no longer differs from base branch 'dev'

Any ideas on why this is happening? I'm facing the exact same issue.

AraHaan commented 2 years ago

To make the changes what I would recommend is to create an artifact of dist/dto-type-declarations.ts using upload-artifact. You can do this in a prerequisite job to the job where you create the pull request. Then in the second job where you create the pull request, use download-artifact to place the file exactly where you want it in the remote repo file structure.

I can bypass this with msbuild's Copy and Delete tasks so that way older unneeded files get deleted where only the newest versions get copied. For my cases I needed this to copy msi/exe windows installers, macos installation bundles (*.pkg), and even linux bundles as well (tar.gz of the files that would have made it into an installer) (where it will commit them to that repository).

peter-evans commented 2 years ago

Hi @lucashimizu

Branch 'branch-111' no longer differs from base branch 'dev'

Any ideas on why this is happening? I'm facing the exact same issue.

This is not an "issue," it's part of the normal operation of the action. If it's not what you expect to happen then it's likely that you need to make some changes to your workflow and/or the way you are using the action for the use case you have. If you need some help then please make a new issue describing your use case and showing the workflow you have tried.

peter-evans commented 2 years ago

I'll close this issue for now because it's getting a bit off-topic.