Files
test-cicd/.woodpecker/build-pipeline.yml
spassignat d3cbe95e3a
Some checks failed
ci/woodpecker/push/build-pipeline Pipeline failed
patch: test 9
2026-05-02 11:11:38 +02:00

168 lines
6.0 KiB
YAML

when:
- event: push
branch: [ main ] # ← Les tags ne sont sur aucune "branch"
- event: pull_request
- event: manual
variables:
- &node_image node:18-alpine
- &git_image alpine/git
steps:
# Étape 1: Nettoyage du projet, à ajuster
- name: clean_project
image: *git_image
commands: |
rm -rf dist
rm -f $CI_WORKSPACE/version.env
- name: prepare
image: *git_image
commands: |
# Récupérer le message du commit
COMMIT_MSG=$(git log -1 --pretty=%B)
echo "📝 Message: $COMMIT_MSG"
# Déterminer le type de version
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
depends_on: [ clean_project ]
# Étape 4: Mettre à jour la version (seulement si nécessaire)
- name: update_version
image: *node_image
commands: |
ls -alsR database
npm ci --cache .npm --prefer-offline
source $CI_WORKSPACE/version.env
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.tar" >> $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 1: Installation des dépendances
- name: build
image: *node_image
commands:
- npm ci --cache .npm --prefer-offline
- npm run build
depends_on: [ update_version ]
# Étape 6: Package des artefacts
- name: package
image: *node_image
commands: |
more $CI_WORKSPACE/version.env
source $CI_WORKSPACE/version.env
if [ "$version_type" != "none" ]; then
WDIR=${CI_WORKSPACE}/artifacts/$NEW_VERSION
echo "create work directory: $WDIR"
mkdir -p $WDIR
echo "create front artifact: $WDIR/front.tar.gz"
tar -czf $WDIR/front.tar.gz -C frontend/dist .
echo "create back artifact: $WDIR/back.tar.gz"
tar -czf $WDIR/back.tar.gz -C backend/dist .
echo "create db artifact: $WDIR/db.tar.gz"
tar -czf $WDIR/db.tar.gz -C database src *.json
echo "create final artifact: ${CI_WORKSPACE}/artifacts/$artifact"
ls -als ${CI_WORKSPACE}/artifacts/$artifact
tar -cf ${CI_WORKSPACE}/artifacts/$artifact -C $WDIR .
fi
ls -als ${CI_WORKSPACE}/artifacts/
depends_on: [ build ]
- name: publish
image: curlimages/curl:latest
environment:
NEXUS_USERNAME:
from_secret: nexus_username
NEXUS_PASSWORD:
from_secret: nexus_password
commands: |
source $CI_WORKSPACE/version.env
echo "📦 Publication de la version $NEW_VERSION : $artifact"
ls -als ${CI_WORKSPACE}/artifacts/$artifact
curl -v \
-u ${NEXUS_USERNAME}:${NEXUS_PASSWORD} \
-F "raw.directory=apps/${CI_REPO_NAME}/${NEW_VERSION}" \
-F "raw.asset1=@${CI_WORKSPACE}/artifacts/$artifact" \
-F "raw.asset1.filename=$artifact" \
https://nexus.cicd.exygen.fr/service/rest/v1/components?repository=domaine-passignat
depends_on: [ package ]
# Étape 5: Commit et tag
- name: commit_tag
image: *git_image
environment:
GITEA_TOKEN:
from_secret: gitea_token
commands: |
# Charger les variables
more $CI_WORKSPACE/version.env
source $CI_WORKSPACE/version.env
echo "version type: $version_type"
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 config user.email "woodpecker@exygen.fr"
git config user.name "Woodpecker CI"
# Ajouter le remote avec token
# Ajouter le package.json modifié
git add package.json
git add ./database/src/sql/*.sql
# Vérifier s'il y a des changements
# if ! git diff --cached --quiet; then
# Commiter la nouvelle version
git commit -m "Pipeline: update current version v$NEW_VERSION [skip ci]"
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
echo "⚠️ Aucun changement à commiter"
fi
depends_on: [ publish ]
- name: trigger-deployment
image: woodpeckerci/plugin-trigger:latest
settings:
token:
from_secret: woodpecker_token
server: https://woodpecker.cicd.exygen.fr # ← Ajoute l'URL du serveur
repo: ${CI_REPO_OWNER}/${CI_REPO_NAME}
branch: main
event: deployment
deploy_id: ${CI_PIPELINE_NUMBER} # ← Peut être optionnel
deploy_to: production # ← Renommé en "environment" parfois
wait: true # ← Attend la fin du déploiement
depends_on: [ publish ]