hv0905/NekoImageGallery

View on GitHub
.github/workflows/test_lint.yml

Summary

Maintainability
Test Coverage
name: Test and Lint Project

on:
  workflow_call:
  push:
    branches-ignore:
      - 'master'
  pull_request:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [ "3.10", "3.11" ]
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'
      - name: Cache for models
        id: cache-models
        uses: actions/cache@v4
        with:
          path: |
            ~/.cache/huggingface/
          key: ${{ runner.os }}-models-${{ hashFiles('requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-models-
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
          pip install -r requirements.txt
          pip install -r requirements.dev.txt
      - name: Test the code with pytest
        run: |
          pytest --cov=app --junitxml=junit.xml .
      - name: Upload test results to Codecov
        if: ${{ !cancelled() }}
        uses: codecov/test-results-action@v1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          flags: "python-${{ matrix.python-version }}"
      - name: Upload coverage reports to Codecov with GitHub Action
        uses: codecov/codecov-action@v4.2.0
        #        if: ${{ matrix.python-version == '3.11' }} # Only upload coverage reports for the latest Python version
        with:
          flags: "python-${{ matrix.python-version }}"
          token: ${{ secrets.CODECOV_TOKEN }}
      - name: Analysing the code with pylint
        run: |
          pylint --rc-file pylintrc.toml -j 0 app scripts tests && lint_result=$? || lint_result=$?
          exit $(( $lint_result & 35 ))