Skip to content

Commit 1d7dabe

Browse files
Add Matrix Pytest Runner GitHub Action
This action runs flake8 and pytest across specified Python versions, allowing for optional requirements files. Co-authored-by: LeAndre <lcjunior1220@gmail.com>
1 parent 70538ce commit 1d7dabe

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

action.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "Matrix Pytest Runner."
2+
description: "Run flake8 and pytest across matrix Python versions with optional requirements files."
3+
author: "GitCodeCheckers"
4+
branding:
5+
icon: "check-circle"
6+
color: "blue"
7+
8+
inputs:
9+
file:
10+
description: "Python file or test path to run with pytest."
11+
required: false
12+
default: ""
13+
python-version:
14+
description: "Python version to use."
15+
required: true
16+
requirements:
17+
description: "Optional requirements file to install from (overrides requirements.txt)"
18+
required: false
19+
default: ""
20+
21+
runs:
22+
using: "composite"
23+
steps:
24+
- uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ inputs.python-version }}
27+
28+
- name: Install dependencies
29+
shell: bash
30+
run: |
31+
python -m pip install --upgrade pip
32+
python -m pip install flake8 pytest
33+
34+
# Priority 1: matrix-provided requirements file
35+
if [ -n "${{ inputs.requirements }}" ] && [ -f "${{ inputs.requirements }}" ]; then
36+
echo "Installing from matrix requirements file: ${{ inputs.requirements }}"
37+
pip install -r "${{ inputs.requirements }}"
38+
39+
# Priority 2: fallback to requirements.txt
40+
elif [ -f requirements.txt ]; then
41+
echo "Installing from requirements.txt"
42+
pip install -r requirements.txt
43+
44+
# Priority 3: no requirements found
45+
else
46+
echo "No requirements file provided or found."
47+
fi
48+
49+
- name: Lint with flake8
50+
shell: bash
51+
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
54+
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+
fi

0 commit comments

Comments
 (0)