-
Notifications
You must be signed in to change notification settings - Fork 5
92 lines (85 loc) · 2.92 KB
/
Copy pathpython-testing.yml
File metadata and controls
92 lines (85 loc) · 2.92 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
# 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'
cooldown-days:
description: 'Number of days to use as the dependency cooldown window (excludes packages newer than N days)'
type: number
default: 3
jobs:
python-versions:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set matrix
id: set-matrix
env:
VERSIONS: ${{ inputs.versions }}
run: |
set -e
echo "Version Input :: $VERSIONS"
matrix=$(echo "$VERSIONS" | tr "," "\n" | awk '{print "\""$1"\""}' | paste -sd "," -)
echo "matrix :: [$matrix]"
echo "matrix=[$matrix]" >> "$GITHUB_OUTPUT"
python-testing:
# This workflow runs on the latest version of Ubuntu
runs-on: ubuntu-latest
if: ${{ needs.python-versions.outputs.matrix != '[]' }}
needs: [ python-versions ]
strategy:
fail-fast: false
matrix:
python-version: ${{ fromJSON(needs.python-versions.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
env:
COOLDOWN_DAYS: ${{ inputs.cooldown-days }}
run: |
set -e
echo "Installing dependencies..."
if [[ -f pyproject.toml ]]; then
python -m pip install --upgrade pip poetry
poetry install
elif [[ -f Pipfile ]]; then
python -m pip install --upgrade pip pipenv
pipenv sync -d
elif [[ -f requirements.txt ]]; then
python -m pip install --upgrade uv
uv pip sync requirements.txt --require-hashes --exclude-newer "$(date -u -d "$COOLDOWN_DAYS days ago" +%Y-%m-%dT%H:%M:%SZ)"
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 pyproject.toml ]]; then
echo "Running poetry run test"
poetry run test
elif [[ -f Pipfile ]]; then
echo "Running pipenv run test"
pipenv 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