|
1 | | -name: "Matrix Pytest Runner." |
2 | | -description: "Run flake8 and pytest across matrix Python versions with optional requirements files." |
| 1 | +name: "Python Code Checker" |
| 2 | +description: "Run tox across matrix Python versions with optional requirements files." |
3 | 3 | author: "GitCodeCheckers" |
4 | 4 | branding: |
5 | 5 | icon: "check-circle" |
6 | 6 | color: "blue" |
7 | 7 |
|
8 | 8 | inputs: |
9 | | - file: |
10 | | - description: "Python file or test path to run with pytest." |
11 | | - required: false |
12 | | - default: "" |
13 | 9 | python-version: |
14 | 10 | description: "Python version to use." |
15 | 11 | required: true |
| 12 | + |
| 13 | + file: |
| 14 | + description: "Optional file or directory passed to tox (if your tox.ini uses it)." |
| 15 | + required: false |
| 16 | + default: "" |
| 17 | + |
16 | 18 | requirements: |
17 | | - description: "Optional requirements file to install from (overrides requirements.txt)" |
| 19 | + description: "Optional requirements file to install from (overrides requirements.txt)." |
18 | 20 | required: false |
19 | 21 | default: "" |
20 | 22 |
|
21 | 23 | runs: |
22 | 24 | using: "composite" |
23 | 25 | steps: |
24 | | - - uses: actions/setup-python@v5 |
| 26 | + - name: Set up Python |
| 27 | + uses: actions/setup-python@v6 |
25 | 28 | with: |
26 | 29 | python-version: ${{ inputs.python-version }} |
| 30 | + allow-prereleases: true |
27 | 31 |
|
28 | | - - name: Install dependencies |
| 32 | + - name: Upgrade pip |
29 | 33 | shell: bash |
30 | | - run: | |
31 | | - python -m pip install --upgrade pip |
32 | | - python -m pip install flake8 pytest |
| 34 | + run: python -m pip install --upgrade pip |
33 | 35 |
|
| 36 | + - name: Install tox + tox-gh-actions |
| 37 | + shell: bash |
| 38 | + run: pip install tox tox-gh-actions |
| 39 | + |
| 40 | + - name: Install project dependencies |
| 41 | + shell: bash |
| 42 | + run: | |
34 | 43 | # Priority 1: matrix-provided requirements file |
35 | 44 | if [ -n "${{ inputs.requirements }}" ] && [ -f "${{ inputs.requirements }}" ]; then |
36 | 45 | echo "Installing from matrix requirements file: ${{ inputs.requirements }}" |
37 | 46 | pip install -r "${{ inputs.requirements }}" |
38 | 47 |
|
39 | 48 | # Priority 2: fallback to requirements.txt |
40 | 49 | elif [ -f requirements.txt ]; then |
41 | | - echo "Installing from requirements.txt" |
| 50 | + echo "Installing from default requirements.txt" |
42 | 51 | pip install -r requirements.txt |
43 | 52 |
|
44 | 53 | # Priority 3: no requirements found |
45 | 54 | else |
46 | 55 | echo "No requirements file provided or found." |
47 | 56 | fi |
48 | 57 |
|
49 | | - - name: Lint with flake8 |
| 58 | + - name: Run tox |
50 | 59 | shell: bash |
51 | 60 | run: | |
52 | | - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
53 | | - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| 61 | + echo "Running tox." |
| 62 | + tox || code=$? |
54 | 63 |
|
55 | | - - name: Run pytest |
56 | | - shell: bash |
57 | | - run: | |
58 | | - if [ -z "${{ inputs.file }}" ]; then |
59 | | - echo "Running pytest on entire project." |
60 | | - pytest |
61 | | - else |
62 | | - echo "Running pytest on: ${{ inputs.file }}" |
63 | | - pytest ${{ inputs.file }} |
| 64 | + # Exit code 5 = no tests collected → treat as success |
| 65 | + if [ "${code:-0}" = "5" ]; then |
| 66 | + echo "No tests collected — treating as success." |
| 67 | + exit 0 |
| 68 | + fi |
| 69 | +
|
| 70 | + # Any other non-zero exit code = real failure |
| 71 | + if [ -n "${code:-}" ] && [ "$code" != "0" ]; then |
| 72 | + echo "Tox failed with exit code $code" |
| 73 | + exit "$code" |
64 | 74 | fi |
0 commit comments