-
Notifications
You must be signed in to change notification settings - Fork 1
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 Merge and Commit logic #75
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
f5dd3a2
to
ef0d9ed
Compare
src/autodev.ts
Outdated
await exec(`git merge origin/${pull.branch}`, undefined, { | ||
env: { | ||
GIT_COMMITTER_DATE: commitDate, | ||
GIT_AUTHOR_DATE: commitDate | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual commit is done a few lines below. (see git commit -m', [message]
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yes, you are right. Is there a particular reason why it is done this way? Why not just keep a number of merge commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A single commit with X merged branches is much easier to read and understand compared to X merge commits + commits that have been made in the branches (we're not using squash merge). For some large repos you have to read trough 2 pages of commits to understand what has been merged into dev.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's the goal to create the same commit hash, when the same branches have been merged, then it should be enough to just change the commit + author dates of the last commit. source
1a96a05
to
3fed51e
Compare
`git show -s --format='%ci' origin/${base}` | ||
) | ||
|
||
await exec(`git checkout ${base}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creation of new branch was moved to the end of logic. Its not yet needed, just start on the base branch
info('🎉 No Pull Requests found. Nothing to merge.') | ||
} | ||
return | ||
info('🎉 No Pull Requests found. Nothing to merge.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need anymore to duplicate the check for a diff here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I guess the return
is useful because the following steps doesn't make sense with no changes, or? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I would still go to the push, so when all pulls get the "dev" label removed, the autodev action will revert the dev branch to main
const message = optimistic | ||
? await merge(base, pulls, updateComment, updateLabel) | ||
: await mergeAll(pulls, updateComment, updateLabel) | ||
await exec(`git checkout -B ${branch}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create the new dev branch on the current commit (which is either $base
if no dev pulls exists, or the newly created merge commit)
|
||
// only push to defined branch if there are changes | ||
await exec('git fetch') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetch again. This reduces (though not completely eliminates) a race condition where another parallel invocation of the autodev action could result in having a inconsistent origin/dev ref
await exec('git push -f') | ||
// ignore any errors | ||
await exec('git push -f', undefined, { | ||
ignoreReturnCode: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command will still fail if run into the (earlier mentioned) race condition here. But in this case we can just ignore the failure (basically it means another invocation of the dev workflow beat us in pushing the same state)
}) | ||
|
||
return ret | ||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we produce reproducible commit hashes now, just compare them to see if the dev state changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The action fails now with this message
/usr/bin/git fetch
/usr/bin/git config --global user.email staffbot@staffbase.com
/usr/bin/git config --global user.name autodev-action
/usr/bin/git show -s --format='%ci' origin/main
'2022-06-03 13:55:05 +0200'
/usr/bin/git checkout main
Switched to a new branch 'main'
branch 'main' set up to track 'origin/main'.
/usr/bin/git merge origin/feature
Updating 94e3cc6..767c0a4
Fast-forward
README.md | 2 ++
1 file changed, 2 insertions(+)
/usr/bin/git reset origin/main
Unstaged changes after reset:
M README.md
/usr/bin/git add -A
/usr/bin/git commit -m AutoDev Merge
The following branches have been merged:
- feature
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident name (for <runner@fv-az39-531.yumyzuo2tp0ejekjjwodrrku4b.bx.internal.cloudapp.net>) not allowed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great improvement! 🎉
info('🎉 No Pull Requests found. Nothing to merge.') | ||
} | ||
return | ||
info('🎉 No Pull Requests found. Nothing to merge.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I guess the return
is useful because the following steps doesn't make sense with no changes, or? 🤔
You can use this example PR to reproduce the issue. As a first check can you can add the command to check the configuration: git config --global --list Otherwise I think we could add the information as environment variables. Or we could use the option |
d319bf7
to
146d385
Compare
9c15d8b
to
c797fa8
Compare
I am not sure what the exact reason is for the original issue, however it seems to work when I set the git config locally. |
Looks really good, but my local changes differ from the npm run all And I think we missed something else. fatal: The current branch dev has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin dev |
2e1195f
to
181a6db
Compare
I resolved the issue now, and did some real tests with an own repository:
|
overrideDate | ||
) | ||
const rev = await execAndSlurp('git rev-parse HEAD') | ||
await exec(`git checkout replace/${rev}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is normal and we can't prevent it?
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:git switch -c
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I don't know what I do differently, but when I run npm run all
, I have differences again?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is normal and we can't prevent it?
You mean the message? I don't think so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I don't know what I do differently, but when I run
npm run all
, I have differences again?!
I guess the result of npm run all
is not exactly reproducible,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a rebase now, removed yarn.lock
, ran yarn
again and then reran npm run all
. Hope this result is now reproducible on your end
It is never used, and just add unnecessary complexity
181a6db
to
ef96d46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for me now.
The action now adds all commits of all merged pull requests to the commit history on the dev-branch. It doesn't hurt, but is this really necessary? I rarely check this commit history and only check out the "squash" commit at the end to understand which branches have been combined.
A "squash" option would be cool :)
Type of Change
Description
Checklist