-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (94 loc) · 3.19 KB
/
Copy pathpython-test.yml
File metadata and controls
108 lines (94 loc) · 3.19 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
# Copyright © 2026 kogeler
# SPDX-License-Identifier: Apache-2.0
# Universal test gate for every Python project in the repository. A Python
# project is a top-level folder containing requirements-dev.txt (pinned test
# and lint dependencies); runtime dependencies come from requirements.txt
# when present. The workflow runs on pushes to any branch and on pull
# requests, building a job matrix of affected projects via the shared
# python-projects-matrix action.
name: Python Tests
on:
push:
branches:
- '**'
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: python-tests-${{ github.ref }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.projects.outputs.matrix }}
has_targets: ${{ steps.projects.outputs.has_targets }}
steps:
- name: Check out repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Locate affected Python projects
id: projects
uses: ./.github/actions/python-projects-matrix
with:
mode: source-changes
- name: Summary
run: |
if [ "${{ steps.projects.outputs.has_targets }}" = "true" ]; then
echo "### 🧪 Python projects to test" >> $GITHUB_STEP_SUMMARY
echo '${{ steps.projects.outputs.folders }}' | jq -r '.[]' | while read -r dir; do
echo "- $dir" >> $GITHUB_STEP_SUMMARY
done
else
echo "### ℹ️ No Python projects affected by this change" >> $GITHUB_STEP_SUMMARY
fi
test:
needs: prepare
if: needs.prepare.outputs.has_targets == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
folder: ${{ fromJson(needs.prepare.outputs.matrix).folders }}
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
# Matches the python:3.14-alpine base image used by the containers.
python-version: '3.14'
cache: pip
cache-dependency-path: ${{ matrix.folder }}/requirements*.txt
- name: Install dependencies
run: |
set -euo pipefail
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
pip install -r requirements-dev.txt
working-directory: ${{ matrix.folder }}
- name: ruff check
run: |
set -euo pipefail
if command -v ruff >/dev/null 2>&1; then
ruff check .
else
echo "ruff is not in requirements-dev.txt; skipping lint"
fi
working-directory: ${{ matrix.folder }}
- name: pytest
run: python -m pytest -v
working-directory: ${{ matrix.folder }}
- name: shellcheck project scripts
run: |
set -euo pipefail
mapfile -t scripts < <(git ls-files "${{ matrix.folder }}" | grep '\.sh$' || true)
if [ "${#scripts[@]}" -gt 0 ]; then
shellcheck "${scripts[@]}"
else
echo "No shell scripts in ${{ matrix.folder }}"
fi