Merge pull request #24 from SalimM21/salim #24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI - Lint, Test, Build & Push | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| lint-and-test: | |
| runs-on: ubuntu-latest | |
| env: | |
| PYTHONPATH: src | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.10' | |
| - name: Install deps | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install flake8 pytest | |
| - name: Lint (flake8) | |
| run: flake8 src || true | |
| - name: Run tests | |
| run: pytest -q | |
| build-and-push: | |
| needs: lint-and-test | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/obesitrack:latest | |
| export-dashboard: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: pip install requests | |
| - name: Export Grafana Dashboard | |
| env: | |
| GRAFANA_URL: ${{ secrets.GRAFANA_URL }} | |
| GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }} | |
| GRAFANA_DASHBOARD_UID: obesitrack | |
| run: python scripts/export_grafana_dashboard.py | |
| - name: Commit & Push Dashboard | |
| run: | | |
| git config --global user.name "github-actions" | |
| git config --global user.email "actions@github.com" | |
| git add docs/grafana-dashboard.json | |
| git commit -m "chore: update Grafana dashboard" || echo "No changes to commit" | |
| git push |