ci.yml 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. name: CI/CD
  2. on:
  3. push:
  4. branches: [ main, develop ]
  5. pull_request:
  6. branches: [ main ]
  7. jobs:
  8. test:
  9. runs-on: ubuntu-latest
  10. strategy:
  11. matrix:
  12. python-version: ['3.11', '3.12']
  13. steps:
  14. - uses: actions/checkout@v4
  15. - name: Set up Python ${{ matrix.python-version }}
  16. uses: actions/setup-python@v5
  17. with:
  18. python-version: ${{ matrix.python-version }}
  19. - name: Cache dependencies
  20. uses: actions/cache@v4
  21. with:
  22. path: ~/.cache/pip
  23. key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
  24. restore-keys: |
  25. ${{ runner.os }}-pip-
  26. - name: Install dependencies
  27. run: |
  28. python -m pip install --upgrade pip
  29. pip install -r requirements.txt
  30. - name: Lint with ruff
  31. run: |
  32. ruff check src/ tests/
  33. - name: Format check with black
  34. run: |
  35. black --check src/ tests/
  36. - name: Type check with mypy
  37. run: |
  38. mypy src/ --ignore-missing-imports
  39. continue-on-error: true
  40. - name: Run tests with pytest
  41. run: |
  42. pytest tests/ -v --cov=src --cov-report=xml --cov-report=term
  43. - name: Upload coverage to Codecov
  44. uses: codecov/codecov-action@v4
  45. with:
  46. file: ./coverage.xml
  47. flags: unittests
  48. name: codecov-umbrella
  49. continue-on-error: true
  50. docker:
  51. runs-on: ubuntu-latest
  52. needs: test
  53. if: github.event_name == 'push' && github.ref == 'refs/heads/main'
  54. steps:
  55. - uses: actions/checkout@v4
  56. - name: Set up Docker Buildx
  57. uses: docker/setup-buildx-action@v3
  58. - name: Build Docker image
  59. run: |
  60. docker build -t cognio:latest .
  61. - name: Test Docker image
  62. run: |
  63. docker run --rm cognio:latest python -c "import src; print('Docker image OK')"
  64. - name: Log in to Docker Hub
  65. if: github.event_name == 'push'
  66. uses: docker/login-action@v3
  67. with:
  68. username: ${{ secrets.DOCKER_USERNAME }}
  69. password: ${{ secrets.DOCKER_PASSWORD }}
  70. continue-on-error: true
  71. - name: Push to Docker Hub
  72. if: github.event_name == 'push'
  73. run: |
  74. docker tag cognio:latest ${{ secrets.DOCKER_USERNAME }}/cognio:latest
  75. docker push ${{ secrets.DOCKER_USERNAME }}/cognio:latest
  76. continue-on-error: true