-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (200 loc) · 8.07 KB
/
Copy pathlint-blueprint.yml
File metadata and controls
225 lines (200 loc) · 8.07 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Lint blueprint
on:
push:
branches:
- main
paths:
- '**.lean'
- 'lakefile.*'
- 'lean-toolchain'
- 'lake-manifest.json'
- '.github/workflows/lint-blueprint.yml'
- 'blueprint/src/**'
- 'blueprint/.chktexrc'
- 'blueprint/latexindent.yaml'
- 'scripts/blueprint_bibtex.py'
- 'scripts/blueprint_lean_sync.py'
- 'scripts/check_reader_facing_prose.py'
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**.lean'
- 'lakefile.*'
- 'lean-toolchain'
- 'lake-manifest.json'
- '.github/workflows/lint-blueprint.yml'
- 'blueprint/src/**'
- 'blueprint/.chktexrc'
- 'blueprint/latexindent.yaml'
- 'scripts/blueprint_bibtex.py'
- 'scripts/blueprint_lean_sync.py'
- 'scripts/check_reader_facing_prose.py'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint-blueprint:
runs-on: ubuntu-latest
name: Check blueprint compiles without errors
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check reader-facing prose patterns
if: github.event_name == 'pull_request'
env:
BASE_REF: origin/${{ github.event.pull_request.base.ref }}
run: |
git fetch --no-tags origin "+refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}"
python3 scripts/check_reader_facing_prose.py --root . --diff-base "$BASE_REF" --ci
- name: Detect changed Lean files
id: changed-lean-files
if: github.event_name == 'pull_request'
env:
BASE_REF: origin/${{ github.event.pull_request.base.ref }}
run: |
git fetch --no-tags origin "+refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }}"
changed_lean_paths="$(git diff --merge-base --name-only "$BASE_REF" -- \
TNLean.lean 'TNLean/**/*.lean' lakefile.* lean-toolchain lake-manifest.json)"
if [ -n "$changed_lean_paths" ]; then
has_changed_lean=true
else
has_changed_lean=false
while IFS= read -r tex_file; do
if [ -f "$tex_file" ] && grep -Eq '\\lean\{|\\uses\{|\\leanok|\\notready' "$tex_file"; then
has_changed_lean=true
break
fi
base_tex="$(git show "$BASE_REF:$tex_file" 2>/dev/null || true)"
if [ -n "$base_tex" ] \
&& grep -Eq '\\lean\{|\\uses\{|\\leanok|\\notready' <<< "$base_tex"; then
has_changed_lean=true
break
fi
done < <(git diff --merge-base --name-only "$BASE_REF" -- \
'blueprint/src/**/*.tex' 'blueprint/src/*.tex')
fi
echo "has_changed_lean=$has_changed_lean" >> "$GITHUB_OUTPUT"
- name: Set up Lean toolchain
id: lean-setup
if: github.event_name != 'pull_request' || steps.changed-lean-files.outputs.has_changed_lean == 'true'
continue-on-error: true
timeout-minutes: 6
uses: texra-ai/lean-env-action@v1
- name: Install blueprint system dependencies
uses: texra-ai/lean-env-action/blueprint-system-deps@v1
- name: Install blueprint Python dependencies
uses: texra-ai/lean-env-action/leanblueprint@v1
- name: Check tensor-network diagram macros
run: |
cd blueprint/src
PYTHONPATH=Packages python3 Packages/tn_diagrams.py \
--check \
--check-peps-usage \
--smoke-render
- name: Lint LaTeX (chktex)
run: |
cd blueprint/src
find . -name '*.tex' -not -path '*/Packages/*' -print0 \
| xargs -0 -r chktex -q -l ../.chktexrc
# TODO: drop continue-on-error after a separate mechanical PR has run
# `latexindent -l blueprint/latexindent.yaml -w -s` over blueprint/src.
- name: Check LaTeX formatting (latexindent)
continue-on-error: true
timeout-minutes: 5
run: |
set -e
status=0
while IFS= read -r f; do
if ! latexindent -k -s -l blueprint/latexindent.yaml "$f" > /dev/null; then
echo "::warning file=$f::not formatted to blueprint/latexindent.yaml; run 'latexindent -l blueprint/latexindent.yaml -w -s \"$f\"' locally to fix"
status=1
fi
done < <(find blueprint/src -name '*.tex' -not -path '*/Packages/*')
exit $status
- name: Build blueprint bibliography
run: python3 scripts/blueprint_bibtex.py
- name: Run leanblueprint web and check for errors
working-directory: blueprint
run: |
set -o pipefail
tmp_output_file="$(mktemp)"
# Run leanblueprint, streaming output to the log and capturing it to a file
set +o pipefail
leanblueprint web 2>&1 | tee "$tmp_output_file"
cmd_status=${PIPESTATUS[0]}
set -o pipefail
# Check for blueprint ERROR lines in the captured output
if grep -q "^ERROR:" "$tmp_output_file"; then
echo "::error::Blueprint has unresolved labels (see ERROR lines above)"
exit 1
fi
if grep -q "WARNING: File not found:" "$tmp_output_file"; then
echo "::warning::Blueprint has missing file references (see WARNING lines above)"
fi
# If leanblueprint itself failed, propagate its exit status
if [ "$cmd_status" -ne 0 ]; then
exit "$cmd_status"
fi
- name: Generate lean_decls from blueprint .tex files
id: lean-decls
run: python3 scripts/blueprint_lean_sync.py --root . --update-lean-decls
- name: Check blueprint and Lean source stay in sync
if: steps.lean-decls.outcome == 'success'
run: python3 scripts/blueprint_lean_sync.py --root . --ci
- name: Fetch PR base ref for diff
id: fetch-base-ref
if: github.event_name == 'pull_request' && steps.lean-setup.outcome == 'success'
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: git fetch --no-tags origin "$BASE_REF"
- name: Error on changed Lean declarations missing blueprint entries
if: github.event_name == 'pull_request' && steps.lean-setup.outcome == 'success'
env:
BASE_REF: origin/${{ github.event.pull_request.base.ref }}
run: |
python3 - <<'PY'
import os
import subprocess
base_ref = os.environ["BASE_REF"]
changed = subprocess.check_output(
[
"git",
"diff",
"--merge-base",
"--name-only",
"--diff-filter=AMR",
base_ref,
"--",
"TNLean.lean",
"TNLean/**/*.lean",
],
text=True,
)
changed_lean_files = [line for line in changed.splitlines() if line.endswith(".lean")]
if not changed_lean_files:
print("No changed TNLean/*.lean files in this pull request.")
raise SystemExit(0)
subprocess.run(
[
"python3",
"scripts/blueprint_lean_sync.py",
"--root",
".",
"--warn-missing-blueprint",
"--diff-base",
base_ref,
"--changed-files",
*changed_lean_files,
],
check=True,
)
PY
- name: Check blueprint Lean declarations
if: steps.lean-setup.outcome == 'success' && steps.lean-decls.outcome == 'success'
continue-on-error: true
timeout-minutes: 10
run: |
if ! lake exe checkdecls blueprint/lean_decls; then
echo "::warning::Some blueprint/lean_decls entries have no matching Lean declaration yet (this is expected while formalization is in progress)"
fi