Repository navigation
158 lines (136 loc) · 5.05 KB
/
Copy pathpython.yml
File metadata and controls
158 lines (136 loc) · 5.05 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
name: Python checks
permissions:
contents: read
on:
# Stacked PRs target a feature branch, so Python checks also run when the base is not main.
pull_request:
jobs:
check-paths:
runs-on: ubuntu-latest
outputs:
any_changed: ${{ steps.changed-files.outputs.any_changed }}
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 0
persist-credentials: false
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
with:
files: |
python/**
spec/**
.github/workflows/python.yml
uv-lock-check:
needs: check-paths
if: needs.check-paths.outputs.any_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
- name: Install uv
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
with:
enable-cache: true
- name: Check uv.lock is up to date
working-directory: python
run: |
uv lock --check
- name: Check requirements.txt is up to date
run: |
scripts/export_requirements
git diff --exit-code python/requirements.txt
- name: Run security scan
run: scripts/run_python_security_checks
python-checks:
needs: check-paths
if: needs.check-paths.outputs.any_changed == 'true'
runs-on: ${{ matrix.os }}
env:
PATH: ${{ github.workspace }}/go/bin:${{ github.workspace }}/.local/share/pnpm:${{ github.workspace }}/.local/bin:/usr/local/bin:/usr/bin:/bin
strategy:
matrix:
os:
- ubuntu-latest # x86_64
- ubuntu-24.04-arm # ARM64
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
include:
# PyPy runs on x86 only.
- os: ubuntu-latest
python-version: "pypy3.11"
fail-fast: false
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
with:
go-version: stable
# uv has no PyPy 3.11 download for linux x86_64, and PyPy 8.0 has no
# pydantic-core wheels. Pin 7.3.23 (Python 3.11.15, pp73 ABI); uv finds
# it on PATH.
- name: Set up PyPy
if: ${{ startsWith(matrix.python-version, 'pypy') }}
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version: pypy3.11-v7.3.23
- name: Install uv and setup Python version
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
with:
enable-cache: true
python-version: ${{ matrix.python-version }}
- name: Format check
run: uv run --active --directory python ruff format --check --preview .
- name: Lint with ruff
run: uv run --active --directory python ruff check --select I .
- name: Static type check (ty)
run: uv run --active --directory python ty check
- name: Static type check (pyrefly)
run: uv run --active --directory python pyrefly check
- name: Install Handlebars 4.7.9
run: |
npm install --prefix "${RUNNER_TEMP}/hbjs" handlebars@4.7.9
echo "HANDLEBARS_JS=${RUNNER_TEMP}/hbjs/node_modules/handlebars" >> "$GITHUB_ENV"
- name: Run Python tests for Python ${{ matrix.python-version }}
working-directory: ./python
run: |
uv run --python ${{ matrix.python-version }} --active --isolated pytest -xvvs --log-level=DEBUG .
- name: Build distributions
run: ./scripts/build_dists
python-checks-all:
if: always()
needs: [uv-lock-check, python-checks]
runs-on: ubuntu-latest
steps:
- name: Check overall status
run: |
if [[ "${NEEDS_UV_LOCK_CHECK_RESULT}" == "failure" || "${NEEDS_PYTHON_CHECKS_RESULT}" == "failure" ]]; then
echo "Python checks failed"
exit 1
fi
echo "Python checks passed or were skipped"
exit 0
env:
NEEDS_UV_LOCK_CHECK_RESULT: ${{ needs.uv-lock-check.result }}
NEEDS_PYTHON_CHECKS_RESULT: ${{ needs.python-checks.result }}