-
Notifications
You must be signed in to change notification settings - Fork 1
81 lines (71 loc) · 2.54 KB
/
format.yaml
File metadata and controls
81 lines (71 loc) · 2.54 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
name: Format
on:
workflow_call:
jobs:
format_check:
name: Verify Rider formatting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install JetBrains ReSharper Global Tools (jb)
run: |
dotnet tool install --global JetBrains.ReSharper.GlobalTools
echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
- name: Run Rider cleanup (dry-check via diff)
run: |
jb cleanupcode \
--profile="Built-in: Reformat Code" \
--no-build \
--verbosity=WARN \
--include="**/*.cs" \
--exclude="**/bin/**" \
--exclude="**/obj/**" \
--exclude="**/.idea/**" \
.
- name: Detect formatting changes (code files only)
id: diff
run: |
LIST_FILE="$RUNNER_TEMP/files_needing_format.txt"
CHANGED="$(git status --porcelain --untracked-files=no -- '*.cs' '*.csproj' '*.sln' | awk '{print $2}' | sort -u)"
if [[ -n "$CHANGED" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "$CHANGED" | tee "$LIST_FILE"
echo "list_file=$LIST_FILE" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "list_file=" >> "$GITHUB_OUTPUT"
fi
- name: Summarize unformatted files
if: steps.diff.outputs.changed == 'true'
run: |
{
echo "### ❌ Formatting check failed"
echo
echo "The following code files are not formatted properly:"
echo
echo '```'
cat "${{ steps.diff.outputs.list_file }}"
echo '```'
echo
echo "➡️ Run Rider **Code Cleanup** (Built-in: *Reformat Code*) locally and commit."
} >> "$GITHUB_STEP_SUMMARY"
- name: Annotate files in Checks UI
if: steps.diff.outputs.changed == 'true'
run: |
while IFS= read -r f; do
echo "::error file=$f,title=Not formatted::Run Rider Code Cleanup (Built-in: Reformat Code) and commit."
done < "${{ steps.diff.outputs.list_file }}"
- name: Revert any changes (always clean workspace)
if: always()
run: |
git restore --staged .
git checkout -- .
git clean -fd
- name: Fail job if formatting needed
if: steps.diff.outputs.changed == 'true'
run: exit 1