Template files for a (i)Python, C and C++ repositories integrated with SonarQube
For those who program oftenly in C
, C++
and Python
, it is common that when creating a new project, many files from other projects and repositories must be copied in the new one. Makefiles, installation scripts, sample test code, etc. are normally repeated in the new repo, or they are useful as templates for new files.
RepoTemplate offers in a single package the basic functionality of a basic repository (project) including:
-
A generic makefile.
-
Example testing code (
unittest
for Python andcppunit
C++). -
Installations and configuration scripts.
-
SonarQube integration.
To use RepoTemplate you will need (non-functional requisites):
-
A GitHub account.
-
A SonarQube account.
-
An Ubuntu Linux machine (we assume it has a x86-64 architecture).
Make sure that you have configured (installed) your GitHub credentials and have configured your account to make some git (see appendixes)
If you have any problem preparing or configuring the repo see the Repository troubleshooting or the Sonar troubleshooting.
NOTE: Hereafter we will assume that your GitHUb account name is
iHacker
.
Creating a new repository from RepoTemplate, is very easy:
-
Create locally a directory for the new Repo, eg.
NewRepo
:mkdir -p NewRepo cd NewRepo
-
Configure your github credentials (see GitHub configurationn):
git config --global --edit
-
Clone the repo template in the new directory (attention to the final
.
; it is mandatory):git clone https://github.com/seap-udea/RepoTemplate.git .
-
Run the make rule
repo
:USER=ihacker make repo
You need to be sure that
NewRepo
does not exist in theiHacker
GitHub account. -
Verify that you have installed all dependencies:
make deps
-
Test your repo:
make
-
Commit your repo changes:
make commit
Voila! you have your new repository.
Before using the repository, however, you need to personalize it.
In order to use some of the best functionalities of RepoTemplate, it is needed to execute some additional commands.
-
Edit
.pack/packrc
and choose, among other options, the version ofpython
andnosetests
you want to use.#Pthon binaries PYTHON=python3 NOSETESTS=nosetests3 #Directories REPODIR=util/repo STOREDIR=.store #Log files LOGFILE=.pack/log
NOTE: It is important to notice that configuration files may change significantly, therefore this is an example.
-
Install dependencies.
make deps_repo
This is a typical output of this command:
Checking for dependencies... Checking for sonar-scanner:not installed. Checking for build-wrapper:not installed. Checking for coverage:not installed. Checking for nosetests:not installed. Checking for clang:not installed. Checking for cppunit:not installed. ----copy this---- sudo apt-get install -y libcppunit-dev libcppunit-doc;sudo apt-get install -y clang;sudo apt-get install -y python3-nose;sudo apt-get install -y python3-coverage;make sonarinstall; ----end copy----
You must copy the commands betwee
----copy this---
and----end copy----
. For the installation of thesonar-scanner
andbuild-wrapper
dependencies see 2. Once installed the dependencies run again:make deps
When all the dependencies are met, the output of
make deps
should be:Checking for dependencies... Checking for sonar-scanner:done. Checking for build-wrapper:done. Checking for coverage:done. Checking for nosetests:done. Checking for clang:done. Checking for cppunit:done. All done.
About sonar binaries: Sonar require two set of binaries: build-wrapper and sonar-scanner (for detailed explanations of this files see Sonar Functionality). Although they should be normally downloaded fron SonarQube website, for the sake of simplicity, we provide along this package a script for getting and placing it in the right place:
make sonarinstall
. -
Create new project in Sonarcloud.io and get the
Project Key
,Organization Key
andtoken
(for detailed instructions see Sonar Cloud configuration) -
Edit
util/repo/sonarc
using thesonar.projectKey=iHacker_NewRepo sonar.organization=iHacker-github sonar.login=2084a54ce06b4d193900141cf67a163681f746d1
NOTE: It is important to notice that configuration files may change significantly, therefore this is an example.
This is some (optional) complicated stuff. You probably know it, so we decided to put it at the end of this file to not bother you. If you are kind of newbie we did not want to scare you with fancy commands. Still if you have some time, please read.
-
Configure:
git config --global user.email "your.email@server.org" git config --global user.name "Your Name"
or equivalently:
git config --global --edit
-
Create a ssh-key, upload it to GitHub and configure ssh in your machine:
ssh-keygen -t rsa -N"" -f $HOME/.ssh/id_rsa_ihacker cat > $HOME/.ssh/config Host github.com-ihacker HostName github.com User git IdentityFile ~/.ssh/id_rsa_ihacker