-
Notifications
You must be signed in to change notification settings - Fork 111
40 lines (32 loc) · 1.06 KB
/
git-lfs-check.yml
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
name: Check git-lfs files
on:
push:
branches: [ 'main', 'release-*' ]
pull_request:
branches: [ 'main', 'release-*' ]
jobs:
git-lfs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
lfs: true
- name: Check git-lfs files
run: |
files=$(git diff --name-status origin/main...HEAD | awk '$1 != "D" && /\.o$/ { print $2 }' || true)
if [ -z "$files" ]; then
echo "No .o files modified"
exit 0
fi
for file in $files; do
contents=$(git cat-file -p :$file)
# Check if the file is binary or an LFS pointer
if [[ $contents == *"version https://git-lfs.github.com/spec/v1"* ]]; then
echo "The file '$file' is correctly tracked by LFS."
elif [[ ! $contents =~ ^[[:print:]]*$ ]]; then
echo "Error: The file '$file' is a binary file and should not be committed directly."
exit 1
fi
done