|
| 1 | +name: Lint code |
| 2 | +on: [push, pull_request] |
| 3 | + |
| 4 | +jobs: |
| 5 | + # Use ruff to check for code style violations |
| 6 | + ruff-check: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Checkout repo |
| 10 | + uses: actions/checkout@v4 |
| 11 | + - name: Set up Python |
| 12 | + uses: actions/setup-python@v4 |
| 13 | + with: |
| 14 | + python-version: "3.12" |
| 15 | + - name: Install dependencies |
| 16 | + run: | |
| 17 | + python -m pip install --upgrade pip |
| 18 | + pip install ruff |
| 19 | + - name: ruff --> Check for style violations |
| 20 | + # Configured in pyproject.toml |
| 21 | + run: ruff check . |
| 22 | + |
| 23 | + # Use ruff to check code formatting |
| 24 | + ruff-format: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + - name: Checkout repo |
| 28 | + uses: actions/checkout@v4 |
| 29 | + - name: Set up Python |
| 30 | + uses: actions/setup-python@v4 |
| 31 | + with: |
| 32 | + python-version: "3.12" |
| 33 | + - name: Install dependencies |
| 34 | + run: | |
| 35 | + python -m pip install --upgrade pip |
| 36 | + pip install ruff |
| 37 | + - name: ruff --> Check code formatting |
| 38 | + run: ruff format --check . |
| 39 | + |
| 40 | + # Use mypy for static type checking |
| 41 | + mypy-check: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + steps: |
| 44 | + - name: Checkout repo |
| 45 | + uses: actions/checkout@v4 |
| 46 | + - name: Set up Python |
| 47 | + uses: actions/setup-python@v4 |
| 48 | + with: |
| 49 | + python-version: "3.12" |
| 50 | + - name: Install dependencies |
| 51 | + run: | |
| 52 | + python -m pip install --upgrade pip |
| 53 | + pip install mypy |
| 54 | + # Start by installing type stubs |
| 55 | + - name: mypy --> Install stubs |
| 56 | + run: echo -e "y" | mypy --install-types . || exit 0 |
| 57 | + - name: mypy --> Static type checking |
| 58 | + # Configured in pyprojet.toml |
| 59 | + run: mypy . |
| 60 | + |
| 61 | + # Use pipreqs to check for missing dependencies |
| 62 | + pipreqs-check: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + steps: |
| 65 | + - name: Checkout repository |
| 66 | + uses: actions/checkout@v4 |
| 67 | + - name: Set up Python |
| 68 | + uses: actions/setup-python@v4 |
| 69 | + with: |
| 70 | + python-version: "3.12" |
| 71 | + |
| 72 | + - name: Install dependencies |
| 73 | + run: | |
| 74 | + python -m pip install --upgrade pip |
| 75 | + pip install -r requirements.txt |
| 76 | + pip install -r requirements-dev.txt |
| 77 | +
|
| 78 | + - name: Run pipreqs |
| 79 | + run: | |
| 80 | + pipreqs --savepath pipreqs.txt 2>&1 | tee pipreqs_output.log |
| 81 | + if grep -q 'WARNING: Package .* does not exist or network problems' pipreqs_output.log; then |
| 82 | + missing_packages=$(grep 'WARNING: Package .* does not exist or network problems' pipreqs_output.log | sed -E 's/.*Package "(.*)" does not exist.*/\1/') |
| 83 | + echo "ERROR: Add unresolved packages to requirements. Missing package(s): $missing_packages. Example: '<pkg> @ git+https://github.com/<author>/<repo>.git'" |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | +
|
| 87 | + - name: Compare requirements |
| 88 | + run: | |
| 89 | + # Extract and sort package names |
| 90 | + awk -F'(=|==|>|>=|<|<=| @ )' '{print $1}' requirements.txt | tr '[:upper:]' '[:lower:]' | sort -u > requirements.compare |
| 91 | + awk -F'(=|==|>|>=|<|<=| @ )' '{print $1}' pipreqs.txt | tr '[:upper:]' '[:lower:]' | sort -u > pipreqs.compare |
| 92 | +
|
| 93 | + # Compare package lists |
| 94 | + if cmp -s requirements.compare pipreqs.compare |
| 95 | + then |
| 96 | + echo "Requirements are the same" |
| 97 | +
|
| 98 | + exit 0 |
| 99 | + else |
| 100 | + echo "Requirements are different" |
| 101 | + echo "" |
| 102 | +
|
| 103 | + echo "=== current requirements.txt ===" |
| 104 | + echo "" |
| 105 | + cat requirements.compare |
| 106 | + echo "" |
| 107 | +
|
| 108 | + echo "=== pipreqs requirements ===" |
| 109 | + echo "" |
| 110 | + cat pipreqs.compare |
| 111 | +
|
| 112 | + exit 1 |
| 113 | + fi |
| 114 | +
|
| 115 | + # Use Prettier to check various file formats |
| 116 | + prettier: |
| 117 | + runs-on: ubuntu-latest |
| 118 | + steps: |
| 119 | + - name: Checkout repository |
| 120 | + uses: actions/checkout@v4 |
| 121 | + - name: Setup node |
| 122 | + uses: actions/setup-node@v4 |
| 123 | + with: |
| 124 | + node-version: "20" |
| 125 | + |
| 126 | + - name: Install Prettier |
| 127 | + run: npm install -g prettier |
| 128 | + |
| 129 | + - name: Run Prettier --check |
| 130 | + run: prettier --check . |
| 131 | + |
| 132 | + # Use editorconfig to check all remaining file formats |
| 133 | + editorconfig: |
| 134 | + runs-on: ubuntu-latest |
| 135 | + steps: |
| 136 | + - name: Checkout repo |
| 137 | + uses: actions/checkout@v4 |
| 138 | + |
| 139 | + - name: Setup node |
| 140 | + uses: actions/setup-node@v4 |
| 141 | + with: |
| 142 | + node-version: "20" |
| 143 | + |
| 144 | + - name: Install editorconfig-checker |
| 145 | + run: npm install -g editorconfig-checker |
| 146 | + |
| 147 | + - name: editorconfig --> Lint files |
| 148 | + run: editorconfig-checker $(git ls-files | grep -v '.py\|.md\|.json\|.yml\|.yaml\|.html\|.Makefile\|.rst') |
0 commit comments