Merge branch 'main' of https://github.com/raold/second-brain #106
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 Pipeline | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| setup: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| cache-key: ${{ steps.cache-key.outputs.value }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| - name: Generate cache key | |
| id: cache-key | |
| run: echo "value=${{ hashFiles('**/requirements.txt', '**/ruff.toml', '**/pytest.ini') }}" >> $GITHUB_OUTPUT | |
| # Cache pip dependencies | |
| - name: Cache pip dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ steps.cache-key.outputs.cache-key }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| # Cache pip packages | |
| - name: Cache pip packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.local | |
| key: ${{ runner.os }}-pip-packages-${{ steps.cache-key.outputs.cache-key }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-packages- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install --cache-dir ~/.cache/pip -r requirements.txt | |
| pip install --cache-dir ~/.cache/pip pytest pytest-cov ruff | |
| docker-build: | |
| runs-on: ubuntu-latest | |
| needs: setup | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Cache Docker layers | |
| - name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: false | |
| tags: second-brain:latest | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
| # Move cache | |
| - name: Move cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| lint: | |
| runs-on: ubuntu-latest | |
| needs: setup | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| # Restore pip cache from setup job | |
| - name: Cache pip dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ needs.setup.outputs.cache-key }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Cache pip packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.local | |
| key: ${{ runner.os }}-pip-packages-${{ needs.setup.outputs.cache-key }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-packages- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install --cache-dir ~/.cache/pip -r requirements.txt | |
| pip install --cache-dir ~/.cache/pip ruff | |
| # Cache ruff cache | |
| - name: Cache ruff cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: .ruff_cache | |
| key: ${{ runner.os }}-ruff-${{ hashFiles('**/ruff.toml', '**/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-ruff- | |
| - name: Auto-fix lint issues (ruff) | |
| run: | | |
| ruff check . --fix || echo "Lint auto-fixed" | |
| - name: Run Linting (ruff) | |
| run: | | |
| ruff check . | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: setup | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.11' | |
| # Restore pip cache from setup job | |
| - name: Cache pip dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ needs.setup.outputs.cache-key }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Cache pip packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.local | |
| key: ${{ runner.os }}-pip-packages-${{ needs.setup.outputs.cache-key }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-packages- | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install --cache-dir ~/.cache/pip -r requirements.txt | |
| pip install --cache-dir ~/.cache/pip pytest pytest-cov | |
| # Cache pytest cache | |
| - name: Cache pytest cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: .pytest_cache | |
| key: ${{ runner.os }}-pytest-${{ hashFiles('**/pytest.ini', '**/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pytest- | |
| - name: Copy .env.example to .env | |
| run: cp .env.example .env | |
| - name: Debug PYTHONPATH | |
| run: | | |
| echo "PYTHONPATH=$PYTHONPATH" | |
| ls -la /home/runner/work/second-brain/second-brain/app | |
| - name: Run Tests with Coverage | |
| run: | | |
| export PYTHONPATH=./app | |
| pytest --cov=app tests/ | |
| - name: Upload Coverage Report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: htmlcov/ |