-
Notifications
You must be signed in to change notification settings - Fork 5
134 lines (112 loc) · 3.84 KB
/
Copy pathpython-testing.yml
File metadata and controls
134 lines (112 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Python Testing Workflow
#
# - Automatically runs tests on all supported versions of Python
name: Python - Testing
on:
workflow_call:
inputs:
versions:
description: 'Python versions to test against'
type: string
# All Major versions of Python that are currently supported
default: '3.9,3.10,3.11,3.12,3.13'
tool:
description: 'The tool to lint with'
type: string
default: 'ruff'
jobs:
versions:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set matrix
id: set-matrix
run: |
versions="${{ inputs.versions }}"
echo "Version Input :: $versions"
matrix=$(echo "$versions" | tr "," "\n" | awk '{print "\""$1"\""}' | paste -sd "," -)
echo "matrix :: [$matrix]"
echo "matrix=[$matrix]" >> "$GITHUB_OUTPUT"
testing:
# This workflow runs on the latest version of Ubuntu
runs-on: ubuntu-latest
if: ${{ needs.python-versions.outputs.matrix != '[]' }}
needs: [ versions ]
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(needs.versions.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
env:
PYTHON_VERSION: ${{ matrix.python-version }}
run: |
set -e
echo "Installing dependencies..."
if [[ -f Pipfile ]]; then
echo "Pipfile found, installing with pipenv"
python -m pip install --upgrade pip pipenv
pipenv sync -d
elif [[ -f uv.lock ]]; then
echo "uv.lock found, installing with uv"
python -m pip install --upgrade uv
uv python install "$PYTHON_VERSION"
uv sync -d
elif [[ -f pyproject.toml ]]; then
echo "pyproject.toml found, installing with poetry"
python -m pip install --upgrade pip poetry
poetry install
elif [[ -f requirements.txt ]]; then
echo "requirements.txt found, installing with pip"
python -m pip install --upgrade pip
pip install -r requirements.txt
elif [[ -f Makefile ]]; then
make install
else
echo "No manifest files found to install dependencies"
fi
- name: Run tests
run: |
set -e
echo "Running Python tests..."
if [[ -f Pipfile ]]; then
echo "Running pipenv run test"
pipenv run test
elif [[ -f uv.lock ]]; then
echo "Running uv test"
uv run test
elif [[ -f pyproject.toml ]]; then
echo "Running poetry run test"
poetry run test
elif [[ -f Makefile ]]; then
echo "Running make test"
make test
else
echo "Unknown test runner..."
echo "Please contact the oss-maintainers team for help."
fi
- name: Run linting
env:
TOOL: ${{ inputs.tool }}
run: |
set -e
if [[ "$TOOL" == "ruff" ]]; then
pip install ruff
ruff check
elif [[ "$TOOL" == "flake8" ]]; then
pip install flake8
flake8 .
elif [[ "$TOOL" == "black" ]]; then
pip install black
black --check .
else
echo "Unknown linting tool..."
echo "Please contact the oss-maintainers team for help."
fi