From 4669dec359255bd4fa559b5a7eeac7048ddc8f5e Mon Sep 17 00:00:00 2001 From: Matthieu Date: Sun, 25 Jan 2026 12:02:20 +0100 Subject: [PATCH] chore : add versioning system and release script --- Inventory_frontend | 2 +- RELEASE.md | 138 ++++++++++++++++++++++++++++++++ VERSION | 1 + migratebdd.md | 7 +- scripts/release.sh | 195 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 339 insertions(+), 4 deletions(-) create mode 100644 RELEASE.md create mode 100644 VERSION create mode 100755 scripts/release.sh diff --git a/Inventory_frontend b/Inventory_frontend index b27662d..9423903 160000 --- a/Inventory_frontend +++ b/Inventory_frontend @@ -1 +1 @@ -Subproject commit b27662d2bcd1a36896c19332bd8ac8d7420b9d62 +Subproject commit 94239031d69be4bfa9dc4fe07d43404ce8b7a98c diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000..d962837 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,138 @@ +# Guide de Release + +## Versioning + +Le projet utilise le [Semantic Versioning](https://semver.org/) (SemVer) : `MAJOR.MINOR.PATCH` + +- **MAJOR** : Changements incompatibles avec les versions précédentes +- **MINOR** : Nouvelles fonctionnalités rétrocompatibles +- **PATCH** : Corrections de bugs rétrocompatibles + +La version est centralisée dans le fichier `VERSION` à la racine du projet. + +## Créer une release + +### Prérequis + +- Tous les changements doivent être commités +- Les tests doivent passer +- Être sur la branche à releaser (ex: `main`, `develop`) + +### Utilisation du script + +```bash +# Afficher l'aide et la version actuelle +./scripts/release.sh + +# Bump patch : 1.0.0 → 1.0.1 +./scripts/release.sh patch + +# Bump minor : 1.0.0 → 1.1.0 +./scripts/release.sh minor + +# Bump major : 1.0.0 → 2.0.0 +./scripts/release.sh major + +# Version spécifique +./scripts/release.sh 2.0.0 +``` + +Le script : +1. Met à jour le fichier `VERSION` +2. Met à jour `config/packages/api_platform.yaml` +3. Crée un commit `chore(release): vX.Y.Z` +4. Crée le tag `vX.Y.Z` + +### Pousser la release + +```bash +git push && git push --tags +``` + +### Créer la release sur Gitea + +1. Aller sur le dépôt Gitea +2. **Releases** > **New Release** +3. Sélectionner le tag `vX.Y.Z` +4. Titre : `v1.0.0` (ou avec un nom descriptif) +5. Description : résumé des changements (voir section Notes de release) + +## Notes de release + +Template pour les notes de release : + +```markdown +## Nouveautés +- Feature A +- Feature B + +## Corrections +- Fix du bug X +- Fix du bug Y + +## Changements +- Refactoring de Z +- Mise à jour des dépendances +``` + +## Fichiers impactés par le versioning + +| Fichier | Usage | +|---------|-------| +| `VERSION` | Source unique de vérité | +| `config/packages/api_platform.yaml` | Version affichée dans l'API | +| `Inventory_frontend/nuxt.config.ts` | Lit VERSION au build | +| Footer de l'app | Affiche `v{{ appVersion }}` | + +## Déploiement en production + +### 1. Base de données + +Dump de la base locale : +```bash +pg_dump -h localhost -p 5433 -U root -d inventory > backup_v1.0.0.sql +``` + +Import en production : +```bash +psql -h -U -d inventory < backup_v1.0.0.sql +``` + +### 2. Variables d'environnement production + +Créer un fichier `.env.local` en production avec : + +```env +APP_ENV=prod +APP_SECRET= +DATABASE_URL="postgresql://user:password@host:5432/inventory?serverVersion=16" +CORS_ALLOW_ORIGIN='^https://votre-domaine\.com$' +JWT_SECRET_KEY=%kernel.project_dir%/config/jwt/private.pem +JWT_PUBLIC_KEY=%kernel.project_dir%/config/jwt/public.pem +JWT_PASSPHRASE= +``` + +### 3. Build production + +Backend : +```bash +composer install --no-dev --optimize-autoloader +php bin/console cache:clear --env=prod +php bin/console doctrine:migrations:migrate --no-interaction +``` + +Frontend : +```bash +cd Inventory_frontend +NUXT_PUBLIC_API_BASE_URL=https://api.votre-domaine.com yarn build +``` + +### 4. Checklist avant mise en prod + +- [ ] Tests passent +- [ ] Migrations DB testées +- [ ] Variables d'environnement configurées +- [ ] Clés JWT générées +- [ ] CORS configuré +- [ ] SSL/HTTPS actif +- [ ] Backup de la DB prod existante (si upgrade) diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..3eefcb9 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0 diff --git a/migratebdd.md b/migratebdd.md index abdba05..65f3ae6 100644 --- a/migratebdd.md +++ b/migratebdd.md @@ -5,6 +5,7 @@ Ce guide explique comment importer un dump SQL venant de pgAdmin dans la base Do ## 1) Export pgAdmin Dans pgAdmin: + - Format: Plain - Options: Use INSERT commands + Use column inserts - Fichier: `data.sql` @@ -22,9 +23,9 @@ python3 scripts/normalize-dump.py data.sql data_norm.sql --lower Utilise `session_replication_role` pour eviter les erreurs de contraintes circulaires. ```bash -docker compose --env-file docker/.env.docker.local exec -T db psql -U $POSTGRES_USER -d $POSTGRES_DB -v ON_ERROR_STOP=1 -c "SET session_replication_role = replica;" -docker compose --env-file docker/.env.docker.local exec -T db psql -U $POSTGRES_USER -d $POSTGRES_DB -v ON_ERROR_STOP=1 < data_norm.sql -docker compose --env-file docker/.env.docker.local exec -T db psql -U $POSTGRES_USER -d $POSTGRES_DB -v ON_ERROR_STOP=1 -c "SET session_replication_role = DEFAULT;" +docker compose --env-file docker/.env.docker.local exec -T db psql -U root -d inventory -v ON_ERROR_STOP=1 -c "SET session_replication_role = replica;" +docker compose --env-file docker/.env.docker.local exec -T db psql -U root -d inventory -v ON_ERROR_STOP=1 < data_norm.sql +docker compose --env-file docker/.env.docker.local exec -T db psql -U root -d inventory -v ON_ERROR_STOP=1 -c "SET session_replication_role = DEFAULT;" ``` ## 4) Verifier diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..4548b95 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,195 @@ +#!/bin/bash +set -e + +# Couleurs pour l'affichage +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Répertoire racine du projet +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" +VERSION_FILE="$PROJECT_ROOT/VERSION" +API_PLATFORM_FILE="$PROJECT_ROOT/config/packages/api_platform.yaml" +FRONTEND_DIR="$PROJECT_ROOT/Inventory_frontend" + +# Lire la version actuelle +current_version=$(cat "$VERSION_FILE" | tr -d '\n') + +# Fonction pour afficher l'aide +show_help() { + echo -e "${BLUE}Usage:${NC} $0 [version|bump_type]" + echo "" + echo "Arguments:" + echo " version Version spécifique (ex: 1.2.3)" + echo " bump_type Type de bump: major, minor, patch" + echo "" + echo "Exemples:" + echo " $0 1.0.0 # Définit la version à 1.0.0" + echo " $0 patch # 1.0.0 -> 1.0.1" + echo " $0 minor # 1.0.0 -> 1.1.0" + echo " $0 major # 1.0.0 -> 2.0.0" + echo "" + echo -e "Version actuelle: ${GREEN}$current_version${NC}" +} + +# Fonction pour bumper la version +bump_version() { + local version=$1 + local bump_type=$2 + + IFS='.' read -r major minor patch <<< "$version" + + case $bump_type in + major) + major=$((major + 1)) + minor=0 + patch=0 + ;; + minor) + minor=$((minor + 1)) + patch=0 + ;; + patch) + patch=$((patch + 1)) + ;; + esac + + echo "$major.$minor.$patch" +} + +# Vérifier les arguments +if [ $# -eq 0 ]; then + show_help + exit 0 +fi + +arg=$1 + +# Déterminer la nouvelle version +case $arg in + major|minor|patch) + new_version=$(bump_version "$current_version" "$arg") + ;; + -h|--help|help) + show_help + exit 0 + ;; + *) + # Vérifier le format de version (semver basique) + if [[ $arg =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + new_version=$arg + else + echo -e "${RED}Erreur:${NC} Format de version invalide: $arg" + echo "Utilisez le format X.Y.Z (ex: 1.2.3) ou major/minor/patch" + exit 1 + fi + ;; +esac + +echo -e "${BLUE}Release v$new_version${NC}" +echo "================================" +echo -e "Version actuelle: ${YELLOW}$current_version${NC}" +echo -e "Nouvelle version: ${GREEN}$new_version${NC}" +echo "" + +# Vérifier qu'on n'est pas sur une version identique +if [ "$current_version" = "$new_version" ]; then + echo -e "${YELLOW}La version est déjà $new_version${NC}" + exit 0 +fi + +# Demander confirmation +read -p "Continuer ? (y/N) " -n 1 -r +echo +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Annulé." + exit 0 +fi + +cd "$PROJECT_ROOT" + +# =========================================== +# ÉTAPE 1 : Gérer le submodule frontend +# =========================================== +echo "" +echo -e "${BLUE}[1/6]${NC} Vérification du submodule frontend..." + +cd "$FRONTEND_DIR" + +# Vérifier s'il y a des changements non commités dans le submodule +if ! git diff --quiet --exit-code || ! git diff --cached --quiet --exit-code; then + echo -e "${YELLOW}Changements détectés dans le submodule frontend${NC}" + git status --short + echo "" + read -p "Commiter ces changements dans le submodule ? (y/N) " -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + git add -A + git commit -m "chore(release): prepare v$new_version" + else + echo -e "${RED}Erreur:${NC} Veuillez d'abord commiter les changements du submodule." + exit 1 + fi +fi + +# =========================================== +# ÉTAPE 2 : Tag le submodule +# =========================================== +echo -e "${BLUE}[2/6]${NC} Création du tag v$new_version dans le submodule..." + +# Vérifier si le tag existe déjà +if git rev-parse "v$new_version" >/dev/null 2>&1; then + echo -e "${YELLOW}Le tag v$new_version existe déjà dans le submodule${NC}" +else + git tag -a "v$new_version" -m "Release v$new_version" + echo -e "${GREEN}Tag v$new_version créé dans le submodule${NC}" +fi + +# Retourner au projet principal +cd "$PROJECT_ROOT" + +# =========================================== +# ÉTAPE 3 : Mettre à jour VERSION +# =========================================== +echo -e "${BLUE}[3/6]${NC} Mise à jour du fichier VERSION..." +echo "$new_version" > "$VERSION_FILE" + +# =========================================== +# ÉTAPE 4 : Mettre à jour api_platform.yaml +# =========================================== +echo -e "${BLUE}[4/6]${NC} Mise à jour de api_platform.yaml..." +sed -i "s/version: .*/version: $new_version/" "$API_PLATFORM_FILE" + +# =========================================== +# ÉTAPE 5 : Commit principal (avec mise à jour du submodule) +# =========================================== +echo -e "${BLUE}[5/6]${NC} Création du commit principal..." +git add "$VERSION_FILE" "$API_PLATFORM_FILE" "$FRONTEND_DIR" +git commit -m "chore(release): v$new_version" + +# =========================================== +# ÉTAPE 6 : Tag principal +# =========================================== +echo -e "${BLUE}[6/6]${NC} Création du tag v$new_version..." +git tag -a "v$new_version" -m "Release v$new_version" + +echo "" +echo -e "${GREEN}✓ Release v$new_version préparée avec succès !${NC}" +echo "" +echo "================================" +echo -e "${YELLOW}Prochaines étapes :${NC}" +echo "" +echo "1. Pousser le submodule frontend :" +echo -e " ${BLUE}cd Inventory_frontend && git push && git push --tags && cd ..${NC}" +echo "" +echo "2. Pousser le projet principal :" +echo -e " ${BLUE}git push && git push --tags${NC}" +echo "" +echo "3. Créer les releases sur Gitea :" +echo " - Inventory_frontend : tag v$new_version" +echo " - Inventory (backend) : tag v$new_version" +echo "" +echo "================================"