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 João Santos Engineering Teams Work Software Engineer joao.santos@zalando.de Autonomously @joaomcsantos Europython 2015
255 105 0 149 149 149 Quick Facts About Zalando Tech 225 225 225 68 84 106 ● Tech HQ in Berlin 84 28 0 0 0 153 ● Other tech offices in Dublin, Helsinki, Dortmund, 65 0 102 Mönchengladbach, Erfurt ● +700 technologists 40 40 40 ● Nearly everything produced in-house
255 105 0 149 149 149 225 225 225 68 84 106 84 28 0 Why? 0 0 153 65 0 102 40 40 40 Why do we need hooks and rules?
255 105 0 149 149 149 225 225 225 68 84 106 84 28 0 How? 0 0 153 65 0 102 40 40 40 How should the rules be enforced?
255 105 0 149 149 149 225 225 225 68 84 106 Dark Ages of 84 28 0 0 0 153 65 0 102 SVN 40 40 40
255 105 0 Dark Ages of SVN 149 149 149 225 225 225 68 84 106 ● Bash script 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 Dark Ages of SVN 149 149 149 225 225 225 68 84 106 ● Bash script 84 28 0 0 0 153 ● Python Hook 65 0 102 40 40 40
255 105 0 149 149 149 225 225 225 68 84 106 The Age of the 84 28 0 0 0 153 65 0 102 Git Hook 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - First Plan 225 225 225 68 84 106 ● A common code base for git and svn 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - First Plan 225 225 225 68 84 106 ● A common code base for git and svn 84 28 0 0 0 153 ● Pre-receive hook 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - First Feedback 225 225 225 68 84 106 ● Git is not SVN 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - First Feedback 225 225 225 68 84 106 ● Git is not SVN 84 28 0 0 0 153 ● People don't use Git the same way 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - Plan B 225 225 225 68 84 106 ● A dedicated hook for Git 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - Plan B 225 225 225 68 84 106 ● A dedicated hook for Git 84 28 0 0 0 153 ● Allow teams to tailor the hooks to their needs 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - Customization 225 225 225 68 84 106 "*playground-*": 84 28 0 check_from: 9999-01-01T00:00 0 0 153 TEAM1/*: 65 0 102 check_from: 2014-01-08T00:00 allowed_projects: [PROJECT1] extra_on_push: [jira.fix_version] 40 40 40 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]
255 105 0 149 149 149 The Age of the Git Hook - Problems 225 225 225 68 84 106 ● Centralized configuration 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - Problems 225 225 225 68 84 106 ● Centralized configuration 84 28 0 0 0 153 ● Trying to check commits on a push 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - Problems 225 225 225 68 84 106 ● Centralized configuration 84 28 0 0 0 153 ● Trying to check commits on a push 65 0 102 1. Git history is not linear 40 40 40
255 105 0 149 149 149 The Age of the Git Hook - Problems 225 225 225 68 84 106 ● Centralized configuration 84 28 0 0 0 153 ● Trying to check commits on a push 65 0 102 1. Git history is not linear 40 40 40 2. Merging to/from a long lived branch
255 105 0 149 149 149 The Age of the Git Hook - Problems 225 225 225 68 84 106 ● Centralized configuration 84 28 0 0 0 153 ● Trying to check commits on a push 65 0 102 1. Git history is not linear 40 40 40 2. Merging to/from a long lived branch ● Checking code style is slow
255 105 0 149 149 149 The Age of the Git Hook - Problems 225 225 225 68 84 106 ● Centralized configuration 84 28 0 0 0 153 ● Trying to check commits on a push 65 0 102 1. Git history is not linear 40 40 40 2. Merging to/from a long lived branch ● Checking code style is slow ● Inflexible
255 105 0 149 149 149 The Age of the Git Hook - Problems 225 225 225 68 84 106 ● Centralizing Git 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 225 225 225 68 84 106 The Age of 84 28 0 0 0 153 65 0 102 Autonomy 40 40 40
255 105 0 149 149 149 The Age of the Autonomy 225 225 225 68 84 106 ● Local git hooks 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Autonomy 225 225 225 68 84 106 ● Local git hooks 84 28 0 0 0 153 ● Optional, a helper not a blocker 65 0 102 40 40 40
255 105 0 149 149 149 The Age of the Autonomy 225 225 225 68 84 106 ● Local git hooks 84 28 0 0 0 153 ● Optional, a helper not a blocker 65 0 102 ● Extensible, one size doesn't fit all 40 40 40
255 105 0 149 149 149 The Age of the Autonomy 225 225 225 68 84 106 ● Local git hooks 84 28 0 0 0 153 ● Optional, a helper not a blocker 65 0 102 ● Extensible, one size doesn't fit all 40 40 40 ● Open Source
255 105 0 149 149 149 The Age of the Autonomy - Turnstile 225 225 225 68 84 106 https://github.com/zalando/turnstile 84 28 0 0 0 153 65 0 102 https://pypi.python.org/pypi/turnstile-core 40 40 40
255 105 0 149 149 149 Turnstile - How to install it 225 225 225 68 84 106 $ pip install turnstile-core 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 Turnstile - How to use it 225 225 225 68 84 106 ● Add a .turnstile.yml file to your repository 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 Turnstile - How to use it 225 225 225 68 84 106 ● Add a .turnstile.yml file to your repository 84 28 0 0 0 153 65 0 102 checks: - specification - branch-release 40 40 40 - protect-master specification: allowed_schemes: ['https'] branch-release: pattern: '^v(?:\d|\_|\.)+$'
255 105 0 149 149 149 Turnstile - How to use it 225 225 225 68 84 106 ● Add a .turnstile.yml file to your repository 84 28 0 0 0 153 ● Install the hooks on your repository: 65 0 102 $ turnstile install 40 40 40
255 105 0 149 149 149 Turnstile - More than a hook 225 225 225 68 84 106 ● Core subcommands: 84 28 0 ○ config 0 0 153 65 0 102 ○ install ○ remove 40 40 40 ○ specification ○ upgrade ○ version
255 105 0 149 149 149 Turnstile - Extending Turnstile 225 225 225 68 84 106 84 28 0 setup( 0 0 153 name='turnstile-codevalidator', 65 0 102 ... entry_points={ 40 40 40 'turnstile.commands': ['codevalidator = turnstile_cv.command'], 'turnstile.pre_commit': ['codevalidator = turnstile_cv.check']})
255 105 0 149 149 149 Turnstile - Extending Turnstile 225 225 225 68 84 106 ● Entry points 84 28 0 0 0 153 ○ turnstile.commands 65 0 102 ○ turnstile.commit_msg 40 40 40 ○ turnstile.pre_commit
255 105 0 149 149 149 What we learned 225 225 225 68 84 106 ● Don't get stuck in the past 84 28 0 0 0 153 65 0 102 40 40 40
255 105 0 149 149 149 What we learned 225 225 225 68 84 106 ● Don't get stuck in the past 84 28 0 0 0 153 ● Develop in the open 65 0 102 40 40 40
255 105 0 149 149 149 What we learned 225 225 225 68 84 106 ● Don't get stuck in the past 84 28 0 0 0 153 ● Develop in the open 65 0 102 ● Build tools not barriers 40 40 40
255 105 0 Ask Questions 149 149 149 225 225 225 68 84 106 84 28 0 https://pypi.python.org/pypi/turnstile-core 0 0 153 65 0 102 https://github.com/zalando/turnstile 40 40 40 https://turnstile.readthedocs.org @joaomcsantos
255 105 0 149 149 149 Where to Find Us: 225 225 225 68 84 106 Tech Blog: tech.zalando.com 84 28 0 0 0 153 GitHub: github.com/zalando 65 0 102 Twitter: @ZalandoTech 40 40 40 Instagram: zalandotech Jobs: http://tech.zalando.com/jobs
Recommend
More recommend