162 lines
6.7 KiB
YAML
162 lines
6.7 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
|
|
needs: install
|
|
container:
|
|
image: registre.esy-web.dev/actions:latest
|
|
volumes:
|
|
- /var/run/docker.sock:/var/run/docker.sock
|
|
- /usr/bin/docker:/usr/bin/docker # Optional, but can help if docker binary isn't in path
|
|
env:
|
|
APP_ENV: test
|
|
MESSENGER_TRANSPORT_DSN: redis://host.docker.internal:15433/messages
|
|
DATABASE_URL: postgres://your_db_user:app_db_test@host.docker.internal:15432/symfony_user?serverVersion=16&charset=utf8
|
|
VAULT_SERVER: http://host.docker.internal:15434
|
|
VAULT_TOKEN: myroot
|
|
|
|
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: Prune previous Docker artifacts
|
|
run: |
|
|
docker rm -f vault-ci postgres-ci redis-ci || true
|
|
docker network rm ci-network || true
|
|
|
|
- name: Start services on Docker
|
|
run: |
|
|
docker network create ci-network
|
|
docker run -d --rm --network ci-network -p 15434:8200 --name vault-ci -e "VAULT_DEV_ROOT_TOKEN_ID=myroot" --cap-add=IPC_LOCK hashicorp/vault:latest vault server -dev
|
|
docker run -d --rm --network ci-network -p 15432:5432 --name postgres-ci -e "POSTGRES_DB=symfony_user" -e "POSTGRES_USER=your_db_user" -e "POSTGRES_PASSWORD=app_db_test" postgres:16
|
|
docker run -d --rm --network ci-network -p 15433:6379 --name redis-ci redis:latest
|
|
echo "Waiting for services to be ready..."
|
|
# --- Add PostgreSQL readiness check ---
|
|
echo "Checking PostgreSQL readiness..."
|
|
# Loop until PostgreSQL is ready to accept connections
|
|
# We use the internal container name (postgres-ci) and port (5432)
|
|
# The pg_isready command checks if the server is accepting connections
|
|
# -h: host, -p: port, -U: user, -d: database
|
|
# PGPASSWORD is used to provide the password non-interactively
|
|
DB_HOST="127.0.0.1"
|
|
DB_PORT="15432"
|
|
DB_USER="your_db_user"
|
|
DB_NAME="symfony_user"
|
|
DB_PASSWORD="app_db_test" # Use the actual password
|
|
|
|
# Install postgresql-client if pg_isready is not available in the runner image
|
|
# This is a common requirement for `pg_isready`
|
|
apt-get update && apt-get install -y postgresql-client || true # Install client tools, ignore if already installed
|
|
|
|
for i in $(seq 1 30); do # Try for up to 30 seconds (30 * 1 second sleep)
|
|
PGPASSWORD=$DB_PASSWORD pg_isready -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME
|
|
if [ $? -eq 0 ]; then
|
|
echo "PostgreSQL is ready!"
|
|
break
|
|
fi
|
|
echo "PostgreSQL not ready yet. Waiting..."
|
|
sleep 1
|
|
done
|
|
|
|
PGPASSWORD=$DB_PASSWORD pg_isready -h $DB_HOST -p $DB_PORT -U $DB_USER -d $DB_NAME
|
|
if [ $? -ne 0 ]; then
|
|
echo "PostgreSQL did not become ready in time. Exiting."
|
|
exit 1
|
|
fi
|
|
# --- End PostgreSQL readiness check ---
|
|
|
|
docker ps
|
|
|
|
- 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
|