Update .github/workflows/main.yml
This commit is contained in:
124
.github/workflows/main.yml
vendored
124
.github/workflows/main.yml
vendored
@@ -1,43 +1,121 @@
|
|||||||
name: CI/CD
|
name: Python CI/CD
|
||||||
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
tags:
|
- develop
|
||||||
- '*'
|
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
env:
|
- develop
|
||||||
# This is the default version of Python to use in most steps which aren't specific
|
|
||||||
DEFAULT_PYTHON_VERSION: "3.11"
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_publish:
|
test-and-validate:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: tests
|
|
||||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python ${{ env.DEFAULT_PYTHON_VERSION }}
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ['3.9', '3.10', '3.11']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout du code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Configuration de Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
- name: Install tools
|
- name: Mise en cache des dépendances
|
||||||
|
uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/.cache/pip
|
||||||
|
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-pip-
|
||||||
|
|
||||||
|
- name: Installation des dépendances
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install twine wheel setuptools
|
if [ -f requirements.txt ]; then
|
||||||
|
pip install -r requirements.txt
|
||||||
|
fi
|
||||||
|
# Installation des outils de test et validation
|
||||||
|
pip install pytest pytest-cov flake8 black pylint mypy
|
||||||
|
|
||||||
- name: Build
|
- name: Vérification du formatage avec Black
|
||||||
run: |
|
run: |
|
||||||
python setup.py sdist bdist_wheel
|
black --check --diff .
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Publish
|
- name: Analyse statique avec Flake8
|
||||||
run: |
|
run: |
|
||||||
export TWINE_USERNAME=${{ secrets.TWINE_USERNAME }}
|
# Arrêt si erreurs critiques, warnings pour le reste
|
||||||
export TWINE_PASSWORD=${{ secrets.TWINE_PASSWORD }}
|
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||||
twine upload dist/*
|
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||||
|
|
||||||
|
- name: Analyse avec Pylint
|
||||||
|
run: |
|
||||||
|
find . -name "*.py" -not -path "./venv/*" -not -path "./.venv/*" | xargs pylint --exit-zero
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Vérification des types avec MyPy
|
||||||
|
run: |
|
||||||
|
mypy . --ignore-missing-imports --no-strict-optional
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Exécution des tests avec Pytest
|
||||||
|
run: |
|
||||||
|
if [ -d "tests" ]; then
|
||||||
|
pytest tests/ -v --cov=. --cov-report=xml --cov-report=html --cov-report=term
|
||||||
|
else
|
||||||
|
echo "Aucun répertoire 'tests' trouvé, tests ignorés"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Upload de la couverture de code
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: coverage-report-${{ matrix.python-version }}
|
||||||
|
path: htmlcov/
|
||||||
|
retention-days: 30
|
||||||
|
|
||||||
|
security-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout du code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Configuration de Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.11'
|
||||||
|
|
||||||
|
- name: Installation de Safety et Bandit
|
||||||
|
run: |
|
||||||
|
pip install safety bandit
|
||||||
|
|
||||||
|
- name: Vérification des vulnérabilités avec Safety
|
||||||
|
run: |
|
||||||
|
if [ -f requirements.txt ]; then
|
||||||
|
safety check -r requirements.txt --json || true
|
||||||
|
fi
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Analyse de sécurité avec Bandit
|
||||||
|
run: |
|
||||||
|
bandit -r . -f json -o bandit-report.json || true
|
||||||
|
bandit -r . -f screen
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Upload du rapport de sécurité
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: security-reports
|
||||||
|
path: |
|
||||||
|
bandit-report.json
|
||||||
|
retention-days: 30
|
||||||
|
|||||||
Reference in New Issue
Block a user