diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..040f76db169fc81c260f6caf5d4d65c79b2a9ac5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -0,0 +1,35 @@ +stages: + - format + +format_files: + stage: format + image: python:3.10 + before_script: + - pip install jq nbformat + script: + - git fetch --unshallow || true + - git fetch origin $CI_COMMIT_REF_NAME + - git checkout $CI_COMMIT_SHA + # Identifier les fichiers modifiés + - MODIFIED_JSON_FILES=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep '\.json$' || true) + - MODIFIED_IPYNB_FILES=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA | grep '\.ipynb$' || true) + - echo "Modified JSON files:" $MODIFIED_JSON_FILES + - echo "Modified IPYNB files:" $MODIFIED_IPYNB_FILES + # Formatage des fichiers JSON + - for file in $MODIFIED_JSON_FILES; do + jq . "$file" > "$file.formatted" && mv "$file.formatted" "$file"; + done + # Formatage des fichiers IPYNB + - for file in $MODIFIED_IPYNB_FILES; do + python -m nbformat --to notebook --input "$file" --output "$file.formatted" && mv "$file.formatted" "$file"; + done + # Ajouter et pousser les modifications + - git config --global user.email "ci-bot@example.com" + - git config --global user.name "CI Bot" + - git add $MODIFIED_JSON_FILES $MODIFIED_IPYNB_FILES + - git commit -m "Formatted JSON and IPYNB files" || echo "No changes to commit." + - git push origin $CI_COMMIT_REF_NAME + rules: + - changes: + - "*.json" + - "*.ipynb"