144 lines
4.9 KiB
YAML
144 lines
4.9 KiB
YAML
# Nom du workflow
|
|
name: Symfony CI - Install, Test, Build, Attest & Deploy
|
|
|
|
# Déclencheurs du workflow
|
|
on:
|
|
push:
|
|
branches:
|
|
- master # Ou 'main'
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
branches:
|
|
- master # Ou 'main'
|
|
|
|
# Permissions nécessaires pour les actions utilisées
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
id-token: write
|
|
attestations: write
|
|
security-events: write # Requis pour Snyk pour poster les résultats
|
|
|
|
jobs:
|
|
# =================================================================
|
|
# JOB 1: INSTALL - Installe les dépendances PHP et JS
|
|
# =================================================================
|
|
install:
|
|
name: 📦 Install Dependencies
|
|
runs-on: self-hosted
|
|
container:
|
|
image: registre.esy-web.dev/actions:latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup PHP and Composer
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: '8.3'
|
|
tools: symfony-cli
|
|
|
|
- name: Install Composer dependencies
|
|
run: composer install --no-suggest --no-interaction --prefer-dist
|
|
|
|
- name: Install Bun dependencies
|
|
run: |
|
|
if [ -f "package.json" ]; then
|
|
bun install
|
|
else
|
|
echo "Warning: No package.json found. Skipping Bun install."
|
|
fi
|
|
# =================================================================
|
|
# JOB 2: TEST - Lance les tests (unité, statique, sécurité)
|
|
# =================================================================
|
|
test:
|
|
name: 📦 Install Dependencies
|
|
runs-on: self-hosted
|
|
services:
|
|
postgres:
|
|
image: postgres:16
|
|
env:
|
|
POSTGRES_DB: symfony_user
|
|
POSTGRES_USER: your_db_user
|
|
POSTGRES_PASSWORD: app_db_test
|
|
redis:
|
|
image: redis:7
|
|
|
|
needs: install
|
|
container:
|
|
image: registre.esy-web.dev/actions:latest
|
|
|
|
env:
|
|
APP_ENV: test
|
|
MESSENGER_TRANSPORT_DSN: doctrine://default?auto_setup=0
|
|
DATABASE_URL: postgres://your_db_user:app_db_test@postgres:5432/symfony_user?serverVersion=16&charset=utf8
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup PHP and Composer
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: '8.3'
|
|
tools: symfony-cli
|
|
|
|
- name: Install Composer dependencies
|
|
run: composer install --no-suggest --no-interaction --prefer-dist
|
|
|
|
- name: Install Bun dependencies
|
|
run: |
|
|
if [ -f "package.json" ]; then
|
|
bun install
|
|
else
|
|
echo "Warning: No package.json found. Skipping Bun install."
|
|
fi
|
|
|
|
- name: Setup PHP for testing
|
|
uses: shivammathur/setup-php@v2
|
|
with:
|
|
php-version: '8.3'
|
|
extensions: fileinfo, intl, dom, pdo, pgsql, redis, opcache, bcmath, zip
|
|
tools: symfony-cli
|
|
coverage: pcov
|
|
|
|
- name: Create .env.test file
|
|
run: |
|
|
echo "APP_ENV=test" > .env.test
|
|
echo "DATABASE_URL=${{ env.DATABASE_URL }}" >> .env.test
|
|
# ... autres variables ...
|
|
|
|
- name: Create Test Database and Schema
|
|
run: |
|
|
php bin/console doctrine:database:create --if-not-exists --env=test
|
|
php bin/console doctrine:migrations:migrate --env=test --no-interaction --allow-no-migration
|
|
|
|
- name: Run PHP Security Checker
|
|
uses: symfonycorp/security-checker-action@v5
|
|
with:
|
|
lock: composer.lock
|
|
|
|
- name: Run PHPUnit Tests
|
|
run: php vendor/bin/phpunit --coverage-text
|
|
|
|
# - name: SonarQube Scan
|
|
# if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
# uses: SonarSource/sonarqube-scan-action@master
|
|
# env:
|
|
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
# SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
|
|
deploy:
|
|
name: 🚀 Deploy to Production
|
|
runs-on: self-hosted
|
|
needs: [test]
|
|
steps:
|
|
- name: Deploy with SSH & Ansible
|
|
uses: appleboy/ssh-action@v1.0.0
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: ${{ secrets.SSH_USER }}
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
port: 22
|
|
script: |
|
|
cd /var/www/mainframe/app && git pull && nohup sh ./update.sh
|