lenskit/lkpy

View on GitHub
.github/workflows/check-sources.yml

Summary

Maintainability
Test Coverage
name: Validate Source Rules
on:
  push:
    branches:
      - main
  pull_request:

concurrency:
  group: check-${{github.ref}}
  cancel-in-progress: true

jobs:
  lint:
    name: Check Source Code
    runs-on: ubuntu-latest

    steps:
      - name: ๐Ÿ“ฅ Check out source code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: ๐Ÿ Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
          cache: "pip"

      - name: ๐Ÿ› ๏ธ Install development tools and dependencies
        run: |
          pip install -e .[dev]

      - name: ๐Ÿชฎ Check source code formatting
        id: format
        run: |
          if ruff format --diff $PKG_DIR; then
            echo passed=yes >>"$GITHUB_OUTPUT"
          else
            echo passed=no >>"$GITHUB_OUTPUT"
            echo "::error::source code not formatted"
          fi
        env:
          PKG_DIR: lenskit

      - name: ๐Ÿœ Check source code lint rules
        id: lint
        run: |
          if ruff check --output-format=github $PKG_DIR; then
            echo passed=yes >>"$GITHUB_OUTPUT"
          else
            echo passed=no >>"$GITHUB_OUTPUT"
            echo "::error::source code lint check failed"
          fi
        env:
          PKG_DIR: lenskit

      - name: ๐Ÿงพ Checking lint and format results
        run: |
          if [ "$FMT_PASSED" = no ]; then
              echo "::error::format failed, failing build"
              exit 1
          fi
          if [ "$LINT_PASSED" = no ]; then
              if [ "$LINT_REQUIRED" = true ]; then
                  echo "::error::lint failed, failing build"
                  exit 2
              else
                  echo "::error::lint failed but non-mandatory"
              fi
          fi
        env:
          FMT_PASSED: ${{ steps.format.outputs.passed }}
          LINT_PASSED: ${{ steps.lint.outputs.passed }}
          LINT_REQUIRED: False