|
| 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