git-at-github-ncareol



git-at-github-ncareol

0 0


git-at-github-ncareol

presentation: git@github.com/ncareol

On Github erikj / git-at-github-ncareol

git@github.com:ncareol

We ❤ Git, We ❤ GitHub

Erik Johnson, NCAR EOL

EOL-Prog Lunch Seminar, 2014/03/27

0.1.0 alpha release

preparation for presentation of same name at SEA Conf 2014

https://sea.ucar.edu/event/gitgithubcomncareol

bleeding edge!

may contain sharp edges!

may be superceded by breaking changes!

caveat emptor!

NCAR Earth Observing Laboratory

(EOL)

NCAR EOL: Field Projects

  • campaigns to conduct atmospheric research

  • e.g.

    • DC3 (2012)
    • MPEX (2013)
    • SAS / NOMADSS / SOAS (2013)
    • CONTRAST (2014)

NCAR EOL: Field Catalog

  • serves and archives field-project data
  • used during and after project
  • developed by 2-6 active Software Engineers @ any time
  • administered by ~ one Software Engineer / active project

NCAR EOL: Field Catalog

  • suite of web and database applications
    • zith9 database schema (MySQL)
    • Catalog Models application (Ruby, ActiveRecord)
    • Catalog Ingest application (Ruby, ActiveRecord, inotify, EventMachine)
    • Field Catalog web application (Ruby on Rails, CoffeeScript, Bootstrap)
    • Catalog Maps web application (Ruby on Rails, CoffeeScript, OpenLayers, Bootstrap)
    • Catalog Nagios monitoring utility (Ruby, ActiveRecord, Nagios)
    • Catalog Stats command-line application (Ruby, ActiveRecord)

Git

  • created by Linus Torvalds for development of Linux kernel
  • initially released in 2005

http://en.wikipedia.org/wiki/Git_(software)

$ man git

$ man git

NAME
  git - the stupid content tracker

DESCRIPTION
  Git is a fast, scalable, distributed revision control system with an
  unusually rich command set that provides both high-level operations and
  full access to internals.

Git

  • DVCS, cf. Hg (Mercurial), GNU Bazaar, BitKeeper
  • every check out is a complete, free-standing repository
  • developers have a complete VCS w/o need to interact w/ central / other repositories

GitHub

a web-based hosting service for software development projects that use the Git revision control system.

http://en.wikipedia.org/wiki/GitHub

GitHub

  • most popular host of Open-Source projects

  • 3.5 million users, April 2013 [1]

  • 10 million repositories, December 2013 [2]

[1] https://github.com/blog/1470-five-years

[2] https://github.com/blog/1724-10-million-repositories

GitHub Organizations

  • unlimited collaborators (associated users)
  • unlimited public repositories
  • pay for private repositories

https://github.com/pricing

GitHub Orgs: ncareol

  • initially: Bronze, 10 private repositories, $25 / month
  • later: Silver, 20 private repositories, $50 / month

https://github.com/pricing

GitHub Issues

In the beginning...

There is an issue:

Issues generally fall into one of two categories:

  • features: make something / make something better
  • bugs: something is wrong and needs to be fixed

Issue Description

composed in plain text and / or markdown / GFM

Markdown

plain-text syntax for authoring that compiles to HTML

designed to be written quickly w/ rich-text formatting provided by HTML

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML). https://daringfireball.net/projects/markdown/

Markdown Basics

# heading 1
## heading 2
### heading 3

**bold**

*italics*

- unordered
- list

1. ordered
1. list

[link](http://some/url)

https://daringfireball.net/projects/markdown/basics

GitHub-Flavored Markdown

Misc enhancements to plain-old Markdown

  • auto-link URLs
  • strikethrough: ~~struck~~ => struck

https://help.github.com/articles/github-flavored-markdown

GitHub-Flavored Markdown

Misc enhancements to plain-old Markdown

  • language-specific syntax highlighting

    ```javascript
    function alertHello() {
      alert("Hello World!");
    }
    ```
    function alertHello() {
      alert("Hello World!");
    }

https://help.github.com/articles/github-flavored-markdown

GitHub Magic!

#issues, @usernames and commit hashes are hot-linked:

https://github.com/blog/831-issues-2-0-the-next-generation

GitHub Magic!

checklists:

- [x] this is a completed item
- [ ] this is a TODO item

https://github.com/blog/831-issues-2-0-the-next-generation

Milestones

  • title
  • description (optional)
  • due date
  • set of issues

Milestones

Milestones

We generally assign significant, planned versions to their own milestones, e.g.

  • Catalog Maps 2.0
  • Catalog Maps 2.1
  • Catalog Maps 2.2

Labels

Issues can be assigned one or more labels

Create / edit / delete labels as needed

Useful for categorizing issues

Labels

CHECKED OUT

when a developer is ready to work on an issue:

  • assign the issue to themselves

  • add the CHECKED OUT label to the issue

Issues

Issues can be observed and commented upon as they progress

  • Comments can be in-line w/ Issue

  • Comments can be made to specific commits or lines of commits

  • Comments are in Markdown / GFM w/ auto-linking features described previously

Branches

Branches are a fundamental part of Git

TODO branches clip art / photo

Git-Branching Workflow

http://nvie.com/posts/a-successful-git-branching-model/

Branch Categories

  • features: feature-...
  • fixes: fix-...
  • experimental: xfeature-...
  • hot features and fixes: hotfeature-...

http://nvie.com/posts/a-successful-git-branching-model/

Branch Names

There are two hard problems in computer science: cache invalidation, naming things and off-by-one errors. Phil Karlton + Martin Fowler

Prefix the branch name w/ the branch category: e.g. feature, fix If the branch is associated w/ an issue, include the issue number-- easy point of reference for which issue the branch applies Finish the branch name w/ short-but-informative description

e.g.

  • feature-42-the-answer
  • fix-314-pi-miscalculation
  • hotfix-all-the-bugs

workflow in action, contrived example, part 1

$ git checkout develop
$ git pull # update w/ latest from origin: github
$ git checkout -b feature-99-add-project-columns
$ vi db/migrate/022_add_project_columns.rb # make and save changes
$ git commit -m "add columns to table project; #99"
$ git push -u origin feature-99-add-project-columns # push to origin

Commit Messages: Issue Number

including the issue number, prefixed w/ # will associate w/ the issue and cause the commit to be displayed on and linked from the issue's page

  • TODO include example(s)

Commit Messages: Issue Number

  • issues can also be closed from commit messages, w/ fixes closes, etc. before commit number:

    • fixes
    • fixed
    • fix
    • closes
    • close
    • closed

Commit Messages: Issue Number

  • good to separate issue ID from message w/ a safe delimiter
    • want to avoid "apply required CSS fix #99" from closing #99
    • semicolon delimiter: "apply required CSS fix; #99" doesn't close #99
    • but if we did intend close the issue: "apply required CSS; fix #99"

Commit Message: GitHub Magic

Like Issue content, #issue IDs, @usernames and commit hashes will be autolinked in GitHub's web interface.

Github Pull Requests

Github Pull Requests: Demo

Github Pull Requests

  • automatically closed when requested merge is performed and pushed to origin

Easy Deploys w/ Git

  • Git-based workflow that allows us to deploy to various environments by using git push

  • Inspired by Heroku

$ git push heroku master

Counting objects: 63, done.
Compressing objects: 100% (49/49), done.
Writing objects: 100% (63/63), 26.35 KiB, done.
Total 63 (delta 2), reused 0 (delta 0)
-----> Ruby/Rails app detected
-----> Installing dependencies using Bundler version 1.3.0.pre.5
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
Fetching gem metadata from https://rubygems.org/.....
...

https://devcenter.heroku.com/articles/git

Easy Deploys w/ Git: Config

Server / deployment target repository:

Add [receive] section to .git/config

[receive]
    denyCurrentBranch = ignore

Easy Deploys w/ Git: Hooks

Automatically trigger actions that are required so that service is aware and updated w/ pushed source code

.git/hooks/post-receive:

echo "bundle'ing"
bundle install --local --path=vendor --deployment --without development test

echo "precompile'ing assets"
rake RAILS_ENV=production assets:precompile

echo "reloading"
/usr/local/catalog/etc/catalog-ui-reload

Easy Deploys w/ Git: Remotes

[ej@kepler] git remote -v
dev ssh://ej@ctm-dev.eol.ucar.edu/usr/local/catalog/catalog_ui (fetch)
dev ssh://ej@ctm-dev.eol.ucar.edu/usr/local/catalog/catalog_ui (push)
ops ssh://ej@sferic.eol.ucar.edu:23/usr/local/catalog/catalog_ui (fetch)
ops ssh://ej@sferic.eol.ucar.edu:23/usr/local/catalog/catalog_ui (push)
staging ssh://ej@sferic-dev.eol.ucar.edu/usr/local/catalog/catalog_ui (push)
staging ssh://ej@sferic-dev.eol.ucar.edu/usr/local/catalog/catalog_ui (fetch)

Merge, Easily Deploy

  • merge to develop
  • deploy local develop branch to dev
    $ git push dev develop
  • test changes on dev environment
  • merge to master
  • deploy local master to staging
    $ git push staging master
  • test changes on staging environment
  • tag release
  • deploy local master to ops
    $ git push ops master
  • test changes on staging environment
  • push develop and master to origin

Misc Git: .gitconfig

  • use aliases
    [alias]
      ss = status
      s  = status -sb
      cl = config --list
      a  = add
      ci = commit
      co = checkout
      d  = diff
      ds = diff --cached # diff staged changes
      p  = push
      b  = branch
      undo    = reset --soft HEAD^

https://github.com/erikj/dotfiles/blob/master/kepler/.gitconfig

https://github.com/erikj/dotfiles/blob/master/.gitconfig.aliases

Misc Git: .gitconfig

  • use global .gitignore
  • keep developer-specific cruft out of project .gitignores
  • ~/.gitconfig

    [core]
      excludesfile = ~/.gitignore-global
  • ~/.gitignore-global

    *.DS_Store
    *.sublime-*
    /.pow*
    jmeter.log

https://github.com/erikj/dotfiles/blob/master/kepler/.gitconfig

https://github.com/erikj/dotfiles/blob/master/.gitignore-global

Lessons Learned

  • Use the tools you have / that are available:

    • Git is awesome
    • GitHub is awesome
    • Markdown is awesome
    • packaging libraries offer many features
  • GitHub is reliable and simple but powerful

  • GitHub can be a great tool for communication between developers and stakeholders

  • Issue discovery can be difficult when there are many Issues

    • => Easy to create duplicates
  • Use Labels for organization

  • Use Git tags for releases

  • Minimize third-party dependencies

Summary

  • Development starts w/ an Issue
  • Markdown / GFM and auto-linking features
  • Git-Branching Workflow
  • GitHub Pull Requests: code review and discussion
  • Git-Based Easy Deploys

Future

  • Faster, smarter Easy Deploys
  • Continuous Integration
  • Vagrant
  • DevOps
  • Open Source

References

</content>