not able to properly keep staging up-to-date with development
Subject of the issue
Hi,
- We are trying to keep the staging branch up-to-date with development branch but everytime a PR is created against
stagingbranch it consists of commits that are already merged in thestagingbranch (which is super weird because the changed files in the PR show that it's gonna make changes that already exist in the upstreamstagingbranch) - we are following the docs here
Steps to reproduce
out github actions workflow:
create-pull-request:
if: github.event_name != 'pull_request'
runs-on:
- feature/generic
- size/xs
steps:
- uses: actions/checkout@v3
with:
ref: staging
- name: Reset branch
run: |
cd $GITHUB_WORKSPACE
git fetch origin development:development
git reset --hard development
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: '${{ steps.github-token.outputs.token }}'
commit-message: Updates from development branch into staging
committer: GitHub <[email protected]>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
signoff: false
branch: development-to-staging
delete-branch: false
title: '[Automated] Updates from development branch into staging'
body: |
Updates from development branch into staging
draft: false
- the above action will generate a PR against
stagingbranch with a new branch calleddevelopment-to-staging - but the PR shows changes which are already present in the
stagingbranch
basically when a PR is generated against staging branch with this action, we only want to see the new commits that don't exist in the staging branch
I've been digging more into this and I think what we want is a two-dot diff in the pull request instead of three-dot diff which is the default
- Thank you
Hi @balusarakesh
Perhaps the example in the docs doesn't work in all cases. It might be because commits on your staging branch are being force pushed and differ from development, but I'm not sure.
I don't know the answer for your particular case, but you can experiment and determine what works for you. The idea is to checkout staging and then modify the local workspace with your development changes.
These lines are making the local workspace match the current development branch. You can change these lines to a different way of updating the local workspace. Perhaps there is a way that suits your use case better. These commands can be experimented with on your local machine.
git fetch origin development:development
git reset --hard development
Let me know if you find a new way to perform this update. It could be useful for other users.
@peter-evans
- I got it to work (PARTIALLY)
- I replaced the above 2 git commands with the following and then I see
two-dotdiff when I compare branches in the pull request view in github:
- name: Rebase branch
run: |
cd $GITHUB_WORKSPACE
git checkout --track -b development origin/development
git reset --hard development
git config --global user.name ${{ github.actor }}
git config --global user.email ${{ github.actor }}
git rebase staging
git checkout -b dev-to-staging-test
git push -f origin dev-to-staging-test:dev-to-staging-test
But the problem is when I create a pull request with peter-evans/create-pull-request@v4 it completely wipes out the rebase operations I'm doing above and thinks there is no changes between the above pushed branch and staging branch like this:
Create or update the pull request branch
/usr/bin/git symbolic-ref HEAD --short
dev-to-staging-test
Working base is branch 'dev-to-staging-test'
/usr/bin/git checkout --progress -B ghktoam-1235-6532-f562-fb269954490e HEAD --
Switched to a new branch 'ghktoam-1235-6532-f562-fb269954490e'
/usr/bin/git status --porcelain -unormal --
/usr/bin/git diff --quiet --
/usr/bin/git diff --quiet --staged --
/usr/bin/git reset --hard
HEAD is now at bg5cv82 [Automated] Updates from development branch into staging (#45)
/usr/bin/git clean -f -d
Resetting working base branch 'dev-to-staging-test'
/usr/bin/git checkout --progress dev-to-staging-test --
Switched to branch 'dev-to-staging-test'
/usr/bin/git reset --hard origin/dev-to-staging-test
HEAD is now at bg5cv82 [Automated] Updates from development branch into staging (#45)
Rebasing commits made to branch 'dev-to-staging-test' on to base branch 'staging'
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force origin staging:staging
/usr/bin/git checkout --progress staging --
Switched to branch 'staging'
Your branch is up to date with 'origin/staging'.
/usr/bin/git rev-list --reverse dev-to-staging-test..ghktoam-1235-6532-f562-fb269954490e .
/usr/bin/git checkout --progress -B ghktoam-1235-6532-f562-fb269954490e HEAD --
Switched to and reset branch 'ghktoam-1235-6532-f562-fb269954490e'
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force origin staging:staging
/usr/bin/git -c protocol.version=2 fetch --no-tags --progress --no-recurse-submodules --force origin dev-to-staging-test:refs/remotes/origin/dev-to-staging-test
Pull request branch 'dev-to-staging-test' already exists as remote branch 'origin/dev-to-staging-test'
/usr/bin/git checkout --progress dev-to-staging-test --
Switched to branch 'dev-to-staging-test'
/usr/bin/git diff --quiet dev-to-staging-test..ghktoam-1235-6532-f562-fb269954490e
/usr/bin/git rev-list --right-only --count staging...ghktoam-1235-6532-f562-fb269954490e
0
Resetting 'dev-to-staging-test'
/usr/bin/git checkout --progress -B dev-to-staging-test ghktoam-1235-6532-f562-fb269954490e --
Reset branch 'dev-to-staging-test'
/usr/bin/git rev-list --right-only --count origin/dev-to-staging-test...dev-to-staging-test
0
/usr/bin/git rev-list --left-only --count origin/dev-to-staging-test...dev-to-staging-test
0
Branch 'dev-to-staging-test' is even with its remote and will not be updated
/usr/bin/git rev-list --right-only --count staging...dev-to-staging-test
0
/usr/bin/git rev-parse HEAD
bg5cv82d509110210e73969e3735d71ac8042a1b
/usr/bin/git branch --delete --force ghktoam-1235-6532-f562-fb269954490e
Deleted branch ghktoam-1235-6532-f562-fb269954490e (was bg5cv82).
Branch 'dev-to-staging-test' no longer differs from base branch 'staging'
is there an option to NOT do any kind of rebase in the github action peter-evans/create-pull-request@v4 and just create a PR between 2 existing branches??
is there an option to NOT do any kind of rebase in the github action peter-evans/create-pull-request@v4 and just create a PR between 2 existing branches??
No, because that's the main point of using this action. It does a lot of the hard work for you for the vast majority of use cases.
If you have an existing branch and just want to create a PR then I recommend just calling the GitHub API yourself with github-script.