Files
test-cicd/.woodpecker/build-pipeline.yml
spassignat 10dd888152
All checks were successful
ci/woodpecker/push/build-pipeline Pipeline was successful
patch: pipeline id
2026-05-03 16:10:48 +02:00

223 lines
7.8 KiB
YAML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
when:
- event: push
branch: [ main ]
- event: pull_request
- event: manual
variables:
- &node_image node:18-alpine
- &git_image alpine/git
- &curl_image curlimages/curl:latest
steps:
# Étape 1: Nettoyage du projet
- name: clean_project
image: *git_image
commands: |
echo "1 $CI_WORKSPACE"
rm -rf dist
rm -f $CI_WORKSPACE/build/version.env
echo "✅ Nettoyage terminé"
depends_on: [ ]
# Étape 2: Analyser le message du commit
- name: prepare
image: *git_image
commands: |
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "📝 Message: $COMMIT_MSG"
if echo "$COMMIT_MSG" | grep -qE "^(major)(\(.*\))?!:"; then
echo "version_type=major" >> $CI_WORKSPACE/version.env
echo "🔴 MAJOR - Breaking change"
elif echo "$COMMIT_MSG" | grep -qE "^(minor)(\(.*\))?:"; then
echo "version_type=minor" >> $CI_WORKSPACE/version.env
echo "🟡 MINOR - Nouvelle fonctionnalité"
elif echo "$COMMIT_MSG" | grep -qE "^(patch)(\(.*\))?:"; then
echo "version_type=patch" >> $CI_WORKSPACE/version.env
echo "🟢 PATCH - Correction"
else
echo "version_type=none" >> $CI_WORKSPACE/version.env
echo "⚠️ Aucun changement de version"
fi
echo "build_dir=$CI_WORKSPACE/build" >> $CI_WORKSPACE/version.env
depends_on: [ clean_project ]
# Étape 3: Mettre à jour la version
- name: update_version
image: *node_image
commands: |
source $CI_WORKSPACE/version.env
npm ci --cache .npm --prefer-offline
if [ "$version_type" != "none" ]; then
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "📦 Version actuelle: $CURRENT_VERSION"
npm run update:$version_type
NEW_VERSION=$(node -p "require('./package.json').version")
echo "🆕 Nouvelle version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $CI_WORKSPACE/version.env
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $CI_WORKSPACE/version.env
echo "ARTIFACT=$CI_REPO_NAME-$NEW_VERSION" >> $CI_WORKSPACE/version.env
else
echo "ARTIFACT=no-artifact" >> $CI_WORKSPACE/version.env
echo "⏭️ Pas de mise à jour de version"
fi
depends_on: [ prepare ]
# Étape 4: Build de l'application
- name: build
image: *node_image
commands:
- npm ci --cache .npm --prefer-offline
- npm run build
depends_on: [ update_version ]
# Étape 5: Package des artefacts
- name: package
image: *node_image
commands: |
source $CI_WORKSPACE/version.env
ARTIFACT_PATH=$CI_WORKSPACE/artifacts/$NEW_VERSION
ARTIFACT_FILE=$CI_WORKSPACE/artifacts/$ARTIFACT.tar.gz
echo "ARTIFACT_PATH=$ARTIFACT_PATH" >> $CI_WORKSPACE/version.env
echo "ARTIFACT_FILE=$ARTIFACT_FILE" >> $CI_WORKSPACE/version.env
if [ "$version_type" != "none" ]; then
mkdir -p $ARTIFACT_PATH
# Créer les archives individuelles
tar -czf $ARTIFACT_PATH/front.tar.gz -C frontend/dist . 2>/dev/null || echo "⚠️ frontend/dist vide"
tar -czf $ARTIFACT_PATH/back.tar.gz -C backend/dist . 2>/dev/null || echo "⚠️ backend/dist vide"
tar -czf $ARTIFACT_PATH/db.tar.gz -C database src *.json 2>/dev/null || echo "⚠️ database vide"
# Créer l'artefact final
cd $ARTIFACT_PATH
tar -cf $ARTIFACT_FILE .
echo "✅ Artefact créé: $ARTIFACT_FILE"
ls -la $ARTIFACT_PATH
fi
ls -als
depends_on: [ build ]
# Étape 6: Publication dans Nexus
- name: publish
image: *curl_image
environment:
NEXUS_USERNAME:
from_secret: nexus_username
NEXUS_PASSWORD:
from_secret: nexus_password
NEXUS_REPOSITORY: domaine-passignat
commands: |
source $CI_WORKSPACE/version.env
if [ "$version_type" != "none" ]; then
echo "📦 Publication de la version $NEW_VERSION : $ARTIFACT"
if [ ! -f "$ARTIFACT_FILE" ]; then
echo "❌ Fichier introuvable: $ARTIFACT_FILE"
ls -la $ARTIFACT_FILE
exit 1
fi
curl -v --fail \
-u "$NEXUS_USERNAME:$NEXUS_PASSWORD" \
-F "raw.directory=apps/$CI_REPO_NAME/$NEW_VERSION" \
-F "raw.asset1=@$ARTIFACT_FILE" \
-F "raw.asset1.filename=$ARTIFACT" \
http://nexus.cicd.exygen.fr/service/rest/v1/components?repository=$NEXUS_REPOSITORY
echo "✅ Artefact publié"
else
echo "⏭️ Pas de publication (version_type=none)"
fi
depends_on: [ package ]
# Étape 7: Commit et tag (après publication)
- name: commit_tag
image: *git_image
environment:
GITEA_TOKEN:
from_secret: gitea_token
commands: |
source $CI_WORKSPACE/version.env
if [ "$version_type" != "none" ]; then
git remote set-url origin http://oauth2:$GITEA_TOKEN@gitea.cicd.exygen.fr/$CI_REPO_OWNER/$CI_REPO_NAME.git
git config user.email "woodpecker@exygen.fr"
git config user.name "Woodpecker CI"
git add package.json ./database/src/sql/*.sql 2>/dev/null || true
# Commiter uniquement s'il y a des changements
if ! git diff --cached --quiet; then
git commit -m "chore: release v$NEW_VERSION [skip ci]"
git push origin main
echo "✅ Commit créé"
else
echo " Aucun changement à commiter"
fi
# Créer et pousser le tag
git tag -a "v$NEW_VERSION" -m "Release version v$NEW_VERSION"
git push origin "v$NEW_VERSION"
echo "🏷️ Tag v$NEW_VERSION créé et poussé"
else
echo "⚠️ Aucun changement à commiter"
fi
ls -als
depends_on: [ publish ]
# Étape 8: Déclencher le déploiement
- name: trigger-deployment
image: curlimages/curl:latest
environment:
WOODPECKER_TOKEN:
from_secret: woodpecker_token
commands: |
source $CI_WORKSPACE/version.env
if [ "$version_type" != "none" ]; then
echo "🚀 Déclenchement du déploiement pour la version $NEW_VERSION"
echo "🚀 $CI_REPO_OWNER"
echo "🚀 $CI_REPO_NAME"
echo "http://woodpecker.cicd.exygen.fr/api/repos/$CI_REPO_OWNER/$CI_REPO_NAME/pipelines"
curl -v --fail -X POST \
"http://woodpecker.cicd.exygen.fr/api/repos/$CI_REPO_OWNER/$CI_REPO_NAME/pipelines" \
-H "Authorization: Bearer $WOODPECKER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"branch": "main",
"event": "deployment",
"deploy_to": "production",
"deploy_id": "'$CI_PIPELINE_NUMBER'",
"ref": "refs/tags/v'$NEW_VERSION'"
}'
echo "✅ Événement deployment déclenché"
else
echo "⏭️ Pas de déclenchement (version_type=none)"
fi
depends_on: [ commit_tag ]
- name: trigger-deployment2
image: woodpeckerci/plugin-trigger
settings:
# L'URL de votre serveur Woodpecker
server: https://woodpecker.cicd.exygen.fr
# Le token d'API (doit être stocké comme secret)
branche: main
deploy_pipeline: ${CI_PIPELINE_NUMBER}
token:
from_secret: woodpecker_token
# Le dépôt cible, avec la branche optionnelle (format propriétaire/répertoire[@branche])
repo: domaine-passignat/gestion
# Paramètre CLÉ : active l'événement 'deployment' et spécifie l'environnement cible
deploy_to: production
# (Optionnel) Transmettre des variables au pipeline déclenché (ex: une version)
params:
- VERSION=${NEW_VERSION}
# (Optionnel) Attendre la fin du pipeline déclenché
wait: true
# Déclenche cette étape uniquement après une publication réussie
depends_on: [ commit_tag ]