25
Marco Mambelli – [email protected] FSPA presentation 9 March 2020 Github and Software Best Practices

Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

  • Upload
    others

  • View
    18

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

Marco Mambelli – [email protected] presentation9 March 2020

Github and Software Best Practices

Page 2: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Set of instructions and its associated documentations that tells a computer what to do or how to perform a task

• Any manuscript/artifact/product written by you with the scope to be used by machine and humans

Software

3/9/20 Marco Mambelli | Github and Software Best Practices2

Page 3: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

3/9/20 Marco Mambelli | Github and Software Best Practices3

Page 4: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

3/9/20 Marco Mambelli | Github and Software Best Practices4

“PiledHigherandDeeper”byJorgeCham,http://www.phdcomics.com

Page 5: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Preserves different version of a document

• Helps merging different contributions

• Answers important questions on the documents– What changed?– Who changed it?– Why?

Version Control System

3/9/20 Marco Mambelli | Github and Software Best Practices5

Imagecredit:https://swcarpentry.github.io/git-novice/01-basics/index.html

Page 6: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

Centralized vs distributed VCS

3/9/20 Marco Mambelli | Github and Software Best Practices6

• CVS• SVN

• Mercurial• Git

Imagecredit:https://betterexplained.com/articles/intro-to-distributed-version-control-illustrated/

Page 7: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Clients for the major platforms– Command line– GUI (Fork, GitHub desktop, GitKraken, Tower,…)

• Online hosting– Bitbucket– GitLab– GitHub

• Hosting at Fermilab– Git integrated with Redmine– GitLab instance

Git resources

3/9/20 Marco Mambelli | Github and Software Best Practices7

Page 8: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Snapshot with GUID (SHA1 hash)– git command [sub-command] [options] [arguments]

• Repository– init

• Staging– add

• Commit– commit (checkout)

• Tag– tag (checkout)

Git concepts – Local repository

3/9/20 Marco Mambelli | Github and Software Best Practices8

Page 9: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Remote– clone– remote add– push– fetch (pull)– Local branches track remote ones (branch –u)

• Define a main repository!

Git remotes – Remote repositories

3/9/20 Marco Mambelli | Github and Software Best Practices9

Workingcopy Server

Page 10: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Code or text-like documents*• When you need to know

– What changed?– Who changed it?– Why?

• Some programs have their own integrated version control

* Git provides LFS (Large File Storage)

Use Git for …

3/9/20 Marco Mambelli | Github and Software Best Practices10

https://git-lfs.github.com/

Imagecredit:https://git-lfs.github.com/

Page 11: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

Centralized workflow

3/9/20 Marco Mambelli | Github and Software Best Practices11

• Single(remote)repo• Singleorderedflow

• Conflictssolvedoneatthetimebythedeveloper

Imagescredit:https://www.atlassian.com/git/tutorials/comparing-workflows

Merge RebaseConflictsresolution

Page 12: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

Feature branching workflow

3/9/20 Marco Mambelli | Github and Software Best Practices12

• Single(remote)repo• Leveragebranches:• master

(releases)• Development• Features• Hotfixes

• Easiertoenforcepolicies

https://nvie.com/posts/a-successful-git-branching-model/ Imagescredit:https://www.atlassian.com/git/tutorials/comparing-workflows

Page 13: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

Fork and branch workflow

3/9/20 Marco Mambelli | Github and Software Best Practices13

• Multipleforkedrepos• Leveragebranches• Featurebranchesin

forkedrepos• Squash• Rebase

• Pullrequests• Eveneasiertoenforce

policies• Restrictedaccess

R1 R2

R1R2

Imagescredit:https://www.atlassian.com/git/tutorials/comparing-workflows

Page 14: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Write meaningful commit messages– First line is the summary– Enough detail to understand the changes

• Access to the repository based on software purpose– Least Privilege approach– Consider signing commits

• Public software should have a license– LICENSE (text file in the root of the repository)– BSD 3-clause, Apache 2.0, GitHub has examples– At Fermilab you can get help in picking and reviewing a license

• Contact Aaron Sauers• https://cdcvs.fnal.gov/redmine/projects/scd-cst/wiki/Software_licensing

• A DOI, Digital Object Identifier, can facilitate citations – https://about.zenodo.org/

Final Git recommendations

3/9/20 Marco Mambelli | Github and Software Best Practices14

https://help.github.com/en/articles/signing-commits

Page 15: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• PASSWORDS!

• Any credential: SSH keys, certificates, …

• Private or PII– IP addresses– Names, birth dates, SSN …

What should never go in Git?

3/9/20 Marco Mambelli | Github and Software Best Practices15

Page 16: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Git repository hosting service• Numbers

– over 40 million users– > 100 million repositories (> 28 million public)– GitHub, Inc. subsidiary of Microsoft

• Main services– Web interface– Wiki– Github Pages, websites https://username.github.io– Github Actions– Pull requests w/ review and comments

– Integrations

GitHub in brief

3/9/20 Marco Mambelli | Github and Software Best Practices16

https://pages.github.com/

https://github.com

https://help.github.com/en/github/managing-your-work-on-github/about-issues

Page 17: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Follow clear coding guidelines– PEP8, Google Python style guide, GNU C coding standards

• Enforce code documentation and standard– Javadoc, Google Python docstrings

• Enforce code validation (linting)– lint, pylint, pycodestyle, shellcheck, jslint– Integrate in VCS workflow

• Use IDE– vi+extensions, PyCharm,

Visual Studio Code, Brackets• Enforce reviews if possible

– Pair programming, peer reviews – Integrate in VCS workflow

Software development (coding)

3/9/20 Marco Mambelli | Github and Software Best Practices17

Page 18: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Documentation– README – Complex manuals (Users, Installation, API, …) – Target audience

• Developers (including your future self)• Users (operators/end users)

• Tests– Software should be tested!– Requirement documentation is crucial– Resources

• Unit test libraries in most languages• Continuous Integration system (CI) provided by Fermilab• Github actions

Documentation and tests

3/9/20 Marco Mambelli | Github and Software Best Practices18

https://cdcvs.fnal.gov/redmine/projects/cihttps://github.com/features/actionshttps://help.github.com/en/actions/building-and-testing-code-with-continuous-integration/setting-up-continuous-integration-using-github-actions

https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-readmes

https://guides.github.com/features/wikis/https://pages.github.com/

Page 19: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• You may need it• Proves different expertise• Releases

– Document the release process– A release should be tagged– Release notes should be easily accessible

• Deployment– Documented deployment procedure– Choose deployment models

• Cloning, archive, container, …– Ask questions to guide the selection

• System/user install?• Relocatable?• One or more installations per host?

Software releases

3/9/20 Marco Mambelli | Github and Software Best Practices19

https://github.com/features/actionshttps://github.com/sdras/awesome-actions#deploymenthttps://itnext.io/https-medium-com-marekermk-guide-to-a-custom-ci-cd-with-github-actions-5aa0ff07a656

Page 20: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Link the accounts• Grant access• Define the container (dockerfile) in Github• Image built and updated automatically

• And you can integrate also with Open Science Grid Singularity images on CVMFS

DockerHub integration

3/9/20 Marco Mambelli | Github and Software Best Practices20

https://docs.docker.com/docker-hub/builds/link-source/

https://github.com/opensciencegrid/cvmfs-singularity-sync

Page 21: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Online LaTeX editor• Real time collaboration, VC• Git integration

– Easier collaboration– Edit outside Overleaf

Overleaf

3/9/20 Marco Mambelli | Github and Software Best Practices21

https://www.overleaf.com/learn/how-to/How_do_I_connect_an_Overleaf_project_with_a_repo_on_GitHub,_GitLab_or_BitBucket%3Fhttps://www.overleaf.com/for/universities

Page 22: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Personal info– Profile picture

• smiling and professional (or none)– Info should be updated– What you want people to see

• Organize your repositories– Documentation (README)– Ideas

• Website, games, scripts, employer targeted– If too many

• Pin projects• Use organizations to stash old repositories• Delete old forks

– Keep forks synchronized

Optimize your profile

3/9/20 Marco Mambelli | Github and Software Best Practices22

Page 23: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Git concepts– Snapshots, repositories– Collaboration workflows

• General coding principles– Planning– Simplicity– Documenting– Testing– Coherence– Reviews

• Github– Keep it updated– Highlight what you want others to see

General ideas

3/9/20 Marco Mambelli | Github and Software Best Practices23

[email protected]

Page 24: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Sources and references– Software Development and Deployment Best Practices

• Multiple authors, Fermilab SCD https://docs.google.com/document/d/1c9ofaj9dBFFjXfqsMlV-_HogL8vONJUOSJBojnz7lHI/edit?usp=sharing

– VCS documents and tutorials• https://help.github.com/• https://www.atlassian.com/git/tutorials/• https://git-scm.com/• https://swcarpentry.github.io/git-novice/• https://education.github.com/git-cheat-sheet-education.pdf

Thank you

3/9/20 Marco Mambelli | Github and Software Best Practices24

Page 25: Github and Software Best Practicesfspa.fnal.gov/wp-content/uploads/2020/03/200309Mambelli.pdf– GUI (Fork, GitHub desktop, GitKraken, Tower,…) • Online hosting – Bitbucket –

• Synchronize a forked repository– https://help.github.com/en/github/collaborating-with-issues-and-

pull-requests/syncing-a-fork– https://stackoverflow.com/questions/20984802/how-can-i-keep-

my-fork-in-sync-without-adding-a-separate-remote/21131381#21131381

– https://stackoverflow.com/questions/15779740/how-to-update-my-fork-to-have-the-same-branches-and-tags-as-the-original-reposit

Extra

3/9/20 Marco Mambelli | Github and Software Best Practices25