-
Notifications
You must be signed in to change notification settings - Fork 5
98 lines (90 loc) · 3.04 KB
/
Copy pathpython-linting.yml
File metadata and controls
98 lines (90 loc) · 3.04 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
# Python Testing Workflow
#
# - Automatically runs tests on all supported versions of Python
name: Python - Linting
on:
workflow_call:
inputs:
tool:
description: 'The tool to lint with'
type: string
default: 'ruff'
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'
cooldown-days:
description: 'Number of days to use as the dependency cooldown window (excludes packages newer than N days)'
type: number
default: 3
permissions:
contents: read
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-linting:
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
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 linting
env:
TOOL: ${{ inputs.tool }}
COOLDOWN_DAYS: ${{ inputs.cooldown-days }}
run: |
set -e
EXCLUDE_NEWER="$(date -u -d "$COOLDOWN_DAYS days ago" +%Y-%m-%dT%H:%M:%SZ)"
if [[ -f requirements.txt ]]; then
python -m pip install --upgrade uv
uv pip sync requirements.txt --exclude-newer "$EXCLUDE_NEWER"
fi
if [[ "$TOOL" == "ruff" ]]; then
ruff check
elif [[ "$TOOL" == "flake8" ]]; then
flake8 .
elif [[ "$TOOL" == "black" ]]; then
black --check .
fi