patch: test 25
Some checks failed
ci/woodpecker/push/build-pipeline Pipeline failed

This commit is contained in:
spassignat
2026-05-02 12:29:18 +02:00
parent 738255a440
commit 6b3edd7429

View File

@@ -1,6 +1,6 @@
when: when:
- event: push - event: push
branch: [ main ] # ← Les tags ne sont sur aucune "branch" branch: [ main ]
- event: pull_request - event: pull_request
- event: manual - event: manual
@@ -10,90 +10,91 @@ variables:
- &curl_image curlimages/curl:latest - &curl_image curlimages/curl:latest
steps: steps:
# Étape 1: Nettoyage du projet, à ajuster # Étape 1: Nettoyage du projet
- name: clean_project - name: clean_project
image: *git_image image: *git_image
commands: | commands: |
rm -rf dist rm -rf dist
mkdir *wdir rm -f ${CI_WORKSPACE}/version.env
ls *wdir echo "✅ Nettoyage terminé"
rm -f *wdir/version.env depends_on: [ ]
# Étape 2: Analyser le message du commit
- name: prepare - name: prepare
image: *git_image image: *git_image
commands: | commands: |
# Récupérer le message du commit
COMMIT_MSG=$(git log -1 --pretty=%B) COMMIT_MSG=$(git log -1 --pretty=%B)
echo "📝 Message: $COMMIT_MSG" echo "📝 Message: $COMMIT_MSG"
# Déterminer le type de version
if echo "$COMMIT_MSG" | grep -qE "^(major)(\(.*\))?!:"; then if echo "$COMMIT_MSG" | grep -qE "^(major)(\(.*\))?!:"; then
echo "version_type=major" >> $CI_WORKSPACE/version.env echo "version_type=major" >> ${CI_WORKSPACE}/version.env
echo "🔴 MAJOR - Breaking change" echo "🔴 MAJOR - Breaking change"
elif echo "$COMMIT_MSG" | grep -qE "^(minor)(\(.*\))?:"; then elif echo "$COMMIT_MSG" | grep -qE "^(minor)(\(.*\))?:"; then
echo "version_type=minor" >> $CI_WORKSPACE/version.env echo "version_type=minor" >> ${CI_WORKSPACE}/version.env
echo "🟡 MINOR - Nouvelle fonctionnalité" echo "🟡 MINOR - Nouvelle fonctionnalité"
elif echo "$COMMIT_MSG" | grep -qE "^(patch)(\(.*\))?:"; then elif echo "$COMMIT_MSG" | grep -qE "^(patch)(\(.*\))?:"; then
echo "version_type=patch" >> $CI_WORKSPACE/version.env echo "version_type=patch" >> ${CI_WORKSPACE}/version.env
echo "🟢 PATCH - Correction" echo "🟢 PATCH - Correction"
else else
echo "version_type=none" >> $CI_WORKSPACE/version.env echo "version_type=none" >> ${CI_WORKSPACE}/version.env
echo "⚠️ Aucun changement de version" echo "⚠️ Aucun changement de version"
fi fi
depends_on: [ clean_project ] depends_on: [ clean_project ]
# Étape 4: Mettre à jour la version (seulement si nécessaire) # Étape 3: Mettre à jour la version
- name: update_version - name: update_version
image: *node_image image: *node_image
commands: | commands: |
ls -alsR database
mkdir -p database/src/sql
npm ci --cache .npm --prefer-offline npm ci --cache .npm --prefer-offline
source $CI_WORKSPACE/version.env source ${CI_WORKSPACE}/version.env
if [ "$version_type" != "none" ]; then if [ "$version_type" != "none" ]; then
CURRENT_VERSION=$(node -p "require('./package.json').version") CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "📦 Version actuelle: $CURRENT_VERSION" echo "📦 Version actuelle: $CURRENT_VERSION"
npm run update:$version_type npm run update:$version_type
NEW_VERSION=$(node -p "require('./package.json').version") NEW_VERSION=$(node -p "require('./package.json').version")
echo "🆕 Nouvelle version: $NEW_VERSION" echo "🆕 Nouvelle version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $CI_WORKSPACE/version.env echo "NEW_VERSION=$NEW_VERSION" >> ${CI_WORKSPACE}/version.env
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $CI_WORKSPACE/version.env echo "CURRENT_VERSION=$CURRENT_VERSION" >> ${CI_WORKSPACE}/version.env
echo "artifact=${CI_REPO_NAME}-$NEW_VERSION.tar" >> $CI_WORKSPACE/version.env echo "artifact=${CI_REPO_NAME}-$NEW_VERSION.tar" >> ${CI_WORKSPACE}/version.env
else else
echo "artifact=no-artifact" >> $CI_WORKSPACE/version.env echo "artifact=no-artifact" >> ${CI_WORKSPACE}/version.env
echo "⏭️ Pas de mise à jour de version" echo "⏭️ Pas de mise à jour de version"
fi fi
depends_on: [ prepare ] depends_on: [ prepare ]
# Étape 1: Installation des dépendances # Étape 4: Build de l'application
- name: build - name: build
image: *node_image image: *node_image
commands: commands: |
- npm ci --cache .npm --prefer-offline npm ci --cache .npm --prefer-offline
- npm run build npm run build
depends_on: [ update_version ] depends_on: [ update_version ]
# Étape 5: Package des artefacts
# Étape 6: Package des artefacts
- name: package - name: package
image: *curl_image image: *node_image
commands: | commands: |
more $CI_WORKSPACE/version.env source ${CI_WORKSPACE}/version.env
source $CI_WORKSPACE/version.env
if [ "$version_type" != "none" ]; then if [ "$version_type" != "none" ]; then
WDIR=${CI_WORKSPACE}/artifacts/$NEW_VERSION mkdir -p ${CI_WORKSPACE}/artifacts/${NEW_VERSION}
echo "create work directory: $WDIR"
mkdir -p $WDIR # Créer les archives individuelles
ls -alsR tar -czf ${CI_WORKSPACE}/artifacts/${NEW_VERSION}/front.tar.gz -C frontend/dist . 2>/dev/null || echo "⚠️ frontend/dist vide"
tar -czf $WDIR/db.tar.gz -C database . tar -czf ${CI_WORKSPACE}/artifacts/${NEW_VERSION}/back.tar.gz -C backend/dist . 2>/dev/null || echo "⚠️ backend/dist vide"
echo "create final artifact: ${CI_WORKSPACE}/artifacts/$artifact" tar -czf ${CI_WORKSPACE}/artifacts/${NEW_VERSION}/db.tar.gz -C database src *.json 2>/dev/null || echo "⚠️ database vide"
tar -cf ${CI_WORKSPACE}/artifacts/$artifact -C $WDIR .
ls -als ${CI_WORKSPACE}/artifacts/$artifact # Créer l'artefact final
cd ${CI_WORKSPACE}/artifacts/${NEW_VERSION}
tar -cf ${CI_WORKSPACE}/artifacts/${artifact} .
echo "✅ Artefact créé: ${CI_WORKSPACE}/artifacts/${artifact}"
ls -la ${CI_WORKSPACE}/artifacts/${artifact}
fi fi
ls -als ${CI_WORKSPACE}/artifacts/
depends_on: [ build ] depends_on: [ build ]
# Étape 6: Publication dans Nexus
- name: publish - name: publish
image: *curl_image image: *curl_image
environment: environment:
@@ -102,66 +103,92 @@ steps:
NEXUS_PASSWORD: NEXUS_PASSWORD:
from_secret: nexus_password from_secret: nexus_password
commands: | commands: |
source $CI_WORKSPACE/version.env source ${CI_WORKSPACE}/version.env
echo "📦 Publication de la version $NEW_VERSION : $artifact"
ls -alsR ${CI_WORKSPACE}/artifacts if [ "$version_type" != "none" ]; then
ARTIFACT_PATH="${CI_WORKSPACE}/artifacts/${artifact}"
curl -v \
-u ${NEXUS_USERNAME}:${NEXUS_PASSWORD} \ echo "📦 Publication de la version ${NEW_VERSION} : ${artifact}"
-F "raw.directory=apps" \
-F "raw.asset1=@${CI_WORKSPACE}/artifacts/$artifact" \ if [ ! -f "${ARTIFACT_PATH}" ]; then
-F "raw.asset1.filename=$artifact" \ echo "❌ Fichier introuvable: ${ARTIFACT_PATH}"
http://nexus/service/rest/v1/components?repository=domaine-passignat ls -la ${CI_WORKSPACE}/artifacts/
exit 1
fi
curl -v \
-u "${NEXUS_USERNAME}:${NEXUS_PASSWORD}" \
-F "raw.directory=apps/${CI_REPO_NAME}/${NEW_VERSION}" \
-F "raw.asset1=@${ARTIFACT_PATH}" \
-F "raw.asset1.filename=${artifact}" \
https://nexus.cicd.exygen.fr/service/rest/v1/components?repository=domaine-passignat
echo "✅ Artefact publié"
else
echo "⏭️ Pas de publication (version_type=none)"
fi
depends_on: [ package ] depends_on: [ package ]
# Étape 5: Commit et tag
# Étape 7: Commit et tag (après publication)
- name: commit_tag - name: commit_tag
image: *git_image image: *git_image
environment: environment:
GITEA_TOKEN: GITEA_TOKEN:
from_secret: gitea_token from_secret: gitea_token
commands: | commands: |
# Charger les variables source ${CI_WORKSPACE}/version.env
more $CI_WORKSPACE/version.env
source $CI_WORKSPACE/version.env
echo "version type: $version_type"
if [ "$version_type" != "none" ]; then if [ "$version_type" != "none" ]; then
echo "http://oauth2:$GITEA_TOKEN@gitea.cicd.exygen.fr/${CI_REPO_OWNER}/${CI_REPO_NAME}.git" git remote set-url origin http://oauth2:${GITEA_TOKEN}@gitea.cicd.exygen.fr/${CI_REPO_OWNER}/${CI_REPO_NAME}.git
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.email "woodpecker@exygen.fr"
git config user.name "Woodpecker CI" git config user.name "Woodpecker CI"
# Ajouter le remote avec token git add package.json ./database/src/sql/*.sql 2>/dev/null || true
# Ajouter le package.json modifié # Commiter uniquement s'il y a des changements
git add ./database/src/sql/*.sql 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
# Vérifier s'il y a des changements # Créer et pousser le tag
# if ! git diff --cached --quiet; then git tag -a "v${NEW_VERSION}" -m "Release version v${NEW_VERSION}"
# Commiter la nouvelle version git push origin "v${NEW_VERSION}"
git commit -m "Pipeline: update current version v$NEW_VERSION [skip ci]" echo "🏷️ Tag v${NEW_VERSION} créé et poussé"
git push origin main
echo "✅ Commit new version"
# Créer 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 created and pushed"
else else
echo "⚠️ Aucun changement à commiter" echo "⚠️ Aucun changement à commiter"
fi fi
depends_on: [ publish ] depends_on: [ publish ]
# Étape 8: Déclencher le déploiement
- name: trigger-deployment - name: trigger-deployment
image: woodpeckerci/plugin-trigger:latest image: curlimages/curl:latest
settings: environment:
token: WOODPECKER_TOKEN:
from_secret: woodpecker_token from_secret: woodpecker_token
server: https://woodpecker.cicd.exygen.fr # ← Ajoute l'URL du serveur commands: |
repo: ${CI_REPO_OWNER}/${CI_REPO_NAME} source ${CI_WORKSPACE}/version.env
branch: main
event: deployment if [ "$version_type" != "none" ]; then
deploy_id: ${CI_PIPELINE_NUMBER} # ← Peut être optionnel echo "🚀 Déclenchement du déploiement pour la version ${NEW_VERSION}"
deploy_to: production # ← Renommé en "environment" parfois
wait: true # ← Attend la fin du déploiement curl -X POST \
depends_on: [ publish ] "https://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 ]