Skip to content

Commit 85642d8

Browse files
ci: update (#45)
1 parent 8cdd28c commit 85642d8

File tree

9 files changed

+119
-60
lines changed

9 files changed

+119
-60
lines changed

.github/workflows/build.yml

Lines changed: 58 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
on:
22
push:
3-
pull_request:
43

54
name: continuous integration
65

@@ -16,23 +15,6 @@ jobs:
1615
all_but_latest: true
1716
access_token: ${{ github.token }}
1817

19-
check_imported:
20-
name: Check all files imported
21-
runs-on: ubuntu-latest
22-
steps:
23-
- name: cleanup
24-
run: |
25-
find . -name . -o -prune -exec rm -rf -- {} +
26-
27-
- uses: actions/checkout@v4
28-
29-
- name: update Algorithm.lean
30-
run: |
31-
git ls-files 'Algorithm/*.lean' | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Algorithm.lean
32-
33-
- name: check that all files are imported
34-
run: git diff --exit-code
35-
3618
build:
3719
name: Build
3820
runs-on: ubuntu-latest
@@ -56,18 +38,12 @@ jobs:
5638
- name: install elan
5739
run: |
5840
set -o pipefail
59-
curl -sSfL https://github.com/leanprover/elan/releases/download/v3.0.0/elan-x86_64-unknown-linux-gnu.tar.gz | tar xz
41+
curl -sSfL https://github.com/leanprover/elan/releases/download/v3.1.1/elan-x86_64-unknown-linux-gnu.tar.gz | tar xz
6042
./elan-init -y --default-toolchain none
6143
echo "$HOME/.elan/bin" >> "${GITHUB_PATH}"
6244
6345
- uses: actions/checkout@v4
6446

65-
# We update `Algorithm.lean` as a convenience here,
66-
# but verify that this didn't change anything in the `check_imported` job.
67-
- name: update Algorithm.lean
68-
run: |
69-
find Algorithm -name "*.lean" | LC_ALL=C sort | sed 's/\.lean//;s,/,.,g;s/^/import /' > Algorithm.lean
70-
7147
- name: If using a lean-pr-release toolchain, uninstall
7248
run: |
7349
if [[ $(cat lean-toolchain) =~ ^leanprover/lean4-pr-releases:pr-release-[0-9]+$ ]]; then
@@ -94,17 +70,71 @@ jobs:
9470
rm -rf .lake/packages/proofwidgets/.lake/build/ir
9571
9672
- name: get cache
73+
id: get
74+
run: |
75+
rm -rf .lake/build/lib/Mutable/
76+
rm -rf .lake/build/lib/Algorithm/
77+
# Fail quickly if the cache is completely cold, by checking for Mathlib.Init
78+
lake exe cache get Mathlib.Init
79+
lake build --no-build Mathlib.Init && lake exe cache get || echo "No cache for 'Mathlib.Init' available"
80+
81+
- name: update {Mutable, Algorithm}.lean
82+
id: mk_all
9783
run: |
98-
lake exe cache clean
99-
lake exe cache get
84+
85+
if ! lake exe mk_all --check
86+
then
87+
echo "Not all lean files are in the import all files"
88+
echo "mk_all=false" >> "${GITHUB_OUTPUT}"
89+
else
90+
echo "mk_all=true" >> "${GITHUB_OUTPUT}"
91+
fi
10092
10193
- name: build algorithm
10294
id: build
10395
uses: liskin/gh-problem-matcher-wrap@v3
10496
with:
10597
linters: gcc
10698
run: |
107-
bash -o pipefail -c "env LEAN_ABORT_ON_PANIC=1 lake build -KCI | tee stdout.log"
99+
bash -o pipefail -c "env LEAN_ABORT_ON_PANIC=1 lake build --wfail -KCI"
100+
101+
- name: Check {Mutable, Algorithm}.lean
102+
run: |
103+
if [ ${{ steps.mk_all.outputs.mk_all }} == "false" ]
104+
then
105+
echo "Please run 'lake exe mk_all' to regenerate the import all files"
106+
exit 1
107+
fi
108+
109+
- name: check for noisy stdout lines
110+
id: noisy
111+
run: |
112+
buildMsgs="$(
113+
## we exploit `lake`s replay feature: since the cache is present, running
114+
## `lake build` will reproduce all the outputs without having to recompute
115+
lake build Mutable Algorithm |
116+
## we filter out the output lines that begin with `✔ [xx/yy]`, where xx, yy
117+
## are either numbers or ?, and the "Build completed successfully." message.
118+
## We keep the rest, which are actual outputs of the files
119+
awk '!($0 ~ "^\\s*✔ \\[[?0-9]*/[?0-9]*\\]" || $0 == "Build completed successfully."){ print $0 }')"
120+
if [ -n "${buildMsgs}" ]
121+
then
122+
printf $'%s\n' "${buildMsgs}"
123+
exit 1
124+
fi
125+
126+
- name: verify `lake exe graph` works
127+
run: |
128+
lake exe graph
129+
rm import_graph.dot
130+
131+
# - name: test algorithm
132+
# id: test
133+
# uses: liskin/gh-problem-matcher-wrap@v3
134+
# with:
135+
# linters: gcc
136+
# run:
137+
# lake test
108138

109139
- name: check for unused imports
110140
id: shake
@@ -120,10 +150,3 @@ jobs:
120150
with:
121151
linters: gcc
122152
run: env LEAN_ABORT_ON_PANIC=1 lake exe runLinter Algorithm
123-
124-
- name: check for noisy stdout lines
125-
id: noisy
126-
run: |
127-
grep --after-context=1 "stdout" stdout.log && ret=0
128-
grep --after-context=1 "stderr" stdout.log && new=0
129-
if [ "${ret}" == "0" ] || [ "${new}" == "0" ]; then exit 1; fi

lakefile.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ extern_lib libleanffi pkg := do
3434
let name := nameToStaticLib "leanffi"
3535
let ffiO ← ffi.o.fetch
3636
buildStaticLib (pkg.nativeLibDir / name) #[ffiO]
37+
38+
-- @[test_driver]
39+
-- lean_exe test where
40+
-- srcDir := "scripts"

scripts/test.lean

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/-
2+
Copyright (c) 2024 Kim Morrison. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kim Morrison
5+
-/
6+
open IO.Process
7+
open System
8+
9+
/--
10+
Run tests, via the Batteries test runner.
11+
12+
When https://github.com/leanprover/lean4/issues/4121
13+
"allow using an upstream executable as a lake `@[test_runner]`"
14+
is resolved, this file can be replaced with a line in `lakefile.lean`.
15+
-/
16+
def main (args : List String) : IO Unit := do
17+
-- ProofWidgets and Batteries may not have been completely built by `lake build` yet,
18+
-- but they are needed by some tests.
19+
_ ← (← spawn { cmd := "lake", args := #["build", "ProofWidgets", "Batteries"] }).wait
20+
let exitcode ← (← spawn { cmd := "lake", args := #["exe", "batteries/test"] ++ args }).wait
21+
exit exitcode.toUInt8

test/Mutable/thunk1.lean

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,43 @@ protected def Thunk'.get (x : Thunk' α) : α :=
2222

2323
/-! lean4/tests/lean/thunk.lean -/
2424

25-
#eval (Thunk'.pure 1).get
26-
#eval (Thunk'.mk fun _ => 2).get
27-
#eval
25+
/-- info: 1 -/
26+
#guard_msgs in #eval
27+
(Thunk'.pure 1).get
28+
/-- info: 2 -/
29+
#guard_msgs in #eval (Thunk'.mk fun _ => 2).get
30+
/--
31+
info: 3
32+
4
33+
5
34+
-/
35+
#guard_msgs in #eval
2836
let t1 := Thunk'.mk fun _ => dbg_trace 4; 5
2937
-- let t2 := Thunk'.mk fun _ => dbg_trace 3; 0
3038
-- let v2 := t2.get
3139
let v2 := dbg_trace 3; 0
3240

3341
let v1 := t1.get
3442
v1 + v2
35-
#eval
43+
/--
44+
info: 6
45+
7
46+
8
47+
-/
48+
#guard_msgs in #eval
3649
let t1 := Thunk'.pure 8 |>.map fun n => dbg_trace 7; n
3750
-- let t2 := Thunk'.mk fun _ => dbg_trace 6; 0
3851
-- let v2 := t2.get
3952
let v2 := dbg_trace 6; 0
4053

4154
let v1 := t1.get
4255
v1 + v2
43-
#eval
56+
/--
57+
info: 9
58+
10
59+
11
60+
-/
61+
#guard_msgs in #eval
4462
let t1 := Thunk'.pure 11 |>.bind fun n => dbg_trace 10; Thunk'.pure n
4563
-- let t2 := Thunk'.mk fun _ => dbg_trace 9; 0
4664
-- let v2 := t2.get

test/Mutable/thunk1.lean.expected.out

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/Mutable/thunk2.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ def test (t : Thunk' Nat) (n : Nat) : Nat :=
2626
def main : IO Unit :=
2727
IO.println (toString (test (compute 1) 100000))
2828

29-
#eval main
29+
/-- info: 10000000000 -/
30+
#guard_msgs in #eval main -- TODO: 超时中断

test/Mutable/thunk2.lean.expected.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/UnionFind.lean

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ import Algorithm.Data.UnionFind
33
abbrev Vector := Batteries.Vector
44
abbrev UF := UnionFind (Fin 10) (Vector (Fin 10) 10) (Vector Nat 10)
55

6-
#eval show IO Unit from do
6+
/--
7+
info: 1
8+
2
9+
-/
10+
#guard_msgs in #eval show IO Unit from do
711
let mut uf : UF := default
812
IO.println (uf.find 1)
913
uf := uf.union 1 2
1014
uf := uf.union 3 4
1115
uf := uf.union 2 4
1216
IO.println ((Quot.unquot (Mutable.get uf)).val.parent[(1 : Fin 10)])
1317

14-
#eval show IO Unit from do
18+
/--
19+
info: 1
20+
4
21+
4
22+
-/
23+
#guard_msgs in #eval show IO Unit from do
1524
let mut uf : UF := default
1625
IO.println (uf.find 1)
1726
uf := uf.union 1 2

test/UnionFind.lean.expected.out

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)