Skip to content
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

Merged
merged 9 commits into from
Jun 20, 2022
Merged

Improve Merge and Commit logic #75

merged 9 commits into from
Jun 20, 2022

Conversation

Stummi
Copy link
Contributor

@Stummi Stummi commented Jun 1, 2022

Type of Change

  • Bugfix
  • Enhancement / new feature
  • Refactoring
  • Documentation

Description

  • Create reproducible commit hashes by using a fixed date/time for the merge commit
  • Remove optimistic option (It is never actually used, and adds unnecessary complexity)
  • Preserve parent refs for dev merge commit
  • Replace hasDiff logic with a comparison on commit hashes

Checklist

  • Write tests
  • Make sure all tests pass
  • Update documentation
  • Review the Contributing Guideline and sign CLA
  • Reference relevant issue(s) and close them after merging

@github-actions
Copy link

github-actions bot commented Jun 1, 2022

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@Stummi
Copy link
Contributor Author

Stummi commented Jun 1, 2022

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jun 1, 2022
@Stummi Stummi force-pushed the various-improvements branch 3 times, most recently from f5dd3a2 to ef0d9ed Compare June 1, 2022 10:11
src/autodev.ts Outdated
Comment on lines 132 to 137
await exec(`git merge origin/${pull.branch}`, undefined, {
env: {
GIT_COMMITTER_DATE: commitDate,
GIT_AUTHOR_DATE: commitDate
}
})
Copy link
Contributor

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])

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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

@Stummi Stummi force-pushed the various-improvements branch 7 times, most recently from 1a96a05 to 3fed51e Compare June 2, 2022 09:32
@Stummi Stummi changed the title Use fixed commit date to produce reproducible dev states Improve Merge and Commit logic Jun 2, 2022
`git show -s --format='%ci' origin/${base}`
)

await exec(`git checkout ${base}`)
Copy link
Contributor Author

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.')
Copy link
Contributor Author

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

Copy link
Contributor

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? 🤔

Copy link
Contributor Author

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}`)
Copy link
Contributor Author

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')
Copy link
Contributor Author

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
Copy link
Contributor Author

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 (
Copy link
Contributor Author

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

Copy link
Contributor

@staffbase-robert staffbase-robert left a 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

Copy link
Contributor

@flaxel flaxel left a 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.')
Copy link
Contributor

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? 🤔

@flaxel
Copy link
Contributor

flaxel commented Jun 3, 2022

The action fails now with this message

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 --reset-author.

@Stummi Stummi force-pushed the various-improvements branch 2 times, most recently from d319bf7 to 146d385 Compare June 10, 2022 11:31
@Stummi Stummi force-pushed the various-improvements branch 4 times, most recently from 9c15d8b to c797fa8 Compare June 13, 2022 11:29
@Stummi
Copy link
Contributor Author

Stummi commented Jun 13, 2022

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.

src/autodev.ts Show resolved Hide resolved
@flaxel
Copy link
Contributor

flaxel commented Jun 13, 2022

Looks really good, but my local changes differ from the dist folder. Could you run the command again?

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

@Stummi Stummi force-pushed the various-improvements branch 4 times, most recently from 2e1195f to 181a6db Compare June 15, 2022 06:28
@Stummi
Copy link
Contributor Author

Stummi commented Jun 15, 2022

I resolved the issue now, and did some real tests with an own repository:

  • Merge commit does work as expected
  • Reproducible Commit hashes do work now

overrideDate
)
const rev = await execAndSlurp('git rev-parse HEAD')
await exec(`git checkout replace/${rev}`)
Copy link
Contributor

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

Copy link
Contributor

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?!

Copy link
Contributor Author

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

Copy link
Contributor Author

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,

Copy link
Contributor Author

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

Copy link
Contributor

@staffbase-robert staffbase-robert left a 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 :)

@Stummi Stummi merged commit 2df605a into main Jun 20, 2022
@Stummi Stummi deleted the various-improvements branch June 20, 2022 10:39
@github-actions github-actions bot locked and limited conversation to collaborators Jun 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants