Commit 084d88e6 authored by Cyril L'Orphelin's avatar Cyril L'Orphelin
Browse files

Tp5 étape 2

parent 1eee985e
......@@ -129,7 +129,7 @@ job_test3 :
----
- Les mots clés only/except permettent de définir des roles de déploiement
- Les mots clés <a href="https://docs.gitlab.com/ee/ci/yaml/#only--except">only/except</a> permettent de définir des roles de déploiement
- Reprenez l'exemple avec 3 stages, et faites en sorte
- que le stage 1 soit toujours executé (pas de règles)
- que le stage 2 soit executé sur la branche tp5
......@@ -162,4 +162,130 @@ job_test3 :
script :
- uname -r
</code></pre>
</details>
### Etape 2 : Automatisation des tests avec Python
**Problème 1**
* Vous allez désormais utiliser une image python:3 pour exécuter le pipeline et il va falloir installer les modules qui vont bien !
* Vous devez avoir dans le répertoire TP5 un répertoire **src** avec le fichier [tri.py](src/tri.py) et son fichier de test [tri_test.py](src/tri_test.py)
* Vous allez écrire un stage de lecture qui execute pylint sur tri.py
* Vous allez écrire un stage de test qui exécute unittest
* Que se passe t'il avec le stage de lecture ? Peut être qu'il faut le considérer comme non bloquant !
<details>
<summary>Solution </summary>
<pre class=" language-yaml" tabindex="0"><code class=" language-yaml"><span class="token key atrule">image</span><span class="token punctuation">:</span> python<span class="token punctuation">:</span><span class="token number">3</span>
<span class="token key atrule">stages</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> lint
<span class="token punctuation">-</span> test
<span class="token key atrule">job_lint</span><span class="token punctuation">:</span>
<span class="token key atrule">stage</span><span class="token punctuation">:</span> lint
<span class="token key atrule">script</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> pip install pylint
<span class="token punctuation">-</span> cd TP5/src
<span class="token punctuation">-</span> pylint tri
<span class="token key atrule">allow_failure</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">job_test</span><span class="token punctuation">:</span>
<span class="token key atrule">stage</span><span class="token punctuation">:</span> test
<span class="token key atrule">script</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> cd TP5/src
<span class="token punctuation">-</span> python <span class="token punctuation">-</span>m unittest tri_test
</code>
</details>
</pre>
* * *
**Problème 2**
* Vous allez maintenant remplacer unittest par l'outil [`coverage`](https://coverage.readthedocs.io/en/coverage-5.5/)
* A partir de `Settings` > `CI/CD` > `General Pipeline` : ajouter l'expression régulière suivante pour les test de couverture : `^TOTAL.+?(\d+\%)$`
* Vous pouvez désormais rajouter un badge de couverture dans la partie `Settings` > `General` > `Badges`
<details>
<summary>Solution coverage</summary>
<pre class=" language-yaml" tabindex="0"><code class=" language-yaml"><span class="token key atrule">image</span> <span class="token punctuation">:</span> python<span class="token punctuation">:</span><span class="token number">3</span>
<span class="token key atrule">stages</span> <span class="token punctuation">:</span>
<span class="token punctuation">-</span> lint
<span class="token punctuation">-</span> test
<span class="token punctuation">-</span> deploy
<span class="token key atrule">job_lint</span> <span class="token punctuation">:</span>
<span class="token key atrule">stage</span><span class="token punctuation">:</span> lint
<span class="token key atrule">script</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> pip install pylint
<span class="token punctuation">-</span> cd TP5/src
<span class="token punctuation">-</span> pylint tri
<span class="token key atrule">allow_failure</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">job_test</span> <span class="token punctuation">:</span>
<span class="token key atrule">stage</span><span class="token punctuation">:</span> test
<span class="token key atrule">script</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> pip install coverage
<span class="token punctuation">-</span> cd TP5/src
<span class="token punctuation">-</span> echo " " <span class="token important">&amp;&amp;</span> echo "<span class="token punctuation">-</span><span class="token punctuation">-</span> Performance tests from tri.py <span class="token punctuation">-</span><span class="token punctuation">-</span>" <span class="token important">&amp;&amp;</span> coverage run tri.py
<span class="token punctuation">-</span> echo " " <span class="token important">&amp;&amp;</span> echo "<span class="token punctuation">-</span><span class="token punctuation">-</span> Coverage Report via Unit Tests <span class="token punctuation">-</span><span class="token punctuation">-</span>" <span class="token important">&amp;&amp;</span> coverage run <span class="token punctuation">-</span>m unittest tri_test.py <span class="token important">&amp;&amp;</span> coverage report <span class="token punctuation">-</span>m <span class="token punctuation">-</span><span class="token punctuation">-</span>omit=tri_test.py
</code></pre>
</details>
<details>
<summary>Badges</summary>
<ul>
<li>Settings > badges </li>
<li>Name : Coverage</li>
<li>Link : https://gitlab.in2p3.fr/%{project_path}/-/commits/%{default_branch}</li>
<li>Url : https://gitlab.in2p3.fr/%{project_path}/badges/%{default_branch}/coverage.svg</li>
</ul>
</details>
* * *
**Problème 3**
* Vous allez maintenant ajouter un stage de build de la documentation
1. Vous devrez install sphinx et le theme rtd (sphinx-rtd-theme)
2. dans le répertoire documentation adaptez les fichiers à votre convenance : [conf.py](documentation/conf.py "conf for sphinx") et [index.rst](documentation/index.rst "index for sphinx")
3. Générer la documentation avec sphinx-build dans le répertoire public
4. Rajouter le path public dans [l'artifact](https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html "doc gitlab artifact")
5. Renommer votre job en "pages" et vérifiez après un déploiement réussi, l'accès à vos "pages" dans le menu **Settings > Pages**
<details>
<summary>Solution</summary>
<pre class=" language-yaml" tabindex="0"><code class=" language-yaml"><span class="token key atrule">image</span> <span class="token punctuation">:</span> python<span class="token punctuation">:</span><span class="token number">3</span>
<span class="token key atrule">stages</span> <span class="token punctuation">:</span>
<span class="token punctuation">-</span> lint
<span class="token punctuation">-</span> test
<span class="token punctuation">-</span> deploy
<span class="token key atrule">job_lint</span> <span class="token punctuation">:</span>
<span class="token key atrule">stage</span><span class="token punctuation">:</span> lint
<span class="token key atrule">script</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> pip install pylint
<span class="token punctuation">-</span> cd TP5/src
<span class="token punctuation">-</span> pylint tri
<span class="token key atrule">allow_failure</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token key atrule">job_test</span> <span class="token punctuation">:</span>
<span class="token key atrule">stage</span><span class="token punctuation">:</span> test
<span class="token key atrule">script</span><span class="token punctuation">:</span>
<span class="token punctuation">-</span> pip install coverage
<span class="token punctuation">-</span> cd TP5/src
<span class="token punctuation">-</span> echo " " <span class="token important">&amp;&amp;</span> echo "<span class="token punctuation">-</span><span class="token punctuation">-</span> Performance tests from tri.py <span class="token punctuation">-</span><span class="token punctuation">-</span>" <span class="token important">&amp;&amp;</span> coverage run tri.py
<span class="token punctuation">-</span> echo " " <span class="token important">&amp;&amp;</span> echo "<span class="token punctuation">-</span><span class="token punctuation">-</span> Coverage Report via Unit Tests <span class="token punctuation">-</span><span class="token punctuation">-</span>" <span class="token important">&amp;&amp;</span> coverage run <span class="token punctuation">-</span>m unittest tri_test.py <span class="token important">&amp;&amp;</span> coverage report <span class="token punctuation">-</span>m <span class="token punctuation">-</span><span class="token punctuation">-</span>omit=tri_test.py
</code></pre>
</details>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment