Using Git Hooks to Help Your 40 40 40 Joo Santos Engineering - - PowerPoint PPT Presentation

using git hooks to help your
SMART_READER_LITE
LIVE PREVIEW

Using Git Hooks to Help Your 40 40 40 Joo Santos Engineering - - PowerPoint PPT Presentation

255 105 0 149 149 149 225 225 225 68 84 106 84 28 0 0 0 153 65 0 102 Using Git Hooks to Help Your 40 40 40 Joo Santos Engineering Teams Work Software Engineer joao.santos@zalando.de Autonomously @joaomcsantos Europython 2015


slide-1
SLIDE 1

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Using Git Hooks to Help Your Engineering Teams Work Autonomously

Europython 2015 João Santos Software Engineer joao.santos@zalando.de @joaomcsantos

slide-2
SLIDE 2

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Quick Facts About Zalando Tech

  • Tech HQ in Berlin
  • Other tech offices in Dublin, Helsinki, Dortmund,

Mönchengladbach, Erfurt

  • +700 technologists
  • Nearly everything produced in-house
slide-3
SLIDE 3

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Why?

Why do we need hooks and rules?

slide-4
SLIDE 4

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

How?

How should the rules be enforced?

slide-5
SLIDE 5

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Dark Ages of SVN

slide-6
SLIDE 6

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Dark Ages of SVN

  • Bash script
slide-7
SLIDE 7

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Dark Ages of SVN

  • Bash script
  • Python Hook
slide-8
SLIDE 8

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook

slide-9
SLIDE 9

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - First Plan

  • A common code base for git and svn
slide-10
SLIDE 10

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - First Plan

  • A common code base for git and svn
  • Pre-receive hook
slide-11
SLIDE 11

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - First Feedback

  • Git is not SVN
slide-12
SLIDE 12

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - First Feedback

  • Git is not SVN
  • People don't use Git the same way
slide-13
SLIDE 13

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Plan B

  • A dedicated hook for Git
slide-14
SLIDE 14

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Plan B

  • A dedicated hook for Git
  • Allow teams to tailor the hooks to their needs
slide-15
SLIDE 15

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Customization

"*playground-*": check_from: 9999-01-01T00:00 TEAM1/*: check_from: 2014-01-08T00:00 allowed_projects: [PROJECT1] extra_on_push: [jira.fix_version] merge_to_feature: [live, master] TEAM1/repository42: allowed_projects: [PROJECT1, PROJECT2] TEAM2/*: allowed_projects: [PROJECT3] check_from: 2014-03-31T12:30 disable_on_push: [git.is_feature_or_bugfix_branch]

slide-16
SLIDE 16

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Problems

  • Centralized configuration
slide-17
SLIDE 17

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Problems

  • Centralized configuration
  • Trying to check commits on a push
slide-18
SLIDE 18

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Problems

  • Centralized configuration
  • Trying to check commits on a push
  • 1. Git history is not linear
slide-19
SLIDE 19

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Problems

  • Centralized configuration
  • Trying to check commits on a push
  • 1. Git history is not linear
  • 2. Merging to/from a long lived branch
slide-20
SLIDE 20

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Problems

  • Centralized configuration
  • Trying to check commits on a push
  • 1. Git history is not linear
  • 2. Merging to/from a long lived branch
  • Checking code style is slow
slide-21
SLIDE 21

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Problems

  • Centralized configuration
  • Trying to check commits on a push
  • 1. Git history is not linear
  • 2. Merging to/from a long lived branch
  • Checking code style is slow
  • Inflexible
slide-22
SLIDE 22

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Git Hook - Problems

  • Centralizing Git
slide-23
SLIDE 23

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of Autonomy

slide-24
SLIDE 24

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Autonomy

  • Local git hooks
slide-25
SLIDE 25

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Autonomy

  • Local git hooks
  • Optional, a helper not a blocker
slide-26
SLIDE 26

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Autonomy

  • Local git hooks
  • Optional, a helper not a blocker
  • Extensible, one size doesn't fit all
slide-27
SLIDE 27

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Autonomy

  • Local git hooks
  • Optional, a helper not a blocker
  • Extensible, one size doesn't fit all
  • Open Source
slide-28
SLIDE 28

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

The Age of the Autonomy - Turnstile https://github.com/zalando/turnstile https://pypi.python.org/pypi/turnstile-core

slide-29
SLIDE 29

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

$ pip install turnstile-core Turnstile - How to install it

slide-30
SLIDE 30

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Turnstile - How to use it

  • Add a .turnstile.yml file to your repository
slide-31
SLIDE 31

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Turnstile - How to use it

  • Add a .turnstile.yml file to your repository

checks:

  • specification
  • branch-release
  • protect-master

specification: allowed_schemes: ['https'] branch-release: pattern: '^v(?:\d|\_|\.)+$'

slide-32
SLIDE 32

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Turnstile - How to use it

  • Add a .turnstile.yml file to your repository
  • Install the hooks on your repository:

$ turnstile install

slide-33
SLIDE 33

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Turnstile - More than a hook

  • Core subcommands:

○ config ○ install ○ remove ○ specification ○ upgrade ○ version

slide-34
SLIDE 34

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Turnstile - Extending Turnstile

setup( name='turnstile-codevalidator', ... entry_points={ 'turnstile.commands': ['codevalidator = turnstile_cv.command'], 'turnstile.pre_commit': ['codevalidator = turnstile_cv.check']})

slide-35
SLIDE 35

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Turnstile - Extending Turnstile

  • Entry points

○ turnstile.commands ○ turnstile.commit_msg ○ turnstile.pre_commit

slide-36
SLIDE 36

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

What we learned

  • Don't get stuck in the past
slide-37
SLIDE 37

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

What we learned

  • Don't get stuck in the past
  • Develop in the open
slide-38
SLIDE 38

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

What we learned

  • Don't get stuck in the past
  • Develop in the open
  • Build tools not barriers
slide-39
SLIDE 39

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Ask Questions

https://pypi.python.org/pypi/turnstile-core https://github.com/zalando/turnstile https://turnstile.readthedocs.org @joaomcsantos

slide-40
SLIDE 40

255 105 0 225 225 225 149 149 149 68 84 106 0 0 153 65 0 102 84 28 0 40 40 40

Where to Find Us:

Tech Blog: tech.zalando.com GitHub: github.com/zalando Twitter: @ZalandoTech Instagram: zalandotech Jobs: http://tech.zalando.com/jobs