feat: ci/cd
This commit is contained in:
+90
-52
@@ -1,78 +1,116 @@
|
||||
# ============================================================
|
||||
# CI — Intégration Continue
|
||||
# Se déclenche sur chaque push et chaque Pull Request.
|
||||
# Lance les tests PHPUnit avec SQLite en mémoire (rapide).
|
||||
# ============================================================
|
||||
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**' # tous les branches
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
jobs:
|
||||
test:
|
||||
name: 🧪 Tests Laravel (PHP ${{ matrix.php }})
|
||||
name: 🧪 Tests Laravel
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php: ['8.3'] # Ajoute d'autres versions si tu veux tester plusieurs PHP
|
||||
|
||||
steps:
|
||||
# ── 1. Récupère le code ─────────────────────────────────
|
||||
- name: 📥 Checkout du code
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# ── 2. Configure PHP avec les extensions nécessaires ────
|
||||
- name: 🐘 Setup PHP ${{ matrix.php }}
|
||||
- name: 🐘 Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: mbstring, bcmath, sqlite3, pdo_sqlite, pgsql, pdo_pgsql, xml, curl, zip, gd, intl
|
||||
coverage: none # met "xdebug" ici si tu veux du coverage
|
||||
php-version: '8.3'
|
||||
extensions: >
|
||||
bcmath,
|
||||
ctype,
|
||||
curl,
|
||||
dom,
|
||||
fileinfo,
|
||||
mbstring,
|
||||
openssl,
|
||||
pdo,
|
||||
tokenizer,
|
||||
xml,
|
||||
zip
|
||||
coverage: none
|
||||
|
||||
|
||||
# ── 3. Cache des dépendances Composer ───────────────────
|
||||
- name: 📦 Cache Composer
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: composer-${{ matrix.php }}-${{ hashFiles('composer.lock') }}
|
||||
restore-keys: composer-${{ matrix.php }}-
|
||||
path: ~/.composer/cache
|
||||
key: composer-${{ hashFiles('composer.lock') }}
|
||||
|
||||
# ── 4. Installe les dépendances PHP ─────────────────────
|
||||
- name: 📦 Installation Composer
|
||||
run: composer install --no-interaction --prefer-dist --optimize-autoloader --no-scripts
|
||||
|
||||
# ── 5. Prépare l'environnement .env de test ─────────────
|
||||
- name: ⚙️ Configuration .env
|
||||
- name: 📦 Install Composer dependencies
|
||||
run: |
|
||||
composer install \
|
||||
--no-interaction \
|
||||
--prefer-dist \
|
||||
--no-progress
|
||||
|
||||
|
||||
- name: ⚙️ Prepare Laravel
|
||||
run: |
|
||||
|
||||
cp .env.example .env
|
||||
# On écrase les variables critiques pour les tests
|
||||
echo "APP_ENV=testing" >> .env
|
||||
echo "APP_KEY=" >> .env
|
||||
echo "DB_CONNECTION=sqlite" >> .env
|
||||
echo "DB_DATABASE=:memory:" >> .env
|
||||
echo "QUEUE_CONNECTION=sync" >> .env
|
||||
echo "SESSION_DRIVER=array" >> .env
|
||||
echo "CACHE_STORE=array" >> .env
|
||||
echo "MAIL_MAILER=array" >> .env
|
||||
echo "BROADCAST_CONNECTION=null" >> .env
|
||||
|
||||
# ── 6. Génère la clé d'application ──────────────────────
|
||||
- name: 🔑 Génération de la clé APP_KEY
|
||||
run: php artisan key:generate --ansi
|
||||
php artisan key:generate
|
||||
|
||||
# ── 7. Exécute les migrations (SQLite :memory:) ─────────
|
||||
- name: 🗄️ Migrations
|
||||
run: php artisan migrate --force --ansi
|
||||
touch database/database.sqlite
|
||||
|
||||
# ── 8. Lance les tests ───────────────────────────────────
|
||||
- name: ✅ Tests PHPUnit
|
||||
run: php artisan test --ansi
|
||||
php artisan migrate --force
|
||||
|
||||
|
||||
- name: 🧪 Run PHPUnit
|
||||
run: |
|
||||
php artisan test
|
||||
|
||||
|
||||
|
||||
docker:
|
||||
|
||||
|
||||
name: 🐳 Build & Push Image
|
||||
|
||||
needs: test
|
||||
|
||||
if: github.ref == 'refs/heads/main'
|
||||
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
||||
steps:
|
||||
|
||||
|
||||
- name: 📥 Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
|
||||
|
||||
- name: 🔐 Login Registry Gitea
|
||||
run: |
|
||||
|
||||
docker login git.leonmorival.xyz \
|
||||
-u "${{ secrets.REGISTRY_USER }}" \
|
||||
-p "${{ secrets.REGISTRY_PASSWORD }}"
|
||||
|
||||
|
||||
|
||||
- name: 🏗️ Build image
|
||||
run: |
|
||||
|
||||
docker build \
|
||||
-t git.leonmorival.xyz/leonm/landing-api:latest \
|
||||
-t git.leonmorival.xyz/leonm/landing-api:${{ github.sha }} \
|
||||
.
|
||||
|
||||
|
||||
|
||||
- name: 📤 Push image
|
||||
run: |
|
||||
|
||||
docker push git.leonmorival.xyz/leonm/landing-api:latest
|
||||
|
||||
docker push git.leonmorival.xyz/leonm/landing-api:${{ github.sha }}
|
||||
|
||||
Reference in New Issue
Block a user