Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and...

50
Software Engineering Techniques for Collaborative Software Development Princeton University Bootcamp 2018 David Luet PICSciE, Research Computing/OIT, Department of Geosciences October 30, 2018

Transcript of Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and...

Page 1: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Software Engineering Techniquesfor

Collaborative Software DevelopmentPrinceton University Bootcamp 2018

David Luet

PICSciE, Research Computing/OIT, Department of Geosciences

October 30, 2018

Page 2: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Outline

Git and GitHub for Collaborative Developments

Testing

Automatic Testing

Other Useful Tools For Collaborative Software Development

References and Getting Help

Conclusion

Page 3: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Outline

Git and GitHub for Collaborative Developments

Testing

Automatic Testing

Other Useful Tools For Collaborative Software Development

References and Getting Help

Conclusion

Page 4: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

A Simple Collaborative Workflow

master

GitHub

C3

devel

C0

master

C1 C2

Teammate’s Computer

C3

C0 C1 C2

C3

C0 C1 C2

devel

devel

master

My Computer

Page 5: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Remote Repository Permissions

I Problem with that simple workflow:I It’s easy to push broken code to the shared repository.I when others pull the changes and start adding their development, it

can create problem.I this does not work well with more than two developers.

I To solve this issue, we introduce two roles with differentpermissions on the shared repository:

I code maintainers: push and pull permissions.I developers: only pull permission.

Page 6: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Forking a Repository on GitHub

Forks are basically a copy of a repo on GitHub.

C0

mastermaster

C1 C2

develdevel

GitHub

Developer

C3

C0 C1 C2

C3

ForkShared

Page 7: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Forking a Repository on GitHub

As the GitHub user buildbot-princeton I want to fork:https://github.com/luet/factorial

Page 8: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Forking a Repository on GitHub

Page 9: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Forking a Repository on GitHub

Page 10: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request: the Different Repositories

C0 C1

master

C3

C0 C1 C2 C2

devel

master

PUSH

C3

C0 C1 C2

devel

master

PULL

GitHub

devel

Developer

Developer’s Computer

C3

Shared

Page 11: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps

C4

devel

C0

master

develdevel

master

C3

GitHub

C3

Developer

Developer’s Computer

C0 C1

C3

C0 C1 C2

C2

master

C2C1

Shared

Page 12: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps

C4

PUSH

devel

C4

devel

C1

C3

C3

master

C2C1C0

C3

C0

master

C1 C2

devel

master

GitHub

C2

Developer

Developer’s Computer

C0

Shared

Page 13: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps

C4

Open Pull-Request

devel

C4

devel

C2

C3

C0

master

C2C1C0 C1

master

C2

devel

C3

master

GitHub

C3

Developer

Developer’s Computer

C0 C1

Shared

Page 14: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps

C4

devel

MERGE

devel

C4

devel

C4

C3

C0 C1 C2

C3

C0 C1 C2

master

master

GitHub

master

Developer

Developer’s Computer

C0 C1 C2

C3

Shared

Page 15: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 16: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 17: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 18: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 19: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 20: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 21: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 22: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 23: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 24: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Pull-Request Steps on GitHub

Page 25: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

hands-on #1

http://luet.princeton.edu/cicd/

Page 26: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Advantages of Doing a Pull-Request?

I Gives us time to review and test the changes before committingthem.

I So that no broken code gets committed to the shared repository.I The problem with this simple workflow is that it can be hard for

the code maintainers to know whether or not changes break thecode.

I That’s why we need to build some tests.

Page 27: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Outline

Git and GitHub for Collaborative Developments

Testing

Automatic Testing

Other Useful Tools For Collaborative Software Development

References and Getting Help

Conclusion

Page 28: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Definition and Motivation

I Debugging is what you do when you know that a program isbroken.

I Testing is a determined, systematic attempt to break a programthat you think is working.

I Testing for Quality Assurance: make sure some changes didn’tchange the results compared to the last version.

I When you write code with testing in mind, you write better codebecause you write better interfaces.

Page 29: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

When to Write the Tests

I Test while you are writing the code.I Test incrementally:

I write part of a program,I test it,I add some more code,I test that,I and so on.

I Some programming techniques (e.g. Extreme Programming)even instruct you to write the tests first.

Page 30: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Testing for Functionality

I Unit testing: test one function.I Test a set of functions or the entire code:

I It can be hard to design a test that will exercise a certain portion ofyour code by running the entire code.

I Use libraries and drivers to isolate functions or a group of functions.

Page 31: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Regression Testing: An Example

I SPECFEM3D_GLOBE (Tromp et. al): simulates global andregional seismic wave propagation.

I This code produces seismograms, which are records of theground motion in one direction at a measuring station as afunction of time.

Page 32: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Regression Testing: Comparing Seismograms

err = ‖ref−syn‖√‖ref‖‖syn‖

< TOLreferencelatest

t

d

Page 33: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

An Actual Seismograms

-0.00015

-0.0001

-5e-05

0

5e-05

0.0001

0.00015

-20 0 20 40 60 80 100 120 140 160 180

GE.ZKR.MXE.sem.ascii

referencelatest

Page 34: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Other Tests

I Use different compilers to:I check that it will compile.I find programming mistakes.I compare the results.

I Use different versions of scripting languages e.g. Python, Matlab.I Run on different OS, hardware to make sure:

I the code runs.I the code gives the same results.

Page 36: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Testing Frameworks Example

I Look at my factorial calculation repository:https://github.com/luet/factorial/

Page 37: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Outline

Git and GitHub for Collaborative Developments

Testing

Automatic Testing

Other Useful Tools For Collaborative Software Development

References and Getting Help

Conclusion

Page 38: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Why Run Test Automatically?

I The temptation when you develop code is to test only that partthat you just wrote.

I But there might be side effects to your changes.I So you want to run a your entire suite of tests every time you make

a change.I you are less likely to do that if the tests have to be run manually.

I Not all the developers have access to all tools.I Once it’s set up you don’t have to spend any time running your

tests.

Page 39: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Test Automation with Travis

I An example:https://github.com/uvaaland/travis_tutorial

I You can get a free account at https://travis-ci.com/.I When you can login with your GitHub credential.I It’s only really free for open source (public repositories).

Page 40: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Test Automation with Jenkins

I Service offered by Research Computing.I Jenkins is a web-based application for automatic testing.I Simple user interface: easy to configure.I The advantage other Travis is that with Jenkins you have access

to the Research Computing resources:I Large number of cores.I Compilers.I Licensed software e.g. Matlab.

I Email [email protected] to request an account.I There is a tutorial at:http://jenkins-doc.princeton.edu/tutorial.html

Page 41: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

A Workflow with Jenkins and GitHub

Typical workflow:

1. A Pull-Request is open on GitHub.

2. GitHub sends a signal to our Jenkins server (webhook).

3. Jenkins runs the tests suite.4. Jenkins reports the results of the tests on the GitHub web site.

I If the changes passed the test, the code maintainer can merge thechanges.

I If the changes failed the test, the developer needs to solve theproblem and push the changes to Github.

Page 42: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Scheduled Tests

I A Pull-Request only triggers short (< 15 min) tests.I We use Jenkins to schedule longer tests:

I daily (< 1 hour).I weekly (> 1 hour).

Page 43: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Jenkins vs. Travis

I With Jenkins you can run on:I the Research Computing clusters.I any machine that you have ssh access to.

I Travis is good for small scripts, not parallel code.

Page 44: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Outline

Git and GitHub for Collaborative Developments

Testing

Automatic Testing

Other Useful Tools For Collaborative Software Development

References and Getting Help

Conclusion

Page 45: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Code Documentation

I It’s important to document your code when someone else willhave to read it.

I especially when this someone else can be you in a couple years.I Doxygen:

I Documentation is in the code.I Supports adding Latex to the documentation.I Build calling graph.I show example

I You can use Sphinx with Python.

Page 46: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Documenting outside the code: GitHub Wiki

I GitHub WikiI It’s easy to write in Markdown.I https://help.github.com/articles/about-github-wikis/

I show examplesI Issues:

I https://guides.github.com/features/issues/I Like a shared TODO list.

I Gists:I https://gist.github.com/I For sharing small codes.

Page 47: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Outline

Git and GitHub for Collaborative Developments

Testing

Automatic Testing

Other Useful Tools For Collaborative Software Development

References and Getting Help

Conclusion

Page 48: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

References

I The Practice of Programming, by Brian W. Kernighan and RobPike.

I Testing with Python:I The Hitchhiker’s Guide to Python!:http://docs.python-guide.org/en/latest/

I Testing your code: http://docs.python-guide.org/en/latest/writing/tests/#testing-your-code

I Agile development: Manifesto for Agile Software Development

Page 49: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Outline

Git and GitHub for Collaborative Developments

Testing

Automatic Testing

Other Useful Tools For Collaborative Software Development

References and Getting Help

Conclusion

Page 50: Software Engineering Techniques for Collaborative Software ... · A Workflow with Jenkins and GitHub Typical workflow: 1.A Pull-Request is open on GitHub. 2.GitHub sends a signal

Conclusion

I I encourage you to, in order of urgency:I use a Version Control System.I design some tests.I run those tests automatically.

I In the long run, it will:I save you some time in debugging and troubleshooting.I let you modify your code with confidence that you are not breaking

it.I generate a better organized and better written code.

I We are here to help.I You can e-mail us at: [email protected] Come to the help sessions Tuesdays (10-11 am) and Thursdays

(2-3 pm), room 347 Lewis Library.

I Job opportunity for Graduate students.