Files
ProjetsPython/.gitea/workflows/publish.yml
lionel b9abd511e6
All checks were successful
/ 🐍 Build & Publish Python Packages (push) Successful in 15s
Switch from gitea to devpi
2025-07-24 18:29:09 +02:00

94 lines
3.1 KiB
YAML

on:
push:
branches:
- master
workflow_dispatch:
jobs:
build-and-publish:
name: 🐍 Build & Publish Python Packages
runs-on: ubuntu-latest
steps:
- name: 📦 Cloner le dépôt
uses: actions/checkout@v3
- name: 🔍 Sélectionner les projets à publier
id: detect
env:
DEVPI_URL: ${{ vars.DEVPI_URL }}
DEVPI_USERNAME: ${{ secrets.DEVPI_USERNAME }}
run: |
set +e # Ne pas interrompre le script en cas d'erreur
git fetch origin master --depth=2 || true
CHANGED=$(git diff --name-only HEAD~1 HEAD || echo "")
#echo "🔍 Fichiers modifiés: $CHANGED"
SELECTED=""
for dir in */; do
if [ ! -f "$dir/setup.py" ]; then
echo "⏭️ $dir ignoré (pas de setup.py)"
continue
fi
NAME=$(cd "$dir" && python3 setup.py --name 2>/dev/null)
if [ -z "$NAME" ]; then
echo "⚠️ Aucun nom récupéré pour $dir"
continue
fi
VERSION=$(cd "$dir" && python3 setup.py --version 2>/dev/null)
if [ -z "$VERSION" ]; then
echo "⚠️ Aucune version récupéré pour $dir"
continue
fi
for f in $CHANGED; do
if [[ "$f" == "$dir"* ]]; then
echo "🟡 Modification détectée dans $dir"
fi
done
API_URL="https://$DEVPI_URL/$DEVPI_USERNAME/dev/$NAME/$VERSION"
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$API_URL")
if [ "$STATUS_CODE" = "404" ]; then
echo "📦 $NAME version $VERSION n'existe pas (HTTP $STATUS_CODE)"
SELECTED+="$dir "
else
echo "🔄 $NAME version $VERSION déjà présente (HTTP $STATUS_CODE)"
fi
done
echo "selected_projects=$SELECTED" >> $GITHUB_OUTPUT
echo "✅ Projets sélectionnés: $SELECTED"
- name: 🔧 Installer les outils Python
if: steps.detect.outputs.selected_projects != ''
run: |
python3 -m pip install --break-system-packages setuptools wheel twine
- name: 🚀 Publier les projets sélectionnés
if: steps.detect.outputs.selected_projects != ''
env:
DEVPI_URL: ${{ vars.DEVPI_URL }}
DEVPI_USERNAME: ${{ secrets.DEVPI_USERNAME }}
DEVPI_PASSWORD: ${{ secrets.DEVPI_PASSWORD }}
run: |
for dir in ${{ steps.detect.outputs.selected_projects }}; do
echo "🚀 Publication de $dir"
cd "$dir"
python3 setup.py sdist
twine upload \
--repository-url https://$DEVPI_URL/$DEVPI_USERNAME/dev \
-u "$DEVPI_USERNAME" \
-p "$DEVPI_PASSWORD" \
dist/* || exit 1
cd -
done
- name: ✅ Aucun projet à publier
if: steps.detect.outputs.selected_projects == ''
run: echo "✅ Aucun projet modifié ou nouveau. Rien à publier."