mirror of
https://github.com/Alex38Lyon/Synthese-PSM_LARRA.git
synced 2026-09-30 07:21:55 +00:00
Modify GitHub Actions to include SQL file checks
Updated workflow to check for changes in both SHP and SQL files. Adjusted conditions for executing subsequent steps based on changes detected.
This commit is contained in:
@@ -5,6 +5,7 @@ on:
|
||||
- main
|
||||
paths:
|
||||
- 'Outputs/SHP/*.shp'
|
||||
- 'Outputs/DB_Synthese-PSM_LARRA.sql'
|
||||
workflow_dispatch:
|
||||
permissions:
|
||||
contents: write
|
||||
@@ -24,12 +25,36 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
# ============================================================
|
||||
# 2. Vérification SHP
|
||||
# 2. Vérification des fichiers SHP et SQL modifiés
|
||||
# ou lancement manuel
|
||||
# ============================================================
|
||||
- name: Check SHP changes
|
||||
- name: Check SHP and SQL changes
|
||||
id: changed
|
||||
shell: bash
|
||||
run: |
|
||||
echo "========================================"
|
||||
echo "VÉRIFICATION DES MODIFICATIONS"
|
||||
echo "========================================"
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Lancement manuel
|
||||
# --------------------------------------------------------
|
||||
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
|
||||
echo "Workflow lancé manuellement."
|
||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||
echo "manual=true" >> "$GITHUB_OUTPUT"
|
||||
echo "shp=true" >> "$GITHUB_OUTPUT"
|
||||
echo "sql=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "========================================"
|
||||
echo "Recherche des fichiers modifiés"
|
||||
echo "========================================"
|
||||
|
||||
# --------------------------------------------------------
|
||||
# SHP ajoutés ou modifiés
|
||||
# --------------------------------------------------------
|
||||
SHP_FILES=$(git diff-tree \
|
||||
--no-commit-id \
|
||||
--name-only \
|
||||
@@ -38,25 +63,87 @@ jobs:
|
||||
"$GITHUB_SHA" \
|
||||
-- 'Outputs/SHP/*.shp')
|
||||
|
||||
echo "SHP ajoutés/modifiés :"
|
||||
echo "$SHP_FILES"
|
||||
# --------------------------------------------------------
|
||||
# SQL ajouté ou modifié
|
||||
# --------------------------------------------------------
|
||||
SQL_FILE="Outputs/DB_Synthese-PSM_LARRA.sql"
|
||||
SQL_CHANGED=$(git diff-tree \
|
||||
--no-commit-id \
|
||||
--name-only \
|
||||
--diff-filter=AM \
|
||||
-r \
|
||||
"$GITHUB_SHA" \
|
||||
-- "$SQL_FILE")
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Affichage
|
||||
# --------------------------------------------------------
|
||||
echo ""
|
||||
echo "SHP ajoutés/modifiés :"
|
||||
if [ -n "$SHP_FILES" ]; then
|
||||
echo "$SHP_FILES"
|
||||
echo "shp=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "Aucun"
|
||||
echo "shp=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "SQL ajouté/modifié :"
|
||||
if [ -n "$SQL_CHANGED" ]; then
|
||||
echo "$SQL_CHANGED"
|
||||
echo "sql=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "Aucun"
|
||||
echo "sql=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
# --------------------------------------------------------
|
||||
# Décision de poursuivre
|
||||
# --------------------------------------------------------
|
||||
if [ -n "$SHP_FILES" ] || [ -n "$SQL_CHANGED" ]; then
|
||||
echo ""
|
||||
echo "SHP ou SQL ajouté/modifié : CONTINUER"
|
||||
echo "changed=true" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo ""
|
||||
echo "Aucun SHP ni SQL ajouté/modifié."
|
||||
echo "changed=false" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
echo "manual=false" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# ============================================================
|
||||
# 3. Arrêt si suppression uniquement
|
||||
# 3.1 Arrêt si aucun SHP/SQL et pas de lancement manuel
|
||||
# ============================================================
|
||||
- name: Stop if no SHP added or modified
|
||||
if: steps.changed.outputs.shp != 'true'
|
||||
- name: Stop if no SHP or SQL changes
|
||||
if: steps.changed.outputs.changed != 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Aucun SHP ajouté ou modifié."
|
||||
echo "Aucun SHP ou SQL ajouté/modifié."
|
||||
echo "Arrêt du workflow."
|
||||
|
||||
# ============================================================
|
||||
# 3.2 Vérification de la base SQL
|
||||
# ============================================================
|
||||
- name: Check SQL database
|
||||
if: steps.changed.outputs.changed == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
set -e
|
||||
echo "========================================"
|
||||
echo "CHECK DATABASE"
|
||||
echo "========================================"
|
||||
SQL_FILE="Outputs/DB_Synthese-PSM_LARRA.sql"
|
||||
if [ ! -f "$SQL_FILE" ]; then
|
||||
echo "ERREUR : fichier SQL introuvable :"
|
||||
echo "$SQL_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Base SQL trouvée :"
|
||||
ls -lh "$SQL_FILE"
|
||||
|
||||
# ============================================================
|
||||
# 4. Micromamba
|
||||
# IMPORTANT :
|
||||
@@ -64,7 +151,7 @@ jobs:
|
||||
# GDAL sera fourni par notre package précompilé.
|
||||
# ============================================================
|
||||
- name: Setup Micromamba
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
uses: mamba-org/setup-micromamba@v3.2.1
|
||||
with:
|
||||
environment-name: pyThtoQgis
|
||||
@@ -89,7 +176,7 @@ jobs:
|
||||
# 5. Informations environnement
|
||||
# ============================================================
|
||||
- name: Environment information
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
echo "========================================"
|
||||
@@ -105,7 +192,7 @@ jobs:
|
||||
# 6. Téléchargement package GDAL
|
||||
# ============================================================
|
||||
- name: Download GDAL + SFCGAL package
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
@@ -133,7 +220,7 @@ jobs:
|
||||
# 7. Installation package GDAL
|
||||
# ============================================================
|
||||
- name: Installation GDAL package
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
set -e
|
||||
@@ -264,7 +351,7 @@ jobs:
|
||||
# 8. Vérification GDAL
|
||||
# ============================================================
|
||||
- name: Check GDAL
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
set -e
|
||||
@@ -291,7 +378,7 @@ jobs:
|
||||
# 9. Vérification SFCGAL
|
||||
# ============================================================
|
||||
- name: Check SFCGAL linkage
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
set -e
|
||||
@@ -305,7 +392,7 @@ jobs:
|
||||
# 10. Test SFCGAL
|
||||
# ============================================================
|
||||
- name: Test SFCGAL via OGR
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
python - <<'PY'
|
||||
@@ -346,7 +433,7 @@ jobs:
|
||||
# 11. Dépendances Python
|
||||
# ============================================================
|
||||
- name: Install Python dependencies
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.sql == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
@@ -358,7 +445,7 @@ jobs:
|
||||
# 12. Affichage des SHP
|
||||
# ============================================================
|
||||
- name: List SHP input files
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
echo "========================================"
|
||||
@@ -374,7 +461,7 @@ jobs:
|
||||
# 13. Exécution pyThtoQgis
|
||||
# ============================================================
|
||||
- name: Run pyThtoQgis
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
set -e
|
||||
@@ -385,43 +472,10 @@ jobs:
|
||||
python pyThtoQgis.py --folder "../../Outputs/SHP/"
|
||||
|
||||
# ============================================================
|
||||
# 14. Vérification base SQL
|
||||
# ============================================================
|
||||
- name: Check SQL database
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
set -e
|
||||
echo "========================================"
|
||||
echo "CHECK DATABASE"
|
||||
echo "========================================"
|
||||
|
||||
echo "========================================"
|
||||
echo "Find SQL"
|
||||
echo "========================================"
|
||||
ls -l
|
||||
echo "========================================"
|
||||
find Outputs \
|
||||
-maxdepth 1 \
|
||||
-type f \
|
||||
-name "*.sql" \
|
||||
-print
|
||||
|
||||
SQL_FILE="Outputs/DB_Synthese-PSM_LARRA.sql"
|
||||
|
||||
if [ ! -f "$SQL_FILE" ]; then
|
||||
echo "ERREUR : fichier SQL introuvable :"
|
||||
echo "$SQL_FILE"
|
||||
# exit 1
|
||||
fi
|
||||
echo "Base SQL trouvée :"
|
||||
ls -lh "$SQL_FILE"
|
||||
|
||||
# ============================================================
|
||||
# 15. Exécution pyThStat
|
||||
# 14. Exécution pyThStat
|
||||
# ============================================================
|
||||
- name: Run pyThStat
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash -el {0}
|
||||
run: |
|
||||
set -e
|
||||
@@ -435,10 +489,10 @@ jobs:
|
||||
python pythStat.py --file "../../Outputs/DB_Synthese-PSM_LARRA.sql"
|
||||
|
||||
# ============================================================
|
||||
# 16. Fichiers produits
|
||||
# 15. Fichiers produits
|
||||
# ============================================================
|
||||
- name: Show generated files
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.sql == 'true' || steps.changed.outputs.manual == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
echo "========================================"
|
||||
@@ -449,15 +503,13 @@ jobs:
|
||||
git diff --stat
|
||||
|
||||
# ============================================================
|
||||
# 17. Commit
|
||||
# 16. Commit
|
||||
# ============================================================
|
||||
- name: Commit generated files
|
||||
if: steps.changed.outputs.shp == 'true'
|
||||
if: steps.changed.outputs.shp == 'true' || steps.changed.outputs.sql == 'true' || steps.changed.outputs.manual == 'true'
|
||||
uses: stefanzweifel/git-auto-commit-action@v7
|
||||
with:
|
||||
commit_message: "Auto-generate outputs from SHP"
|
||||
commit_message: "Auto-generate outputs from ScriptPython"
|
||||
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>"
|
||||
|
||||
Reference in New Issue
Block a user