-
-
Notifications
You must be signed in to change notification settings - Fork 28
43 lines (39 loc) · 1.24 KB
/
treefmt.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
40
41
42
43
name: Check formatting with treefmt
on:
[push, pull_request]
jobs:
treefmt:
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@v22
- uses: actions/checkout@v3
- id: files
uses: tj-actions/changed-files@v44
- name: Run treefmt
run: nix fmt
- name: Check diff
run: |
unformatted_touched=()
unformatted_untouched=()
while IFS= read -r unformatted_file; do
matched=
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ "$changed_file" == "$unformatted_file" ]]; then
unformatted_touched+=("$unformatted_file")
matched=1
break
fi
done
if [[ -z "$matched" ]]; then
unformatted_untouched+=("$unformatted_file")
fi
done <<< "$(git diff --name-only)"
if (( ${#unformatted_untouched[@]} )); then
echo "These files are not formatted, but out of scope of this PR:"
printf '%s\n' "${unformatted_untouched[@]}"
fi
if (( ${#unformatted_touched[@]} )); then
echo "These files are created/edited but not formatted:"
printf '%s\n' "${unformatted_touched[@]}"
exit 1
fi