git and gerrit workflowslive.wandisco.com › defauw_git-gerrit_workflows_live2014.pdf · –...

46
Git and Gerrit Workflows Enforcing Manual & Automated Review

Upload: others

Post on 26-Jun-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Git and Gerrit Workflows

Enforcing Manual & Automated Review

Page 2: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

•  Branching and Workflow Review •  A Look at Gerrit •  The Gerrit Workflow •  Other Workflows •  Customizing Gerrit Workflow

Agenda

Page 3: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Branching and Workflow Basics

Page 4: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Branches  represent  divergence.  They  confuse  developers.  They  add  complexity.  

Page 5: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

So  why  make  a  branch?  

Page 6: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Maintain  related  sets  of  work  –  Isolate  unstable  or  custom  code  

trunk

feature

Page 7: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Maintain  related  sets  of  work  –  Work  on  older  releases  

trunk

rel-1.1

Page 8: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Branches  Have…  DuraDon  

trunk

feature Promote  and  

reDre  

Page 9: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Branches  Have…  Stability  

trunk

feature

rel-1.1

More  stable  

Less  stable  

Page 10: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Branches  Have…  Flow  of  Change  

trunk

feature

rel-1.1

Merge  down  

Promote  up  

Page 11: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Simple  to  Complex  

trunk feature

sandbox

rel

patch

custom

Page 12: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Workflow  Guides  the  Flow  of  Change  

trunk

task branch

svn merge git merge

Page 13: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

A Look at Gerrit

Page 14: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Origins

Mondrian!

Rietveld!

Perforce-­‐centric  Google  internal  

Open  source  Subversion  

Android  ecosystem  Vibrant  community  

Page 15: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Community

User  Conferences  Hackathons  

Sponsors  Contributors  

Qualcomm  Motorola  Google  SAP  

SpoDfy  Yahoo  Nvidia  Samsung  

Page 16: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Repository Management

Key Features

Code Review

Access Control

Page 17: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Repository Management

Key Features

Code Review

Access Control

Repo  creaDon  HTTPS/SSH  

Page 18: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Repository Management

Key Features

Code Review

Access Control

Hierarchical  model  Granular  permissions  

LDAP  &  others  

Page 19: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Gerrit Workflow

Page 20: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

The Gerrit Model

•  Unreviewed  changes  isolated  

•  CI  built  into  workflow  

Page 21: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Android

•  ‘Repo’  coordinates  300+  repos  

•  Isolates  patch  authors  from  commi\ers  

•  Otherwise  not  as  bad  as  it  looks  

Page 22: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

•  All changes are reviewed •  Dynamic review branches •  Review IDs group serial work •  Human voting •  Enforce CI on every commit

– Build system gets a vote!

Key Principles

Page 23: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Steps

Clone  • Gerrit  has  unusual  URLs  •  Should  clone  change-­‐id  hook  

Push  • Use  special  review  ref  •  Can  amend  exisDng  review  

Review  •  +1  to  like,  +2  to  approve  •  Build  result  

Submit  • Merge  through  UI  •  Commit  to  branch  

Page 24: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

•  Web UI •  CLI / API •  Download patch •  Voting rights based on access control

– +/- 1 – +/- 2 – Verify

Review Options

Page 25: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Check  out  original  commit  

Amend  commit  with  new  work  

Push  again  

Rework

Each  change  has  a  unique  

ID  

All  amendments  preserved  as  patch  sets  

Page 26: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

•  Even rejected changes are valuable •  Comments are often as important as the

code •  Can enforce ‘signed off by’

Etiquette

Page 27: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

•  Best to see it in action •  Find a demo station

This is weird

Page 28: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Other Git Workflows

Page 29: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Fork and pull

Pull  request  Work  Fork    

Page 30: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Topic branches

30  

Merge  request  

Push  branch  Work  

Make  topic  branch  

Clone  

Page 31: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Mainline model

Push  frequently  

Push  to  trunk  

Work  locally  

31  

Page 32: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Git Flow

•  Uses several long lived branches

–  Master –  Develop –  Staging

•  Feature and release branches and tags

32  

Page 33: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Gerrit

•  Similar to topic branches with very narrow topics

•  Really represents mainline model with continuous review

ConDnuous  Review  ‘The  speedy  picking  up  of  unreviewed  pending  commits’  -­‐  Paul  Hammant  

•  Every  commit  is  reviewed  •  Within  minute  or  hours  of  

compleDon  •  Before  it  hits  trunk  •  Ties  review  to  code  

Page 34: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Mainline  model  is  built  for  conDnuous  delivery  

 In  parDcular  have  a  mainline:  a  single  branch  of  the  project  currently  under  development.  Pre\y  much  everyone  should  work  off  this  mainline  most  of  the  Dme.  (Reasonable  branches  are  bug  fixes  of  prior  producDon  releases  and  temporary  experiments.)  –  Mar8n  Fowler  

git commit –am “task work” git push origin HEAD:refs/for/master <review, build, and publish in Gerrit>

Steps to Trunk

Page 35: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Customizing Gerrit Workflow

Page 36: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Defines when a change can be submitted

"  Default – One highest vote in

each category – No lowest votes in

any category

Submit Rules

Both:  Human +2!CI +1!  But  not:  Human -2!Or  CI -1!

Page 37: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Defines how a change can be submitted (per project)

"  Types – Fast forward only – Merge if necessary – Merge always – Cherry pick – Rebase if

necessary

Submit Types

Page 38: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Prolog – Logic programming

language – Often used in AI – Bit of a learning

curve

Custom Workflows

"   What’s possible –  Project-specific submit rules –  Replace default submit

rules –  Define when a commit is

accepted –  Override project submit type

Page 39: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Prolog-café fork embedded "  Prolog-shell provided for testing "  SWI-Prolog environment for debugging

Prolog in Gerrit

Page 40: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Stored in rules.pl in refs/meta/config branch – Modify via Git commits

"  Sequence – Gerrit provides a set of facts about a change

•  Author, committer, message, etc. •  Provided in gerrit package

– Then calls rules.pl •  Submit_rule predicate •  Return value indicates whether change is

submittable •  And indicates the submit criteria

Project-specific submit rules

Page 41: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Filters submit rules "  Runs up parent project hierarchy "  Mechanism for global admins to enforce

rules across all projects

Global submit filters

Page 42: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Write a submit_type predicate "  For any change indicate accepted submit

type "  Can include submit type filters

Custom submit type

Page 43: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

"  Test submit_rule against a real change in Gerrit

"  Use test-submit rule

Testing submit rules

cat rules.pl | ! ssh gerrit_host gerrit test-submit rule <change id> -s!

Page 44: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Example: Authors cannot +2

submit_rule(S) :-! gerrit:default_submit(X),! X =.. [submit | Ls],! add_non_author_approval(Ls, R),! S =.. [submit | R].!!add_non_author_approval(S1, S2) :-! gerrit:commit_author(A),! gerrit:commit_label(label('Code-Review', 2), R),! R \= A, !,! S2 = [label('Non-Author-Code-Review', ok(R)) | S1].!add_non_author_approval(S1, ! [label('Non-Author-Code-Review', need(_)) | S1]).!

Page 45: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Example: Only fast forward on release branches

submit_type(fast_forward_only) :-! gerrit:change_branch(B), regex_matches('refs/heads/! release.*', B),! !.!submit_type(T) :- gerrit:project_default_submit_type(T)!

Page 46: Git and Gerrit Workflowslive.wandisco.com › DeFauw_Git-Gerrit_Workflows_Live2014.pdf · – Modify via Git commits " Sequence – Gerrit provides a set of facts about a change

Thank You @rdefauw