Skip to content

Commit 6bd8d41

Browse files
committed
add safety scripts
1 parent c9fb940 commit 6bd8d41

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

scripts/install_pre-push.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# Rename the pre-push sample file if it exists
4+
if [ -f ".git/hooks/pre-push.sample" ]; then
5+
mv .git/hooks/pre-push.sample .git/hooks/pre-push
6+
fi
7+
8+
# Copy the content of scripts/pre-push into .git/hooks/pre-push
9+
cp scripts/pre-push.sh .git/hooks/pre-push
10+
11+
# Make the pre-push hook executable
12+
chmod +x .git/hooks/pre-push
13+
14+
echo "Pre-push hook installed."

scripts/pre-push.sh

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
3+
################################################################################
4+
# TEST SCRIPT TO RUN BEFORE PUSHING CHANGES
5+
#
6+
# This script ensures that the key components of the Lean project are functional
7+
# before changes are pushed to the repository by checking that:
8+
# 1. You are in the correct directory;
9+
# 2. The project builds successfully;
10+
# 3. The blueprint is successfully generated in both PDF and web versions;
11+
# 4. LaTeX declarations in the blueprint match Lean declarations in the codebase.
12+
################################################################################
13+
14+
# Ensure the script is in the outermost 'FLT' folder
15+
echo "Checking if you are in the correct directory..."
16+
if [ ! -f lakefile.lean ]; then
17+
echo "❌ Error: This doesn't appear to be the outermost 'FLT' directory.
18+
Please run this script from the correct folder."
19+
exit 1
20+
else
21+
echo "✅ Correct directory detected."
22+
fi
23+
24+
# Get Mathlib cache
25+
echo "Attempting to get Mathlib cache..."
26+
if ! lake exe cache get; then
27+
echo "❌ Error: Failed to get Mathlib cache. Continuing without cache."
28+
else
29+
echo "✅ Mathlib cache successfully retrieved."
30+
fi
31+
32+
# Build the project
33+
echo "Building the project..."
34+
if ! lake build FLT; then
35+
echo "❌ Error: Project build failed. Please check the code for errors."
36+
exit 1
37+
else
38+
echo "✅ Project build completed successfully."
39+
fi
40+
41+
# Generate the PDF version of the blueprint
42+
echo "Generating PDF version of the blueprint..."
43+
if ! leanblueprint pdf; then
44+
echo "❌ Error: Failed to generate PDF version of the blueprint."
45+
exit 1
46+
else
47+
echo "✅ PDF version of the blueprint generated successfully."
48+
fi
49+
50+
# Generate the web version of the blueprint
51+
echo "Generating web version of the blueprint..."
52+
if ! leanblueprint web; then
53+
echo "❌ Error: Failed to generate web version of the blueprint."
54+
exit 1
55+
else
56+
echo "✅ Web version of the blueprint generated successfully."
57+
fi
58+
59+
# Check declarations
60+
echo "Checking if Lean declarations in the blueprint match the codebase..."
61+
if ! lake exe checkdecls blueprint/lean_decls; then
62+
echo "❌ Error: Some declarations in the blueprint do not match Lean declarations in the codebase."
63+
exit 1
64+
else
65+
echo "✅ All declarations match successfully."
66+
fi
67+
68+
# Final message on test completion
69+
echo "🎉 All steps completed successfully! You are ready to push."

scripts/run_before_push.sh

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
3+
################################################################################
4+
# TEST SCRIPT TO RUN BEFORE PUSHING CHANGES
5+
#
6+
# This script ensures that the key components of the Lean project are functional
7+
# before changes are pushed to the repository by checking that:
8+
# 1. You are in the correct directory;
9+
# 2. The project builds successfully;
10+
# 3. The blueprint is successfully generated in both PDF and web versions;
11+
# 4. LaTeX declarations in the blueprint match Lean declarations in the codebase.
12+
################################################################################
13+
14+
# Ensure the script is in the outermost 'FLT' folder
15+
echo "Checking if you are in the correct directory..."
16+
if [ ! -f lakefile.lean ]; then
17+
echo "❌ Error: This doesn't appear to be the outermost 'FLT' directory.
18+
Please run this script from the correct folder."
19+
echo "Press any key to exit..."
20+
read
21+
exit 1
22+
fi
23+
echo "✅ Correct directory detected."
24+
25+
# Get Mathlib cache
26+
echo "Attempting to get Mathlib cache..."
27+
if ! lake exe cache get; then
28+
echo "❌ Error: Failed to get Mathlib cache. Continuing without cache."
29+
else
30+
echo "✅ Mathlib cache successfully retrieved."
31+
fi
32+
33+
# Build the project
34+
echo "Building the project..."
35+
if ! lake build FLT; then
36+
echo "❌ Error: Project build failed. Please check the code for errors."
37+
echo "Press any key to exit..."
38+
read
39+
exit 1
40+
else
41+
echo "✅ Project build completed successfully."
42+
fi
43+
44+
# Generate the PDF version of the blueprint
45+
echo "Generating PDF version of the blueprint..."
46+
if ! leanblueprint pdf; then
47+
echo "❌ Error: Failed to generate PDF version of the blueprint."
48+
echo "Press any key to exit..."
49+
read
50+
exit 1
51+
else
52+
echo "✅ PDF version of the blueprint generated successfully."
53+
fi
54+
55+
# Generate the web version of the blueprint
56+
echo "Generating web version of the blueprint..."
57+
if ! leanblueprint web; then
58+
echo "❌ Error: Failed to generate web version of the blueprint."
59+
echo "Press any key to exit..."
60+
read
61+
exit 1
62+
else
63+
echo "✅ Web version of the blueprint generated successfully."
64+
fi
65+
66+
# Check declarations
67+
echo "Checking if Lean declarations in the blueprint match the codebase..."
68+
if ! lake exe checkdecls blueprint/lean_decls; then
69+
echo "❌ Error: Some declarations in the blueprint do not match Lean declarations in the codebase."
70+
echo "Press any key to exit..."
71+
read
72+
exit 1
73+
else
74+
echo "✅ All declarations match successfully."
75+
fi
76+
77+
# Final message on test completion
78+
echo "🎉 All steps completed successfully! You are ready to push."

0 commit comments

Comments
 (0)