|
| 1 | +name: CI/CD Pipeline - ACFC Application |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +env: |
| 11 | + PYTHON_VERSION: '3.12' |
| 12 | + NODE_VERSION: '18' |
| 13 | + |
| 14 | +jobs: |
| 15 | + test-unit: |
| 16 | + name: Tests Unitaires |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout du code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Configuration Python |
| 24 | + uses: actions/setup-python@v4 |
| 25 | + with: |
| 26 | + python-version: ${{ env.PYTHON_VERSION }} |
| 27 | + |
| 28 | + - name: Cache des dépendances Python |
| 29 | + uses: actions/cache@v3 |
| 30 | + with: |
| 31 | + path: ~/.cache/pip |
| 32 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-*.txt') }} |
| 33 | + restore-keys: | |
| 34 | + ${{ runner.os }}-pip- |
| 35 | + |
| 36 | + - name: Installation des dépendances |
| 37 | + run: | |
| 38 | + python -m pip install --upgrade pip |
| 39 | + pip install -r requirements-test.txt |
| 40 | + pip install -r requirements-app.txt |
| 41 | + pip install -r requirements-api.txt |
| 42 | + |
| 43 | + - name: Vérification de la syntaxe Python |
| 44 | + run: | |
| 45 | + python -m py_compile app_acfc/**/*.py |
| 46 | + python -m py_compile api_acfc/**/*.py |
| 47 | + python -m py_compile tests/**/*.py |
| 48 | + |
| 49 | + - name: Tests unitaires avec pytest |
| 50 | + run: | |
| 51 | + pytest tests/unit/ -v --tb=short --cov=app_acfc --cov=api_acfc --cov-report=xml --cov-report=html |
| 52 | + |
| 53 | + - name: Upload des rapports de couverture |
| 54 | + uses: actions/upload-artifact@v3 |
| 55 | + with: |
| 56 | + name: coverage-reports-unit |
| 57 | + path: | |
| 58 | + coverage.xml |
| 59 | + htmlcov/ |
| 60 | + |
| 61 | + test-integration: |
| 62 | + name: Tests d'Intégration |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: test-unit |
| 65 | + |
| 66 | + services: |
| 67 | + mariadb: |
| 68 | + image: mariadb:10.6 |
| 69 | + env: |
| 70 | + MYSQL_ROOT_PASSWORD: test_password |
| 71 | + MYSQL_DATABASE: acfc_test |
| 72 | + MYSQL_USER: acfc_user |
| 73 | + MYSQL_PASSWORD: acfc_password |
| 74 | + ports: |
| 75 | + - 3306:3306 |
| 76 | + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 |
| 77 | + |
| 78 | + mongodb: |
| 79 | + image: mongo:5.0 |
| 80 | + env: |
| 81 | + MONGO_INITDB_ROOT_USERNAME: admin |
| 82 | + MONGO_INITDB_ROOT_PASSWORD: test_password |
| 83 | + MONGO_INITDB_DATABASE: acfc_test |
| 84 | + ports: |
| 85 | + - 27017:27017 |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Checkout du code |
| 89 | + uses: actions/checkout@v4 |
| 90 | + |
| 91 | + - name: Configuration Python |
| 92 | + uses: actions/setup-python@v4 |
| 93 | + with: |
| 94 | + python-version: ${{ env.PYTHON_VERSION }} |
| 95 | + |
| 96 | + - name: Installation des dépendances |
| 97 | + run: | |
| 98 | + python -m pip install --upgrade pip |
| 99 | + pip install -r requirements-test.txt |
| 100 | + pip install -r requirements-app.txt |
| 101 | + pip install -r requirements-api.txt |
| 102 | + |
| 103 | + - name: Attente des services |
| 104 | + run: | |
| 105 | + # Attendre que MariaDB soit prêt |
| 106 | + until mysqladmin ping -h 127.0.0.1 -P 3306 -u root -ptest_password --silent; do |
| 107 | + echo 'Attente de MariaDB...' |
| 108 | + sleep 2 |
| 109 | + done |
| 110 | + |
| 111 | + # Attendre que MongoDB soit prêt |
| 112 | + until mongo --host 127.0.0.1:27017 --eval "db.runCommand('ping').ok" --quiet; do |
| 113 | + echo 'Attente de MongoDB...' |
| 114 | + sleep 2 |
| 115 | + done |
| 116 | + |
| 117 | + - name: Initialisation de la base de données |
| 118 | + run: | |
| 119 | + python init_database.py |
| 120 | + env: |
| 121 | + DATABASE_URL: mysql://acfc_user:acfc_password@127.0.0.1:3306/acfc_test |
| 122 | + MONGODB_URL: mongodb://admin:test_password@127.0.0.1:27017/acfc_test |
| 123 | + |
| 124 | + - name: Tests d'intégration |
| 125 | + run: | |
| 126 | + pytest tests/integration/ -v --tb=short --cov-append --cov=app_acfc --cov=api_acfc |
| 127 | + env: |
| 128 | + DATABASE_URL: mysql://acfc_user:acfc_password@127.0.0.1:3306/acfc_test |
| 129 | + MONGODB_URL: mongodb://admin:test_password@127.0.0.1:27017/acfc_test |
| 130 | + FLASK_ENV: testing |
| 131 | + |
| 132 | + test-e2e: |
| 133 | + name: Tests End-to-End |
| 134 | + runs-on: ubuntu-latest |
| 135 | + needs: [test-unit, test-integration] |
| 136 | + |
| 137 | + steps: |
| 138 | + - name: Checkout du code |
| 139 | + uses: actions/checkout@v4 |
| 140 | + |
| 141 | + - name: Configuration Python |
| 142 | + uses: actions/setup-python@v4 |
| 143 | + with: |
| 144 | + python-version: ${{ env.PYTHON_VERSION }} |
| 145 | + |
| 146 | + - name: Configuration Node.js |
| 147 | + uses: actions/setup-node@v3 |
| 148 | + with: |
| 149 | + node-version: ${{ env.NODE_VERSION }} |
| 150 | + |
| 151 | + - name: Installation des dépendances Python |
| 152 | + run: | |
| 153 | + python -m pip install --upgrade pip |
| 154 | + pip install -r requirements-test.txt |
| 155 | + pip install -r requirements-app.txt |
| 156 | + pip install -r requirements-api.txt |
| 157 | + |
| 158 | + - name: Installation de Chrome pour les tests |
| 159 | + run: | |
| 160 | + sudo apt-get update |
| 161 | + sudo apt-get install -y google-chrome-stable |
| 162 | + |
| 163 | + - name: Tests End-to-End |
| 164 | + run: | |
| 165 | + pytest tests/e2e/ -v --tb=short |
| 166 | + |
| 167 | + security-scan: |
| 168 | + name: Analyse de Sécurité |
| 169 | + runs-on: ubuntu-latest |
| 170 | + needs: test-unit |
| 171 | + |
| 172 | + steps: |
| 173 | + - name: Checkout du code |
| 174 | + uses: actions/checkout@v4 |
| 175 | + |
| 176 | + - name: Configuration Python |
| 177 | + uses: actions/setup-python@v4 |
| 178 | + with: |
| 179 | + python-version: ${{ env.PYTHON_VERSION }} |
| 180 | + |
| 181 | + - name: Installation de bandit |
| 182 | + run: | |
| 183 | + python -m pip install bandit[toml] |
| 184 | + |
| 185 | + - name: Scan de sécurité avec Bandit |
| 186 | + run: | |
| 187 | + bandit -r app_acfc/ api_acfc/ -f json -o bandit-report.json |
| 188 | + bandit -r app_acfc/ api_acfc/ -f txt |
| 189 | + |
| 190 | + - name: Upload du rapport Bandit |
| 191 | + uses: actions/upload-artifact@v3 |
| 192 | + if: always() |
| 193 | + with: |
| 194 | + name: security-report |
| 195 | + path: bandit-report.json |
| 196 | + |
| 197 | + code-quality: |
| 198 | + name: Qualité du Code |
| 199 | + runs-on: ubuntu-latest |
| 200 | + |
| 201 | + steps: |
| 202 | + - name: Checkout du code |
| 203 | + uses: actions/checkout@v4 |
| 204 | + |
| 205 | + - name: Configuration Python |
| 206 | + uses: actions/setup-python@v4 |
| 207 | + with: |
| 208 | + python-version: ${{ env.PYTHON_VERSION }} |
| 209 | + |
| 210 | + - name: Installation des outils de qualité |
| 211 | + run: | |
| 212 | + python -m pip install --upgrade pip |
| 213 | + pip install flake8 black isort mypy pylint |
| 214 | + |
| 215 | + - name: Vérification du formatage avec Black |
| 216 | + run: | |
| 217 | + black --check --diff app_acfc/ api_acfc/ tests/ |
| 218 | + |
| 219 | + - name: Vérification des imports avec isort |
| 220 | + run: | |
| 221 | + isort --check-only --diff app_acfc/ api_acfc/ tests/ |
| 222 | + |
| 223 | + - name: Analyse avec Flake8 |
| 224 | + run: | |
| 225 | + flake8 app_acfc/ api_acfc/ tests/ --max-line-length=100 --extend-ignore=E203,W503 |
| 226 | + |
| 227 | + - name: Analyse avec Pylint |
| 228 | + run: | |
| 229 | + pylint app_acfc/ api_acfc/ --output-format=json > pylint-report.json || true |
| 230 | + pylint app_acfc/ api_acfc/ --output-format=text |
| 231 | + |
| 232 | + - name: Upload du rapport Pylint |
| 233 | + uses: actions/upload-artifact@v3 |
| 234 | + if: always() |
| 235 | + with: |
| 236 | + name: pylint-report |
| 237 | + path: pylint-report.json |
| 238 | + |
| 239 | + build-docker: |
| 240 | + name: Build Images Docker |
| 241 | + runs-on: ubuntu-latest |
| 242 | + needs: [test-unit, test-integration] |
| 243 | + |
| 244 | + steps: |
| 245 | + - name: Checkout du code |
| 246 | + uses: actions/checkout@v4 |
| 247 | + |
| 248 | + - name: Configuration Docker Buildx |
| 249 | + uses: docker/setup-buildx-action@v3 |
| 250 | + |
| 251 | + - name: Build de l'image Application |
| 252 | + run: | |
| 253 | + docker build -f app_acfc/dockerfile.app -t acfc-app:${{ github.sha }} . |
| 254 | + |
| 255 | + - name: Build de l'image API |
| 256 | + run: | |
| 257 | + docker build -f api_acfc/dockerfile.api -t acfc-api:${{ github.sha }} . |
| 258 | + |
| 259 | + - name: Build de l'image MariaDB |
| 260 | + run: | |
| 261 | + docker build -f mariadb/dockerfile.mariadb -t acfc-mariadb:${{ github.sha }} . |
| 262 | + |
| 263 | + - name: Test des images Docker |
| 264 | + run: | |
| 265 | + # Test de l'image app |
| 266 | + docker run --rm acfc-app:${{ github.sha }} python -c "import app_acfc; print('App OK')" |
| 267 | + |
| 268 | + # Test de l'image API |
| 269 | + docker run --rm acfc-api:${{ github.sha }} python -c "import api_acfc; print('API OK')" |
| 270 | + |
| 271 | + test-demo: |
| 272 | + name: Tests de Démonstration |
| 273 | + runs-on: ubuntu-latest |
| 274 | + if: github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, '[demo]') |
| 275 | + |
| 276 | + steps: |
| 277 | + - name: Checkout du code |
| 278 | + uses: actions/checkout@v4 |
| 279 | + |
| 280 | + - name: Configuration Python |
| 281 | + uses: actions/setup-python@v4 |
| 282 | + with: |
| 283 | + python-version: ${{ env.PYTHON_VERSION }} |
| 284 | + |
| 285 | + - name: Installation des dépendances |
| 286 | + run: | |
| 287 | + python -m pip install --upgrade pip |
| 288 | + pip install -r requirements-test.txt |
| 289 | + pip install -r requirements-app.txt |
| 290 | + |
| 291 | + - name: Tests de démonstration |
| 292 | + run: | |
| 293 | + pytest tests/demo/ -v -s --tb=short |
| 294 | + |
| 295 | + deploy-staging: |
| 296 | + name: Déploiement Staging |
| 297 | + runs-on: ubuntu-latest |
| 298 | + needs: [test-unit, test-integration, test-e2e, security-scan, code-quality, build-docker] |
| 299 | + if: github.ref == 'refs/heads/develop' && github.event_name == 'push' |
| 300 | + environment: staging |
| 301 | + |
| 302 | + steps: |
| 303 | + - name: Checkout du code |
| 304 | + uses: actions/checkout@v4 |
| 305 | + |
| 306 | + - name: Déploiement vers Staging |
| 307 | + run: | |
| 308 | + echo "Déploiement vers l'environnement de staging" |
| 309 | + # Ici, ajouter les commandes de déploiement spécifiques |
| 310 | + # Par exemple : docker-compose up -d, kubectl apply, etc. |
| 311 | + |
| 312 | + deploy-production: |
| 313 | + name: Déploiement Production |
| 314 | + runs-on: ubuntu-latest |
| 315 | + needs: [test-unit, test-integration, test-e2e, security-scan, code-quality, build-docker] |
| 316 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 317 | + environment: production |
| 318 | + |
| 319 | + steps: |
| 320 | + - name: Checkout du code |
| 321 | + uses: actions/checkout@v4 |
| 322 | + |
| 323 | + - name: Déploiement vers Production |
| 324 | + run: | |
| 325 | + echo "Déploiement vers l'environnement de production" |
| 326 | + # Ici, ajouter les commandes de déploiement spécifiques |
| 327 | + |
| 328 | + cleanup: |
| 329 | + name: Nettoyage |
| 330 | + runs-on: ubuntu-latest |
| 331 | + needs: [deploy-staging, deploy-production] |
| 332 | + if: always() |
| 333 | + |
| 334 | + steps: |
| 335 | + - name: Nettoyage des artefacts temporaires |
| 336 | + run: | |
| 337 | + echo "Nettoyage des ressources temporaires" |
| 338 | + # Commandes de nettoyage si nécessaire |
0 commit comments