"Git Hooked!" Using Git hooks to improve your software development process

28
Milton Bryant DevOps Lead for Polished Geek Git Hooked!

description

Famous last words: "Works for me!" Sometimes, even though code works for you, when you push it to the remote repository or install it on the production site, suddenly you're faced with pesky errors that escaped the testing process. The later bugs are found during development, the more expensive a project becomes in terms of time, frustration, and money. One way to improve your code quality is to use automated testing with Git hooks. In this session, Milton Bryant will walk you through some practical applications of automated testing using Git hooks. He'll demonstrate how to get Git hooks working with existing PHPUnit tests, to allow you to test your code as you commit it. Presented at the Joomla World Conference 2014 in Cancun, Mexico - November 7, 2014

Transcript of "Git Hooked!" Using Git hooks to improve your software development process

Page 1: "Git Hooked!" Using Git hooks to improve your software development process

Milton BryantDevOps Lead

for Polished Geek

GitHooked!

Page 2: "Git Hooked!" Using Git hooks to improve your software development process

Milton BryantDevOps Lead at Polished Geek

Working with Joomla since 2010

Email - [email protected]

Twitter - @Krealic

Page 3: "Git Hooked!" Using Git hooks to improve your software development process

What hooks are &

how to use them

Page 4: "Git Hooked!" Using Git hooks to improve your software development process

Demo #1

Triggering unit test(s) with pre-commit git hook

Page 5: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

Page 6: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

CheckoutRebase

post-checkoutpre-rebase

Merge

post-merge

Page 7: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

pre-commitcode validationunit testscheck for missing files

If fail, aborts with message and no commit

Page 8: "Git Hooked!" Using Git hooks to improve your software development process

Alert you to merge conflict code inside of files

Page 9: "Git Hooked!" Using Git hooks to improve your software development process

Execute Scripts

Page 10: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

prepare-commit-msgedit pre-defined template messages

Page 11: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

commit-msgruns during commituse to ensure standards followed

Example: abort commit if JIRA issue resolution comments missing

Page 12: "Git Hooked!" Using Git hooks to improve your software development process

Send a pre-defined message or enforce commit signature policy

Page 13: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

post-commitruns only after successful commituse for notifications

Page 14: "Git Hooked!" Using Git hooks to improve your software development process

Notify users when commits or pushes have been made

Page 15: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

pre-receiveenforce dev policies

can reject entire push

Page 16: "Git Hooked!" Using Git hooks to improve your software development process

Generate/update ticket or issue under related project

Page 17: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

updateexecutes per branch

updatedPass/Fail per branch

updated

“mini-pre-receive”

Page 18: "Git Hooked!" Using Git hooks to improve your software development process

Changes to

CommitCommit Push Repo

Update

Local Remote

pre-commit

prepare-commit-msg

commit-msg

post-commit

pre-receive

update

post-receive

post-receiveteam notifications

continuous integration

only runs after successful update

Page 19: "Git Hooked!" Using Git hooks to improve your software development process

Build Log Files

Page 20: "Git Hooked!" Using Git hooks to improve your software development process

Relocate Files

Page 21: "Git Hooked!" Using Git hooks to improve your software development process

Demo #2Sending a notification to Slack with the post-commit git hook

Page 22: "Git Hooked!" Using Git hooks to improve your software development process

Top 5 Tips

Page 23: "Git Hooked!" Using Git hooks to improve your software development process

Tip #1By default, git hooks are not shared to the remote repository.

Page 24: "Git Hooked!" Using Git hooks to improve your software development process

Tip #2You can create a symbolic link from a “hooks” directory

Page 25: "Git Hooked!" Using Git hooks to improve your software development process

Tip #3If responses flicker too fast on the screen, pool them to a file.

Page 26: "Git Hooked!" Using Git hooks to improve your software development process

Tip #4It is possible to bypass hooks by using --no-verify, --no-merge or –no-checkout

Page 27: "Git Hooked!" Using Git hooks to improve your software development process

Tip #5With git hooks, you can…

Page 28: "Git Hooked!" Using Git hooks to improve your software development process

Milton BryantDevOps Lead

[email protected]@KrealicPolishedGeek.com @PolishedGeek

Slides available online https://PolishedGeek.com/githooked

??? ??