Add CI workflow
This commit is contained in:
94
.gitea/workflows/publish.yml
Normal file
94
.gitea/workflows/publish.yml
Normal file
@ -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."
|
Reference in New Issue
Block a user