Files
Synthese-PSM_LARRA/.github/workflows/pyThtoQgis-2.yml
T
Alex38Lyon 04a9c6ccbc Enhance pyThtoQgis workflow with SHP checks
Updated the GitHub Actions workflow to include checks for added or modified SHP files, improved comments, and adjusted commit messages for generated outputs.
2026-08-31 21:21:31 +02:00

468 lines
12 KiB
YAML

name: pyThtoQgis-2
on:
push:
branches:
- main
paths:
- 'Outputs/SHP/*.shp'
workflow_dispatch:
permissions:
contents: write
concurrency:
group: pyThtoQgis
cancel-in-progress: false
jobs:
pyThtoQgis:
runs-on: ubuntu-latest
steps:
# ============================================================
# 1. Récupération du dépôt
# ============================================================
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# ============================================================
# 2. Vérification du type de modification
#
# Le workflow est déclenché par *.shp mais GitHub déclenche
# également l'action lorsqu'un SHP est supprimé.
#
# On ne continue que si au moins un SHP a été AJOUTÉ ou MODIFIÉ.
# ============================================================
- name: Check SHP changes
id: changed
shell: bash
run: |
echo "========================================"
echo "Recherche des SHP ajoutés/modifiés"
echo "========================================"
SHP_FILES=$(git diff-tree \
--no-commit-id \
--name-only \
--diff-filter=AM \
-r \
"$GITHUB_SHA" \
-- 'Outputs/SHP/*.shp')
echo "Fichiers SHP ajoutés/modifiés :"
echo "$SHP_FILES"
if [ -n "$SHP_FILES" ]; then
echo "shp=true" >> "$GITHUB_OUTPUT"
else
echo "shp=false" >> "$GITHUB_OUTPUT"
fi
# ============================================================
# 3. Arrêt si aucun SHP ajouté/modifié
# ============================================================
- name: Stop if no SHP added or modified
if: steps.changed.outputs.shp != 'true'
shell: bash
run: |
echo "Aucun fichier SHP ajouté ou modifié."
echo "Le workflow s'arrête."
# ============================================================
# 4. Installation de Micromamba
# ============================================================
- name: Setup Micromamba
if: steps.changed.outputs.shp == 'true'
uses: mamba-org/setup-micromamba@v2
with:
environment-name: pyThtoQgis
create-args: >-
python=3.12
numpy
sfcgal=2.2
geos
proj
sqlite
libtiff
libjpeg-turbo
libpng
zlib
curl
openssl
swig
cmake
ninja
pkg-config
init-shell: bash
cache-environment: true
cache-downloads: true
# ============================================================
# 5. Informations environnement
# ============================================================
- name: Environment information
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
echo "========================================"
echo "Python"
echo "========================================"
python --version
which python
echo "========================================"
echo "Conda"
echo "========================================"
echo "CONDA_PREFIX=$CONDA_PREFIX"
echo "========================================"
echo "Packages"
echo "========================================"
conda list | grep -E \
"python|numpy|gdal|geos|sfcgal|proj|sqlite|cmake"
# ============================================================
# 6. Vérification SFCGAL
# ============================================================
- name: Check SFCGAL
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
echo "========================================"
echo "SFCGAL"
echo "========================================"
sfcgal-config --version || true
echo ""
echo "Bibliothèques SFCGAL :"
find "$CONDA_PREFIX" \
\( -iname "*sfcgal*.so*" -o -iname "*SFCGAL*.so*" \) \
-print
# ============================================================
# 7. Compilation de GDAL avec SFCGAL
# ============================================================
- name: Build GDAL with SFCGAL
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
set -e
GDAL_VERSION=3.13.3
echo "========================================"
echo "Compilation GDAL $GDAL_VERSION"
echo "========================================"
cd "$RUNNER_TEMP"
git clone \
--depth 1 \
--branch "v${GDAL_VERSION}" \
https://github.com/OSGeo/gdal.git
cd gdal
mkdir build
cd build
echo "========================================"
echo "Configuration CMake"
echo "========================================"
cmake .. \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX" \
-DCMAKE_PREFIX_PATH="$CONDA_PREFIX" \
-DCMAKE_LIBRARY_PATH="$CONDA_PREFIX/lib" \
-DCMAKE_INCLUDE_PATH="$CONDA_PREFIX/include" \
-DCMAKE_INSTALL_RPATH="$CONDA_PREFIX/lib" \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DGDAL_USE_SFCGAL=ON \
-DGDAL_USE_GEOS=ON \
-DGDAL_USE_PROJ=ON \
-DGDAL_USE_SQLITE3=ON \
-DGDAL_USE_CURL=ON \
-DGDAL_BUILD_OPTIONAL_DRIVERS=ON \
-DBUILD_PYTHON_BINDINGS=ON
echo "========================================"
echo "Compilation"
echo "========================================"
ninja -j"$(nproc)"
echo "========================================"
echo "Installation"
echo "========================================"
ninja install
# ============================================================
# 8. Vérification GDAL
# ============================================================
- name: Check GDAL
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
echo "========================================"
echo "GDAL"
echo "========================================"
which gdalinfo
gdalinfo --version
echo ""
echo "GDAL Python :"
python - <<'PY'
from osgeo import gdal
print(gdal.VersionInfo("--version"))
print()
print(gdal.VersionInfo("--build-info"))
PY
# ============================================================
# 9. Vérification liaison GDAL / SFCGAL / GEOS
# ============================================================
- name: Check GDAL SFCGAL linkage
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
echo "========================================"
echo "GDAL / SFCGAL linkage"
echo "========================================"
echo ""
echo "libgdal :"
find "$CONDA_PREFIX/lib" \
-maxdepth 1 \
-name "libgdal.so*" \
-print
echo ""
echo "Dépendances libgdal :"
ldd "$CONDA_PREFIX/lib/libgdal.so" \
| grep -Ei "sfcgal|geos" || true
# ============================================================
# 10. Test SFCGAL via OGR
# ============================================================
- name: Test SFCGAL via OGR
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
python - <<'PY'
from osgeo import ogr
from osgeo import gdal
print("========================================")
print("Test SFCGAL via OGR")
print("========================================")
print("GDAL :", gdal.VersionInfo("--version"))
# --------------------------------------------------------
# Création d'une géométrie 3D
# --------------------------------------------------------
wkt = """
POLYHEDRALSURFACE Z (
(
(0 0 0,
10 0 0,
10 10 0,
0 10 0,
0 0 0)
)
)
"""
geom = ogr.CreateGeometryFromWkt(wkt)
if geom is None:
raise RuntimeError(
"Impossible de créer la géométrie 3D"
)
print("Type :", geom.GetGeometryName())
print(
"Geometry type :",
geom.GetGeometryType()
)
print(
"Has Z :",
ogr.GT_HasZ(
geom.GetGeometryType()
)
)
try:
valid = geom.IsValid()
print(
"IsValid() :",
valid
)
except Exception as e:
print(
"IsValid() ERROR :",
e
)
raise
print()
print("Test SFCGAL terminé avec succès.")
# ============================================================
# 11. Installation des dépendances Python du projet
# ============================================================
- name: Install Python dependencies
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
python -m pip install --upgrade pip
pip install \
alive-progress
# ============================================================
# 12. Affichage des SHP à traiter
# ============================================================
- name: List SHP input files
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
echo "========================================"
echo "Fichiers SHP"
echo "========================================"
find Outputs/SHP \
-maxdepth 1 \
-type f \
-name "*.shp" \
-print
# ============================================================
# 13. Exécution de pyThtoQgis
# ============================================================
- name: Run pyThtoQgis
if: steps.changed.outputs.shp == 'true'
shell: bash -el {0}
run: |
echo "========================================"
echo "Exécution pyThtoQgis"
echo "========================================"
cd Scripts/pyThtoQgis
python pyThtoQgis.py \
--folder "../../Outputs/SHP/"
# ============================================================
# 14. Affichage des fichiers produits
# ============================================================
- name: Show generated files
if: steps.changed.outputs.shp == 'true'
shell: bash
run: |
echo "========================================"
echo "Fichiers générés / modifiés"
echo "========================================"
git status --short
echo ""
echo "========================================"
echo "Différence Git"
echo "========================================"
git diff --stat
# ============================================================
# 15. Commit des fichiers produits
# ============================================================
- name: Commit generated files
if: steps.changed.outputs.shp == 'true'
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: "Auto-generate outputs from SHP"
commit_user_name: "github-actions[bot]"
commit_user_email: "41898282+github-actions[bot]@users.noreply.github.com"
commit_author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"