GithubHelp home page GithubHelp logo

Comments (4)

dsyme avatar dsyme commented on June 13, 2024

The action is nothing surprising, but actually looking at it now perhaps I should be using git pull rather than git merge

name: Auto-prepare a PR from update to main
on:
  push:
    branches:
      - update

jobs:
  create-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: main
          fetch-depth: 0
      - name: Merge update branch into main
        run: |
          git fetch origin update
          git merge origin/update
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v5
        with:
          branch: integrate/update-to-main
          title: "Merge update into main"
          body: "This is an automated pull request to update the main branch with the latest changes from update."
          delete-branch: true

from create-pull-request.

peter-evans avatar peter-evans commented on June 13, 2024

Hi @dsyme

Please take a look at this example. I think this is what you are trying to do.
https://github.com/peter-evans/create-pull-request/blob/main/docs/examples.md#keep-a-branch-up-to-date-with-another

I don't think using merge is going to work.

from create-pull-request.

dsyme avatar dsyme commented on June 13, 2024

Thanks! My scenario is a little different - we have two branches production and main but allow changes to flow into both (e.g. hotfixes into production and normal dev work into main). I'm using this action to automate the PRs for the integrations between the two.

The problem is that merge commits always appear - and this really stems from the fact that the GitHub UI doesn't support PRs that are fast-forward merges, so the act of merging a PR always leaves a merge commit, squash or rebase of some kind in the commit history. This means that you end up with an endless infinite ping pong of empty merge commits between the two branches.

I found a workaround which is like this. But I do wonder if this could be the default behaviour.

Thank you for the GH action btw, it's very useful!

jobs:
  create-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: production
          fetch-depth: 0
      - name: Promote main to production
        run: |
          git config --global pull.ff only
          git config --global user.email "..."
          git config --global user.name "..."
          git fetch origin
          # Check if there are any actual code differences between the two branches. If so, merge 
          # the main branch into production. If not, do nothing, which will not result in creation of a PR.
          # This prevents PRs being created when there are no actual code changes only merge commits
          if git diff --quiet origin/production...origin/main; then
            echo "production branch already includes everything from main branch"
          else
            git merge origin/main
          fi
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v5
        with:
          branch: integrate/main-to-production
          title: "[Release] Promote main to production"
          delete-branch: true

from create-pull-request.

peter-evans avatar peter-evans commented on June 13, 2024

Maybe to avoid the merge commits you could try this in your workflow:

  1. checkout production
  2. fetch main (origin)
  3. create a new local branch on the HEAD of production called temp-merge, for example
  4. merge origin/main into temp-merge
  5. checkout production again (this part is like the example I linked, but we don't need to fetch because temp-merge is already available locally)
  6. do git reset --hard temp-merge
  7. run create-pull-request

Apologies if I misunderstood and this doesn't work. 😄

from create-pull-request.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.