diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b251f5c4..71363fbc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,5 @@ name: Lint + on: push: branches: @@ -6,11 +7,8 @@ on: pull_request: concurrency: - # Concurrency group that uses the workflow name and PR number if available - # or commit SHA as a fallback. If a new build is triggered under that - # concurrency group while a previous build is running it will be canceled. - # Repeated pushes to a PR will cancel all previous builds, while multiple - # merges to master will not cancel. + # Concurrency configuration to cancel previous runs on the same branch/PR, + # ensuring only the latest commit is tested. group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} cancel-in-progress: true @@ -19,31 +17,43 @@ jobs: runs-on: ubuntu-24.04 strategy: matrix: - python-version: ['3.10'] + # Select a stable, modern Python version for running lint tools + python-version: ['3.10'] steps: - - uses: actions/checkout@v4 + - name: Checkout Repository + uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} + - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + # Optimization: Cache Poetry path and setup automatically using setup-python + cache: 'poetry' - - name: Install poetry - run: make poetry-download - - - name: Set up cache - uses: actions/cache@v4 + - name: Install Poetry + # Optimization: Use a dedicated action for faster and cleaner Poetry setup + uses: snok/install-poetry@v1 with: - path: | - .venv - ~/.cache/pre-commit - key: venv-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}-${{ hashFiles('.pre-commit-config.yaml') }} + # Lock to a specific stable version of Poetry for consistency + version: 1.8.0 - - name: Install dependencies + - name: Configure and Install Python Dependencies + # Poetry installs dependencies based on poetry.lock. We use --no-root + # as the lint job primarily needs dependencies, not the project itself installed. run: | poetry config virtualenvs.in-project true - make install + poetry install --no-root - - name: Lint - run: | - make pre-commit + - name: Set up Pre-Commit Cache + # Cache for pre-commit hooks themselves, independent of Python dependencies. + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + # Key depends only on the config file defining the hooks + key: pre-commit-v1-${{ hashFiles('.pre-commit-config.yaml') }} + restore-keys: | + pre-commit-v1- + + - name: Run Pre-Commit Hooks + # Run pre-commit within the poetry environment to ensure local dependencies are used + run: poetry run pre-commit run --all-files