-
Notifications
You must be signed in to change notification settings - Fork 122
63 lines (54 loc) · 2.19 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
#
# This workflow runs the dotnet formatter on all c-sharp code.
#
name: dotnet-format
on:
workflow_dispatch:
pull_request:
branches: [ "main", "feature*" ]
jobs:
check-format:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: jitterbit/get-changed-files@v1
- 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
if: steps.changed-files.outputs.added_modified != ''
run: |
csproj_files=()
for file in ${{ steps.changed-files.outputs.added_modified }}; do
echo "$file was changed"
dir="$GITHUB_WORKSPACE/$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=$(dirname $dir)
done
done
csproj_files=($(printf "%s\n" "${csproj_files[@]}" | sort -u))
echo "Found ${#csproj_files[@]} unique csproj files: ${csproj_files[*]}"
echo "::set-output name=csproj_files::${csproj_files[*]}"
- name: Install dotnet-format tool
if: steps.changed-files.outputs.added_modified != ''
run: dotnet tool install -g dotnet-format
# This step will run dotnet format on each of the unique csproj files and fail if any changes are made
- name: Run dotnet format
if: steps.changed-files.outputs.added_modified != ''
run: |
for csproj in ${{ steps.find-csproj.outputs.csproj_files }}; do
echo "Running dotnet format on $csproj"
dotnet format $csproj --verify-no-changes --verbosity detailed
done