-
Notifications
You must be signed in to change notification settings - Fork 1
116 lines (96 loc) · 3.11 KB
/
python.yml
File metadata and controls
116 lines (96 loc) · 3.11 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
name: ci
on:
push:
branches: ["main"]
paths:
- "**/*.py"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/python.yml"
pull_request:
branches: ["main"]
types: [opened, synchronize, reopened, unlabeled]
paths:
- "**/*.py"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/python.yml"
workflow_dispatch:
inputs:
python-version:
description: "Python version (leave empty for all)"
required: false
default: ""
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
UV_PROJECT_ENVIRONMENT: $pythonLocation
jobs:
test-and-lint:
name: Run Tests & Linting
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'no-ci')
strategy:
matrix:
python-version: ${{ fromJson(
github.event_name == 'workflow_dispatch' && github.event.inputs.python-version != ''
&& format('["{0}"]', github.event.inputs.python-version)
|| '["3.11", "3.12", "3.13"]'
) }}
extras: ["--all-extras"]
include:
- python-version: ${{
github.event_name == 'workflow_dispatch' && github.event.inputs.python-version != ''
&& format('{0}', github.event.inputs.python-version)
|| '3.13'
}}
extras: ""
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install the project
run: uv sync --locked ${{ matrix.extras }} --dev
- name: Check format with ruff
run: uv run ruff format --check
- name: Lint with ruff
run: uv run ruff check
- name: Test with pytest
run: uv run pytest
- name: Type check with ty
# TODO: remove `grep -v || true` once ty supports a flag to suppress warnings (https://github.com/astral-sh/ty/issues/2169)
# grep -v filters out warnings from the GitHub annotations output to keep the PR review
# interface readable. Warnings are still visible locally and should not be forgotten.
run: uv run ty check --output-format github | grep -v "::warning " || true
build:
name: Build Package
needs: test-and-lint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Build package
run: uv build
- name: Upload package artifact
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
uses: actions/upload-artifact@v7
with:
name: built-package
path: dist/