-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (93 loc) · 3.52 KB
/
format.yaml
File metadata and controls
105 lines (93 loc) · 3.52 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: format_check
on:
workflow_call:
jobs:
format_check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x
- name: Install JetBrains ReSharper Global Tools (jb)
shell: bash
run: |
set -euo pipefail
cd /tmp
dotnet tool install --global JetBrains.ReSharper.GlobalTools
echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
- name: Discover all solutions
id: discover
shell: bash
run: |
set -euo pipefail
git ls-files '*.sln' > solutions.txt || true
echo "Found solution files:"
cat solutions.txt || true
count=$(wc -l < solutions.txt | tr -d ' ')
echo "solution_count=$count" >> "$GITHUB_OUTPUT"
- name: Check formatting
shell: bash
run: |
set -euo pipefail
ROOT="${GITHUB_WORKSPACE}"
count="${{ steps.discover.outputs.solution_count }}"
if [ "$count" != "0" ]; then
echo "==> Formatting all discovered .sln files"
while IFS= read -r sln; do
[ -z "$sln" ] && continue
echo "==> Restoring $sln"
dotnet restore "$sln"
echo "==> Running jb cleanupcode on $sln"
jb cleanupcode "$sln" \
--profile="Built-in: Reformat Code" \
--no-build \
--verbosity=WARN \
--include="$ROOT/Assets/**/*.cs" \
--exclude="$ROOT/**/bin/**" \
--exclude="$ROOT/**/obj/**" \
--exclude="$ROOT/**/.idea/**" \
--exclude="$ROOT/**/Library/**" \
--exclude="$ROOT/**/Logs/**" \
--exclude="$ROOT/**/Temp/**"
done < solutions.txt
else
echo "==> No .sln files found. Running jb cleanupcode by glob include (absolute paths)."
jb cleanupcode "$ROOT" \
--profile="Built-in: Reformat Code" \
--verbosity=WARN \
--include="$ROOT/Assets/**/*.cs" \
--exclude="$ROOT/**/bin/**" \
--exclude="$ROOT/**/obj/**" \
--exclude="$ROOT/**/.idea/**" \
--exclude="$ROOT/**/Library/**" \
--exclude="$ROOT/**/Logs/**" \
--exclude="$ROOT/**/Temp/**"
fi
- name: Diff & annotate unformatted files (fail if any)
shell: bash
run: |
set -euo pipefail
DIFF_FILE=cleanup.diff
git --no-pager diff --unified=0 -- 'Assets/**/*.cs' > "$DIFF_FILE" || true
git --no-pager diff --name-only -- 'Assets/**/*.cs' || true
if [ -s "$DIFF_FILE" ]; then
echo "Unformatted changes detected in Assets/:"
awk '
BEGIN { file="" }
/^\+\+\+ b\// { sub(/^\+\+\+ b\//, "", $0); file=$0; next }
/^@@ / {
match($0, /\+([0-9]+)(,([0-9]+))?/, m)
start = m[1]
printf("::error file=%s,line=%d,title=Formatting differs::Run Rider Code Cleanup (or jb cleanupcode) locally and commit.\n", file, start)
}
' "$DIFF_FILE"
echo "::error title=Formatting check failed::Some files under Assets/ differ from the configured formatting."
exit 1
else
echo "Formatting is clean in Assets/."
fi