110 lines
3.0 KiB
YAML
110 lines
3.0 KiB
YAML
name: CI
|
||
|
||
on:
|
||
push:
|
||
branches:
|
||
- main
|
||
- develop
|
||
|
||
pull_request:
|
||
branches:
|
||
- main
|
||
- develop
|
||
jobs:
|
||
test:
|
||
name: 🧪 Tests Laravel
|
||
runs-on: ubuntu-latest
|
||
env:
|
||
DB_CONNECTION: sqlite
|
||
DB_DATABASE: database/database.sqlite
|
||
steps:
|
||
- name: 📥 Checkout
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- name: 🔒 Vérifier l’immutabilité des migrations
|
||
env:
|
||
EVENT_NAME: ${{ github.event_name }}
|
||
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
||
PUSH_BASE_SHA: ${{ github.event.before }}
|
||
run: |
|
||
case "$EVENT_NAME" in
|
||
pull_request) base_sha="$PR_BASE_SHA" ;;
|
||
push) base_sha="$PUSH_BASE_SHA" ;;
|
||
*) echo "Événement non supporté : $EVENT_NAME"; exit 1 ;;
|
||
esac
|
||
|
||
sh scripts/ci/check-migration-immutability.sh "$base_sha"
|
||
|
||
- name: 🐘 Setup PHP
|
||
uses: shivammathur/setup-php@v2
|
||
with:
|
||
php-version: '8.4'
|
||
extensions: bcmath,ctype,curl,dom,fileinfo,intl,mbstring,openssl,pdo,tokenizer,xml,zip
|
||
coverage: none
|
||
|
||
- name: Cache Composer
|
||
uses: actions/cache@v4
|
||
with:
|
||
path: ~/.composer/cache
|
||
key: composer-cache
|
||
|
||
- name: Install Composer dependencies
|
||
run: |
|
||
composer install \
|
||
--no-interaction \
|
||
--prefer-dist \
|
||
--no-progress
|
||
|
||
- name: ⚙️ Prepare Laravel
|
||
run: |
|
||
cp .env.example .env
|
||
php artisan key:generate
|
||
touch database/database.sqlite
|
||
php artisan migrate --force
|
||
|
||
|
||
- name: 🧪 Run PHPUnit
|
||
run: |
|
||
php artisan test
|
||
|
||
|
||
|
||
docker:
|
||
name: 🐳 Build & Push Images
|
||
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/daily-meal-api:latest \
|
||
-t git.leonmorival.xyz/leonm/daily-meal-api:${{ github.sha }} \
|
||
.
|
||
|
||
- name: 🏗️ Build database backup image
|
||
run: |
|
||
docker build \
|
||
-f docker/database-backup/Dockerfile \
|
||
-t git.leonmorival.xyz/leonm/daily-meal-postgres-tools:latest \
|
||
-t git.leonmorival.xyz/leonm/daily-meal-postgres-tools:${{ github.sha }} \
|
||
docker/database-backup
|
||
|
||
- name: 📤 Push images
|
||
run: |
|
||
docker push git.leonmorival.xyz/leonm/daily-meal-api:latest
|
||
docker push git.leonmorival.xyz/leonm/daily-meal-api:${{ github.sha }}
|
||
docker push git.leonmorival.xyz/leonm/daily-meal-postgres-tools:latest
|
||
docker push git.leonmorival.xyz/leonm/daily-meal-postgres-tools:${{ github.sha }}
|