From 6056b5c2851db05cbda7825fb71d8928520269ca Mon Sep 17 00:00:00 2001
From: Matthieu Boileau <matthieu.boileau@math.unistra.fr>
Date: Tue, 21 Nov 2017 00:23:16 +0100
Subject: [PATCH] Update notebook with exo2

---
 tp-gitlab-ci.ipynb | 302 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 299 insertions(+), 3 deletions(-)

diff --git a/tp-gitlab-ci.ipynb b/tp-gitlab-ci.ipynb
index a7f818b..dc2f3d9 100644
--- a/tp-gitlab-ci.ipynb
+++ b/tp-gitlab-ci.ipynb
@@ -149,7 +149,8 @@
    "outputs": [],
    "source": [
     "export USERNAME=\"m.boileau\"  # votre login sur git.unistra.fr\n",
-    "export TPDIR=$HOME         # le répertoire où vous souhaitez installer le TP"
+    "export TPBASEDIR=$HOME      # le répertoire où vous souhaitez installer le TP\n",
+    "export TPDIR=$TPBASEDIR/tp-gitlab-ci"
    ]
   },
   {
@@ -165,7 +166,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "cd $TPDIR\n",
+    "cd $TPBASEDIR\n",
     "git clone git@git.unistra.fr:$USERNAME/tp-gitlab-ci.git"
    ]
   },
@@ -261,7 +262,7 @@
     "\n",
     "### Mettre en place une action d'intégration continue\n",
     "\n",
-    "Aller dans le répertoire racine du clone local de votre projet et basculer sur la branche `exo1`"
+    "Allez dans le répertoire racine du clone local de votre projet et basculez sur la branche `exo1`"
    ]
   },
   {
@@ -444,6 +445,301 @@
     "\n",
     "> **Note :** les fichiers peuvent s'éditer directement dans GitLab."
    ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "slide"
+    }
+   },
+   "source": [
+    "## Exo2 : helloworld en C\n",
+    "\n",
+    "### Description\n",
+    "\n",
+    "On écrit le programme `helloworld` en C qui doit afficher `hello, world`.\n",
+    "\n",
+    "### Mettre en place une action de *build*\n",
+    "\n",
+    "Dans votre clone local, basculez sur la branche `exo2`"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "cd $TPDIR\n",
+    "git stash  # si vous avez des modifications non enregistrées dans exo1\n",
+    "git checkout exo2"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
+   "source": [
+    "Listez le contenu du répertoire"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "ls -al"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Vérifiez que le progamme compile"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "make"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
+   "source": [
+    "On crée le fichier `.gitlab-ci.yml` avec une étape (`stage`) de `build`. Il doit contenir :\n",
+    "```yaml\n",
+    "build_hello:\n",
+    "  stage: build\n",
+    "  tags:\n",
+    "    - shell\n",
+    "  script:\n",
+    "    - make\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "cat > .gitlab-ci.yml <<- EOM\n",
+    "build_hello:\n",
+    "  stage: build\n",
+    "  tags:\n",
+    "    - shell\n",
+    "  script:\n",
+    "    - make\n",
+    "EOM"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
+   "source": [
+    "On vérifie le contenu"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "cat .gitlab-ci.yml"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "-"
+    }
+   },
+   "source": [
+    "On enregistre et on pousse."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "slideshow": {
+     "slide_type": "-"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "git add .gitlab-ci.yml\n",
+    "git commit -m \"Add .gitlab-ci.yml with a build stage\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "scrolled": true,
+    "slideshow": {
+     "slide_type": "subslide"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "git push"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "-"
+    }
+   },
+   "source": [
+    "Sur GitLab, observez l'exécution de votre job dans la rubrique de votre projet :\n",
+    "```\n",
+    "CI / CD > Pipelines\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "slide"
+    }
+   },
+   "source": [
+    "### Ajouter une action de *test*\n",
+    "\n",
+    "On souhaite ajouter une étape de test réalisée avec `make test`. Tester l'exécution du test (il ne doit pas renvoyer d'erreur) :"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "make test"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "slideshow": {
+     "slide_type": "slide"
+    }
+   },
+   "source": [
+    "Il faut ajouter le contenu suivant :\n",
+    "```yaml\n",
+    "test_hello:\n",
+    "  stage: test\n",
+    "  tags:\n",
+    "    - shell\n",
+    "  script:\n",
+    "    - make test\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "cat >> .gitlab-ci.yml <<- EOM\n",
+    "\n",
+    "test_hello:\n",
+    "  stage: test\n",
+    "  tags:\n",
+    "    - shell\n",
+    "  script:\n",
+    "    - make test\n",
+    "EOM"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "cat .gitlab-ci.yml"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "On enregistre, on pousse et on vérifie l'exécution de la chaîne d'intégration continue dans `CI / CD > Pipelines`\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "slideshow": {
+     "slide_type": "-"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "git add .gitlab-ci.yml\n",
+    "git commit -m \"Add a test stage to .gitlab-ci.yml\""
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "scrolled": true
+   },
+   "outputs": [],
+   "source": [
+    "git push"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### Provoquez des erreurs\n",
+    "\n",
+    "Modifier les fichiers\n",
+    "\n",
+    "\n",
+    "- de build : notez que le test n'est pas exécuté\n",
+    "- de test : le\n"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "Récupérer un artifact"
+   ]
   }
  ],
  "metadata": {
-- 
GitLab