From 7d9587b26d7f5dfc89ad9695526f9fbfd3f40670 Mon Sep 17 00:00:00 2001 From: lionel <.> Date: Tue, 8 Jul 2025 15:03:53 +0200 Subject: [PATCH] Add CI workflow --- .gitea/workflows/publish.yml | 94 ++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 .gitea/workflows/publish.yml diff --git a/.gitea/workflows/publish.yml b/.gitea/workflows/publish.yml new file mode 100644 index 0000000..8eaf02c --- /dev/null +++ b/.gitea/workflows/publish.yml @@ -0,0 +1,94 @@ +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: + REGISTRY_URL: ${{ vars.REGISTRY_URL }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + 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://$REGISTRY_USERNAME:$REGISTRY_PASSWORD@$REGISTRY_URL/api/v1/packages/$REGISTRY_USERNAME/pypi/$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: + REGISTRY_URL: ${{ vars.REGISTRY_URL }} + REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_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://$REGISTRY_URL/api/packages/$REGISTRY_USERNAME/pypi \ + -u "$REGISTRY_USERNAME" \ + -p "$REGISTRY_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."