Reuse Lint Complains About Files Declared In .gitignore In GitHub CI

by ADMIN 69 views

Introduction

As a developer, ensuring that your code adheres to licensing and copyright regulations is crucial. One of the tools that helps you achieve this is reuse lint, which checks your code for compliance with various licenses. However, when using GitHub Actions to deploy a CI pipeline, you may encounter issues with reuse lint complaining about files declared in the .gitignore file. In this article, we will explore this issue and provide a solution.

The Problem

When running uv run python -m reuse lint in your GitHub Actions pipeline, you may encounter errors like the following:

 '0BSD' found in:
* /__w/sensorium_ssc/sensorium_ssc/.uv_cache/archive-v0/NJ5KClVwQ7p2VFiCK_K4g/mypyc/lib-rt/pythoncapi_compat.h
* /__w/sensorium_ssc/sensorium_ssc/.venv/lib/python3.10/site-packages/mypyc/lib-rt/pythoncapi_compat.h
'BSD-2-Clause' found in:
* /__w/sensorium_ssc/sensorium_ssc/.uv_cache/archive-v0/YkhwO4bnZE5GchuE62ERD/boolean/__init__.py
* /__w/sensorium_ssc/sensorium_ssc/.uv_cache/archive-v0/YkhwO4bnZE5GchuE62ERD/boolean/boolean.py
* /__w/sensorium_ssc/sensorium_ssc/.uv_cache/archive-v0/YkhwO4bnZE5GchuE62ERD/boolean/test_boolean.py
* ...
* # MISSING COPYRIGHT AND LICENSING INFORMATION

The following files have no copyright and licensing information:
* /__w/sensorium_ssc/sensorium_ssc/src/sensorium.egg-info/PKG-INFO
* /__w/sensorium_ssc/sensorium_ssc/src/sensorium.egg-info/SOURCES.txt

These errors occur because reuse lint is inspecting files that are declared in the .gitignore file. This is unexpected behavior, as the documentation states that files declared in .gitignore should be ignored.

GitHub Actions Configuration

To reproduce this issue, you need to have a GitHub Actions pipeline configured to run reuse lint. Here is an example github-actions.yml file:

name: CI

on:
  push:
  pull_request:

env:
  IMAGE: "ghcr.io/astral-sh/uv:python3.12-bookworm"

jobs:
  test:
    runs-on: ubuntu-latest
    container: "ghcr.io/astral-sh/uv:python3.12-bookworm"
    
    env:
      QT_QPA_PLATFORM: "offscreen"
      MYPY_CACHE_DIR: ${{ github.workspace }}/.mypy_cache
      UV_CACHE_DIR: ${{ github.workspace }}/.uv_cache

    steps:
      - uses: actions/checkout@v4

      - name: Check REUSE License compliance
        run: uv run python -m reuse lint

      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: |
            .mypy_cache
            .uv_cache
          key: ${{ runner.os }}-checks-${{ hashFiles('**/pyproject.toml') }}
          restore-keys: |
            ${{ runner.os }}-checks-

      - name: Install system dependencies
        run: |
          apt-get update && apt-get install -y libdbus-1-3 libegl1 libgl1 libxkbcommon0

      - name: Install Python dependencies
        run: uv sync

      - name: Run tests
        run: uv run python -m pytest --cov --cov-report=term --cov-report=xml --junit-xml=report.xml

      - name: Run type checking
        run: uv run python -m mypy --no-error-summary docs src tests

      - name: Run Ruff checks
        run: |
          uv run python -m ruff check docs src tests
          uv run python -m ruff format --diff docs src tests

      - name: Build documentation
        run: uv run sphinx-build docs public

      - name: Upload documentation
        uses: actions/upload-artifact@v4
        with:
          name: documentation
          path: public

      - name: Upload test results
        uses: actions/upload-artifact@v4
        with:
          name: test-results
          path: report.xml

      - name: Upload coverage reports
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.xml
          fail_ci_if_error: true

  build:
    needs: test
    runs-on: ubuntu-latest
    container: "ghcr.io/astral-sh/uv:python3.12-bookworm"

    steps:
      - uses: actions/checkout@v4

      - name: Cache dependencies
        uses: actions/cache@v4
        with:
          path: |
            .mypy_cache
            .uv_cache
          key: ${{ runner.os }}-checks-${{ hashFiles('**/pyproject.toml') }}
          restore-keys: |
            ${{ runner.os }}-checks-

      - name: Install dependencies
        run: uv sync

      - name: Build package
        run: uv build

      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist

.gitignore Configuration

To reproduce this issue, you also need to have a .gitignore file that declares the files that should be ignored. Here is an example .gitignore file:

*.py[co]
*.egg-info/
__pycache__/

/public/

/.coverage
/coverage.xml
/report.xml

.DS_Store
*.sw[op]
/.vscode

.reuse/
.uv_cache/
.mypy_cache/
.venv/

Solution

To solve this issue, you need to configure reuse lint to ignore the files declared in the .gitignore file. You can do this by adding the following configuration to your REUSE.toml file:

[ignore]
  [[ignore.file]]
    path = ".gitignore"
    pattern = "^\\.uv_cache/.*{{content}}quot;
    pattern = "^\\.mypy_cache/.*{{content}}quot;
    pattern = "^\\.venv/.*{{content}}quot;

This configuration tells reuse lint to ignore any files that match the patterns specified in the .gitignore file.

Conclusion

Q: What is the issue with reuse lint complaining about files declared in .gitignore?

A: The issue is that reuse lint is inspecting files that are declared in the .gitignore file, which is unexpected behavior. The documentation states that files declared in .gitignore should be ignored.

Q: Why is this happening in GitHub Actions but not in Gitlab?

A: This issue is specific to GitHub Actions and may be related to the way that GitHub Actions handles file caching and dependencies. In Gitlab, the issue does not occur because the file caching and dependencies are handled differently.

Q: How can I configure reuse lint to ignore files declared in .gitignore?

A: You can configure reuse lint to ignore files declared in .gitignore by adding the following configuration to your REUSE.toml file:

[ignore]
  [[ignore.file]]
    path = ".gitignore"
    pattern = "^\\.uv_cache/.*{{content}}quot;
    pattern = "^\\.mypy_cache/.*{{content}}quot;
    pattern = "^\\.venv/.*{{content}}quot;

This configuration tells reuse lint to ignore any files that match the patterns specified in the .gitignore file.

Q: What are some common patterns that I should add to the ignore configuration?

A: Some common patterns that you may want to add to the ignore configuration include:

  • ^\\.uv_cache/.*$ to ignore files in the .uv_cache directory
  • ^\\.mypy_cache/.*$ to ignore files in the .mypy_cache directory
  • ^\\.venv/.*$ to ignore files in the .venv directory
  • ^\\.gitignore$ to ignore the .gitignore file itself

Q: How can I troubleshoot this issue if it persists after adding the ignore configuration?

A: If the issue persists after adding the ignore configuration, you can try the following troubleshooting steps:

  • Check the reuse lint logs to see if there are any errors or warnings related to the files that are being inspected.
  • Verify that the REUSE.toml file is being read correctly by reuse lint.
  • Try running reuse lint with the --verbose flag to see more detailed output.
  • Check the GitHub Actions logs to see if there are any errors or warnings related to the file caching and dependencies.

Q: Is there a way to avoid adding the ignore configuration altogether?

A: Unfortunately, it is not possible to avoid adding the ignore configuration altogether. The issue is specific to GitHub Actions and requires a custom configuration to resolve.

Q: Can I use a different tool instead of reuse lint?

A: Yes, you can use a different tool instead of reuse lint. Some popular alternatives include:

  • license-checker
  • license-finder
  • cloc

However, keep in mind that these tools may have different features and configurations, so you may need to adjust your workflow accordingly.