class: center, middle, inverse, title-slide # GitHub and Friends ## AKA: How do I get badges on my repo ### Colin Gillespie (
@csgillespie
) --- layout: true layout: true <div class="jr-header"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer"><span>© 2018 Jumping Rivers (jumpingrivers.com)</span></div> --- # Material * HTML slides: https://jumpingrivers.com/t/2018-erum-github/ * GitHub organisation: https://github.com/erum2018-talk/ - A dummy R package used in this talk (`erum2018/`) - Markdown documents (`slides/`) - Drat repository (`drat/`) * This talk uses git and GitHub * Appropriate credits are the end --- # We all use packages (don't we?) -- * Version numbers -- * Enforces documentation -- - But it can't force us to write good documentation! -- * __Automatic code checking__ - R CMD check my_amazing_pkg.tar.gz - R CMD check --as-cran my_amazing_pkg.tar.gz --- # We all use version control (don't we?) -- We get to avoid * thesis.R * thesis1a.R * thesis1a_final.R -- * thesis1a_final_I_hate_my_degree.R -- It (allegedly) makes it easier to merge documents > Generally "a good thing" --- # Data science workflow <img src="graphics/pipeline.jpg" width="100%" style="display: block; margin: auto;" /> --- layout: true layout: true <div class="jr-header-inverse"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer-inverse"><span>© 2018 Jumping Rivers (jumpingrivers.com)</span></div> --- class: inverse, middle, center background-image: url(assets/white_logo.png) # Automate whenever possible --- layout: true layout: true <div class="jr-header"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer"><span>© 2018 Jumping Rivers (jumpingrivers.com)</span></div> --- # The trouble with code is... .pull-left[ * I don't trust myself to write good code 100% of the time * Solution: Check my (pushed) commits! ] .pull-right[ <img src="graphics/machine_learning_no_text.jpg" width="90%" style="display: block; margin: auto;" /> ] --- background-image: url(graphics/travis-op.png) # Travis CI [![Build Status](https://travis-ci.org/eRum2018-talk/erum2018.svg?branch=master)](https://travis-ci.org/eRum2018-talk/erum2018) > Travis CI is a hosted, distributed continuous integration service > used to build and test software projects hosted at GitHub -- You push, travis checks you haven't done something silly --- # Add .travis.yml to your repo [![Build Status](https://travis-ci.org/eRum2018-talk/erum2018.svg?branch=master)](https://travis-ci.org/eRum2018-talk/erum2018) ``` language: r cache: packages ``` -- ``` r: - release - oldrel - devel ``` -- ``` notifications: email: on_success: change on_failure: change ``` -- > Authorise at [travis-ci.org](https://travis-ci.org/) --- layout: true layout: true <div class="jr-header-inverse"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer-inverse"><span>© 2018 Jumping Rivers (jumpingrivers.com)</span></div> --- class: inverse, middle, center background-image: url(assets/white_logo.png) # Anything else? --- layout: true layout: true <div class="jr-header"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer"><span>© 2018 Jumping Rivers (jumpingrivers.com)</span></div> --- # Test suite code coverage [![codecov](https://codecov.io/gh/eRum2018-talk/erum2018/branch/master/graph/badge.svg)](https://codecov.io/gh/eRum2018-talk/erum2018) You can add unit tests to your package: - specific inputs, give outputs - expected errors - fix a bug, add a test -- ``` # .travis.yml r_packages: - covr ``` -- ``` after_success: - Rscript -e "covr::codecov()" ``` --- # Test suite code coverage [![codecov](https://codecov.io/gh/eRum2018-talk/erum2018/branch/master/graph/badge.svg)](https://codecov.io/gh/eRum2018-talk/erum2018) You can add unit tests to your package: - specific inputs, give outputs - expected errors - fix a bug, add a test ``` # .travis.yml r_packages: - covr ``` ``` after_success: - Rscript -e "if(length(grep('1\$', ${TRAVIS_JOB_NUMBER}))) covr::codecov()"; ``` --- # Coding standards Do commits follow a style guide? ``` r_packages: - lintr after_success: - Rscript -e 'lintr::lint_package()' ``` --- # Automatically push packages to a repo - An R repository is just a collection of packages - Ordered in a specific way - It can hosted on a web-server, USB stick, or standard file system - If a package is in a repo, we can use - `install.packages()` - `update.packages()` --- # The drat package - The __drat__ package makes it easy to create your own repository - Takes care of the file structure via `drat::insertPackage("my_pkg")` - GitHub makes it easy to host a web-site - Just create a branch called `gh-pages` -- - Big picture - Run `drat::insertPackage("my_pkg_1.0.0.tar.gz")` on travis - Push package to gh-pages - Specify the repo URL and `install.packages()` now works --- # Now via travis CI ``` r_packages: - drat ``` -- ``` # deploy.sh a shell script after_success: - test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && bash deploy.sh ``` --- # Don't like email - try PushBullet ``` r_packages: - RPushbullet after_success: - Rscript -e 'RPushbullet::pbPost( "note", "If you think my accent is bad", "Search for 'Geordie' on Youtube", apikey = Sys.getenv("PUSHBULLET"), devices = list("XXX", "YYY"))' ``` -- * Same idea applies to slack and friends * Alternatively, use a direct Github integration for twitter - Go to: Settings -> Integrations & services on GitHub --- # All the cool kids use Docker [![](https://img.shields.io/docker/automated/csgillespie/erum2018.svg)](https://hub.docker.com/r/csgillespie/erum2018/builds/) - Straightforward to link GitHub with Dockerhub - Commit triggers dockerhub to build an image --- # appveyor [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/eRum2018-talk/erum2018?branch=master&svg=true)](https://ci.appveyor.com/project/eRum2018-talk/erum2018) - Continuous Integration solution for Windows - travis for Windows - Commit triggers package builds on - R 3.3, R 3.4, R 3.5 - drat then pushes the Windows binaries to our drat repo! --- layout: true layout: true <div class="jr-header-inverse"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer-inverse"><span>© 2018 Jumping Rivers (jumpingrivers.com)</span></div> --- class: inverse, middle, center background-image: url(assets/white_logo.png) # Use cases? --- layout: true layout: true <div class="jr-header"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer"><span>© 2018 Jumping Rivers (jumpingrivers.com)</span></div> --- # Teaching We run courses almost every week - Course materials are distributed via packages - Everyone uses `install.packages()` ```r update.packages("erum2018") ``` - Docker image created for running RStudio in the cloud - [jumpingrivers.training](https://jumpingrivers.training) --- # R conferences and groups * List of useR groups and conferences > https://jumpingrivers.github.io/meetingsR/ -- * Pages hosted on GitHub - bookdown site - Anyone can propose a change via a Pull request -- * Following a master commit, - travis, builds the bookdown html and pushes to a gh-pages branch - Parses the file to create a csv list of groups/conferences - tweet the commit --- # Thanks & Any Questions? <img src="graphics/erum2018.png" width="84%" style="display: block; margin: auto;" /> See [jumpingrivers.com/dates](https://jumpingrivers.com/dates) for our upcoming courses (UK/Germany) <img src="graphics/300_125.jpg" width="20%" style="display: block; margin: auto;" /> --- # References - Creating repos with [drat](https://github.com/eddelbuettel/drat) - R interface to [pushbullet](https://github.com/eddelbuettel/rpushbullet) - Static code analyse with [lintr](https://github.com/jimhester/lintr) - Test coverage with [covr](https://github.com/r-lib/covr) - [r-travis](https://github.com/craigcitro/r-travis)