Repository navigation
200 lines (185 loc) · 6.4 KB
/
Copy pathpython-check.yaml
File metadata and controls
200 lines (185 loc) · 6.4 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Python Check
run-name: "${{ github.actor }} checking Python code"
permissions:
contents: read
pull-requests: read
"on":
pull_request:
push:
branches: ["release/*"]
workflow_dispatch:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string
workflow_call:
inputs:
checkout-path:
description: "Path to check out code to"
required: false
type: string
skip-relevance-check:
description: "Bypass relevance check"
required: false
type: boolean
default: false
pr-base-sha:
description: "Base SHA of the PR for relevance check"
required: false
type: string
pr-head-sha:
description: "Head SHA of the PR for relevance check"
required: false
type: string
ref:
description: "The branch, ref, or SHA to checkout"
required: false
type: string
repo:
description: "The repository to checkout from"
required: false
type: string
jobs:
setup:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.setup.outputs.is_act }}
ref: ${{ steps.setup.outputs.ref }}
repo: ${{ steps.setup.outputs.repo }}
base_sha: ${{ steps.setup.outputs.base_sha }}
pr_number: ${{ steps.setup.outputs.pr_number }}
checkout_path: ${{ steps.setup.outputs.checkout_path }}
has_changes: ${{ steps.setup.outputs.has_changes }}
steps:
- name: Workflow setup
id: setup
uses: Framework-R-D/action-workflow-setup@f73307dd8c13cb66c2565c9ace32571517b1cea8 # v1
with:
file-type: |
python
yaml
include-globs: |
scripts/**
ci/**
.devcontainer/**
head-ref: ${{ inputs.pr-head-sha }}
ref: ${{ inputs.ref }}
repo: ${{ inputs.repo }}
pr-base-sha: ${{ inputs.pr-base-sha }}
checkout-path: ${{ inputs.checkout-path }}
python-check:
needs: setup
if: >
always() && (
github.event_name == 'workflow_dispatch' ||
inputs.skip-relevance-check ||
needs.setup.outputs.has_changes == 'true'
)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref:
${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || needs.setup.outputs.ref }}
path: ${{ needs.setup.outputs.checkout_path }}
repository:
${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name ||
needs.setup.outputs.repo }}
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
- name: Install Python dependencies
run: uv tool install ruff && uv tool install mypy --with types-PyYAML
- name: Run ruff check
id: ruff
working-directory: ${{ needs.setup.outputs.checkout_path }}
env:
FORCE_COLOR: 1
run: |
echo "➡️ Checking Python code with ruff..."
ruff check
continue-on-error: true
- name: Run MyPy check
id: mypy
working-directory: ${{ needs.setup.outputs.checkout_path }}
run: |
echo "➡️ Checking Python code with MyPy..."
mypy --color-output .
continue-on-error: true
- name: Evaluate Python checks result
if: always() && (steps.ruff.outcome != 'skipped' || steps.mypy.outcome != 'skipped')
env:
REPO: ${{ needs.setup.outputs.repo }}
# yamllint disable rule:line-length
run: |
REPO_NAME="${REPO##*/}"
if [ "${{ steps.ruff.outcome }}" = 'success' ] && [ "${{ steps.mypy.outcome }}" = 'success' ]; then
echo "✅ Python checks passed."
else
echo "::error::Python checks failed. Comment '@${REPO_NAME}bot python-fix' on the PR to attempt auto-fix."
exit 1
fi
# yamllint enable
scripts-test:
needs: setup
if: >
always() && (
github.event_name == 'workflow_dispatch' ||
inputs.skip-relevance-check ||
needs.setup.outputs.has_changes == 'true'
)
strategy:
fail-fast: false
matrix:
arch:
- amd64
- arm64
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
permissions:
contents: read
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref:
${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || needs.setup.outputs.ref }}
path: ${{ needs.setup.outputs.checkout_path }}
repository:
${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name ||
needs.setup.outputs.repo }}
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
- name: Run scripts unit tests with coverage
working-directory: ${{ needs.setup.outputs.checkout_path }}
run: |
echo "➡️ Running scripts/ unit tests with coverage..."
uv run --python 3.12 --with pytest --with PyYAML --with pytest-cov \
pytest scripts/test/ -v \
--cov=scripts \
--cov=ci \
--cov=.devcontainer \
--cov-report="xml:${GITHUB_WORKSPACE}/coverage-scripts.xml" \
--cov-report=term-missing
- name: Upload scripts coverage to Codecov
if: ${{ hashFiles('coverage-scripts.xml') != '' }}
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
files: coverage-scripts.xml
flags: ${{ matrix.arch }}
name: phlex-scripts-coverage-${{ matrix.arch }}
fail_ci_if_error: false
verbose: true
root_dir: ${{ needs.setup.outputs.checkout_path || '.' }}
token: ${{ env.CODECOV_TOKEN }}