Skip to content

Commit 53a80b9

Browse files
committed
CI: Add tests that validate that files are correctly tracked by Git LFS.
1 parent 868fa6f commit 53a80b9

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

.github/workflows/test-git-lfs.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test Git LFS Tracking
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
# pull_request is not supported for this workflow due to self-hosted runners
8+
# see the "Reviewing PRs from forks" section in CONTRIBUTING.md for more details
9+
10+
jobs:
11+
check-lfs:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Check that binary files are tracked by LFS
19+
run: |
20+
echo "Checking that all binary files are tracked by Git LFS..."
21+
22+
# File extensions that should be tracked by LFS (from .gitattributes)
23+
EXTENSIONS="pptx pdf png jpg jpeg gif webp"
24+
25+
# Build find pattern
26+
FIND_PATTERN=""
27+
for ext in $EXTENSIONS; do
28+
if [ -n "$FIND_PATTERN" ]; then
29+
FIND_PATTERN="$FIND_PATTERN -o"
30+
fi
31+
FIND_PATTERN="$FIND_PATTERN -name *.$ext"
32+
done
33+
34+
# Find all matching files
35+
FILES=$(find . -type f \( $FIND_PATTERN \) ! -path "./.git/*" ! -path "./venv/*" 2>/dev/null || true)
36+
37+
if [ -z "$FILES" ]; then
38+
echo "No binary files found to check."
39+
exit 0
40+
fi
41+
42+
FAILED=0
43+
NOT_LFS_FILES=""
44+
45+
for file in $FILES; do
46+
# Check if file is an LFS pointer (starts with "version https://git-lfs.github.com/spec/v1")
47+
if head -c 50 "$file" 2>/dev/null | grep -q "version https://git-lfs.github.com/spec/v1"; then
48+
echo "✓ $file (LFS pointer)"
49+
else
50+
echo "✗ $file (NOT tracked by LFS)"
51+
NOT_LFS_FILES="$NOT_LFS_FILES\n - $file"
52+
FAILED=1
53+
fi
54+
done
55+
56+
if [ $FAILED -eq 1 ]; then
57+
echo ""
58+
echo "=========================================="
59+
echo "ERROR: The following files should be tracked by Git LFS but are not:"
60+
echo -e "$NOT_LFS_FILES"
61+
echo ""
62+
echo "To fix this, run:"
63+
echo " git rm --cached <file>"
64+
echo " git add <file>"
65+
echo " git commit -m 'Track file with Git LFS'"
66+
echo ""
67+
echo "Make sure Git LFS is installed and .gitattributes includes the file pattern."
68+
echo "=========================================="
69+
exit 1
70+
fi
71+
72+
echo ""
73+
echo "All binary files are properly tracked by Git LFS!"

0 commit comments

Comments
 (0)