-
Notifications
You must be signed in to change notification settings - Fork 1.2k
132 lines (124 loc) · 4.43 KB
/
Copy pathcode_quality.yml
File metadata and controls
132 lines (124 loc) · 4.43 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
name: Code Quality
env:
PYTHON_VERSION: "3.12"
on:
pull_request:
workflow_dispatch:
inputs:
commit_id:
description: 'Branch or Commit ID (optional)'
required: false
type: string
schedule:
# Run at 10:00 UTC every day
- cron: "00 10 * * *"
jobs:
format_ruff:
name: Check format with ruff
runs-on: ubuntu-latest
permissions:
checks: write
steps:
- name: Check out repo ${{ github.event_name == 'workflow_dispatch' && inputs.commit_id || github.sha }}
uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.commit_id || github.sha }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up uv
uses: astral-sh/setup-uv@v8.1.0
- name: Do dev install
run: uv pip install --system -e .[dev]
- name: Check format with ruff
shell: bash
id: check_format
continue-on-error: true
run: |
if ! ruff format --check; then
echo "::warning title=ruff format::Files need re-formatting (run 'ruff format .' locally)"
exit 78 # no longer works in github, but would mark action step with a warning
fi
- name: Check imports with ruff
shell: bash
id: check_import
continue-on-error: true
run: |
# This is separate from formatting. See:
# https://docs.astral.sh/ruff/formatter/#sorting-imports
if ! ruff check --select I,RUF022; then
echo "::warning title=ruff import::Files need import sorting (run 'ruff check --select I,RUF022 --fix' locally to auto-fix)"
exit 78 # no longer works in github, but would mark action step with a warning
fi
- name: Mark step with a warning
if: ${{ steps.check_format.outcome == 'failure' || steps.check_import.outcome == 'failure' }}
uses: actions/github-script@v9
with:
script: |
await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Failed ruff checks',
head_sha: context.sha,
status: 'completed',
conclusion: 'neutral',
completed_at: new Date().toISOString(),
output: {
title: 'ruff found violations',
summary: 'Run `ruff format . and `ruff check --select I,RUF022 --fix` locally and push the changes.'
}
})
# Have a separate workflow because we don't want to enforce this at all
# It will have too many errors initially and is likely to deter contributors
ruff-linting:
name: Linting with ruff
runs-on: ubuntu-latest
permissions:
checks: read
steps:
- name: Check out repo ${{ github.event_name == 'workflow_dispatch' && inputs.commit_id || github.sha }}
uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.commit_id || github.sha }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up uv
uses: astral-sh/setup-uv@v8.1.0
- name: Do dev install
run: uv pip install --system -e .[dev]
- name: Run ruff linting
shell: bash
continue-on-error: true
run: |
ruff check
run-mypy:
name: Run informational mypy
runs-on: ubuntu-latest
permissions:
checks: read
steps:
- name: Check out repo ${{ github.event_name == 'workflow_dispatch' && inputs.commit_id || github.sha }}
uses: actions/checkout@v6
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.commit_id || github.sha }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up uv
uses: astral-sh/setup-uv@v8.1.0
- name: Do guidance install
run: uv pip install --system -e .[all,dev]
- name: Get mypy type packages
continue-on-error: true
run: mypy --install-types --non-interactive guidance
- name: Run mypy
shell: bash
continue-on-error: true
run: |
mypy guidance
echo "==========================================="
echo "Done"