-
Notifications
You must be signed in to change notification settings - Fork 701
74 lines (64 loc) · 2.47 KB
/
dotnet-format.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
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
name: dotnet-format
on:
pull_request:
branches: ["main", "feature*"]
paths:
- "webapi/**"
- "tools/**"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
check-format:
runs-on: ubuntu-latest
env:
NUGET_CERT_REVOCATION_MODE: offline
steps:
- name: Check out code
uses: actions/checkout@v3
with:
clean: true
- name: Get changed files
id: changed-files
uses: jitterbit/get-changed-files@v1
continue-on-error: true
- name: No C# files changed
id: no-csharp
if: steps.changed-files.outputs.added_modified == ''
run: echo "No C# files changed"
# This step will loop over the changed files and find the nearest .csproj file for each one, then store the unique csproj files in a variable
- name: Find csproj files
id: find-csproj
run: |
csproj_files=()
if [[ ${{ steps.changed-files.outcome }} == 'success' ]]; then
for file in ${{ steps.changed-files.outputs.added_modified }}; do
echo "$file was changed"
dir="./$file"
while [[ $dir != "." && $dir != "/" && $dir != $GITHUB_WORKSPACE ]]; do
if find "$dir" -maxdepth 1 -name "*.csproj" -print -quit | grep -q .; then
csproj_files+=("$(find "$dir" -maxdepth 1 -name "*.csproj" -print -quit)")
break
fi
dir=$(echo ${dir%/*})
done
done
else
# if the changed-files step failed, run dotnet on the whole sln instead of specific projects
echo "Running dotnet format on whole solution"
csproj_files=$(find ./ -type f -name "*.sln" | tr '\n' ' ');
fi
csproj_files=($(printf "%s\n" "${csproj_files[@]}" | sort -u))
echo "Found ${#csproj_files[@]} unique csproj/sln files: ${csproj_files[*]}"
echo "csproj_files=${csproj_files[*]}" >> $GITHUB_OUTPUT
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Check formatting
if: steps.find-csproj.outputs.csproj_files != ''
run: |
for csproj in ${{ steps.find-csproj.outputs.csproj_files }}; do
echo "Checking formatting for $csproj"
dotnet format $csproj --verify-no-changes --verbosity diagnostic
done