@@ -121,10 +121,61 @@ jobs:
121121 demo/bin/Release/
122122 retention-days : 7
123123
124- code-quality :
124+ auto-format :
125125 runs-on : ubuntu-latest
126126 needs : [check-changes, build]
127- if : needs.check-changes.outputs.should-skip != 'true'
127+ if : needs.check-changes.outputs.should-skip != 'true' && github.event_name == 'push' && github.ref != 'refs/heads/main'
128+
129+ steps :
130+ - name : Checkout code
131+ uses : actions/checkout@v4
132+ with :
133+ token : ${{ secrets.GITHUB_TOKEN }}
134+ fetch-depth : 0
135+
136+ - name : Setup .NET
137+ uses : actions/setup-dotnet@v4
138+ with :
139+ dotnet-version : ${{ env.DOTNET_VERSION }}
140+
141+ - name : Restore dependencies
142+ run : dotnet restore
143+
144+ - name : Format code - Main Solution
145+ run : |
146+ echo "🔧 Formatting main solution..."
147+ dotnet format NLWebNet.sln --verbosity diagnostic
148+
149+ - name : Format code - AspireDemo Solution
150+ run : |
151+ echo "🔧 Formatting AspireDemo solution..."
152+ dotnet format samples/AspireDemo/NLWebNet.AspireDemo.sln --verbosity diagnostic
153+
154+ - name : Check for formatting changes
155+ id : format-check
156+ run : |
157+ if git diff --quiet; then
158+ echo "No formatting changes needed"
159+ echo "changes=false" >> $GITHUB_OUTPUT
160+ else
161+ echo "Formatting changes detected"
162+ echo "changes=true" >> $GITHUB_OUTPUT
163+ git status --porcelain
164+ fi
165+
166+ - name : Commit formatting changes
167+ if : steps.format-check.outputs.changes == 'true'
168+ run : |
169+ git config --local user.email "[email protected] " 170+ git config --local user.name "GitHub Action"
171+ git add .
172+ git commit -m "🔧 Auto-format code with dotnet format"
173+ git push
174+
175+ code-quality :
176+ runs-on : ubuntu-latest
177+ needs : [check-changes, build, auto-format]
178+ if : needs.check-changes.outputs.should-skip != 'true' && always() && (needs.auto-format.result == 'success' || needs.auto-format.result == 'skipped')
128179
129180 steps :
130181 - name : Checkout code
@@ -145,12 +196,15 @@ jobs:
145196 dotnet build --configuration Release --verbosity minimal --warnaserror
146197
147198 - name : Check formatting
148- run : dotnet format --verify-no-changes --verbosity diagnostic
199+ run : |
200+ echo "🔍 Checking code formatting..."
201+ dotnet format NLWebNet.sln --verify-no-changes --verbosity diagnostic
202+ dotnet format samples/AspireDemo/NLWebNet.AspireDemo.sln --verify-no-changes --verbosity diagnostic
149203
150204 security-scan :
151205 runs-on : ubuntu-latest
152- needs : [check-changes, build]
153- if : needs.check-changes.outputs.should-skip != 'true'
206+ needs : [check-changes, build, auto-format ]
207+ if : needs.check-changes.outputs.should-skip != 'true' && always() && (needs.auto-format.result == 'success' || needs.auto-format.result == 'skipped')
154208
155209 steps :
156210 - name : Checkout code
@@ -176,8 +230,8 @@ jobs:
176230
177231 package-validation :
178232 runs-on : ubuntu-latest
179- needs : [check-changes, build]
180- if : needs.check-changes.outputs.should-skip != 'true' && (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
233+ needs : [check-changes, build, auto-format ]
234+ if : needs.check-changes.outputs.should-skip != 'true' && always() && (needs.auto-format.result == 'success' || needs.auto-format.result == 'skipped') && (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
181235
182236 steps :
183237 - name : Checkout code
@@ -269,8 +323,8 @@ jobs:
269323
270324 docker-build :
271325 runs-on : ubuntu-latest
272- needs : [check-changes, build]
273- if : needs.check-changes.outputs.should-skip != 'true' && (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
326+ needs : [check-changes, build, auto-format ]
327+ if : needs.check-changes.outputs.should-skip != 'true' && always() && (needs.auto-format.result == 'success' || needs.auto-format.result == 'skipped') && (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
274328
275329 steps :
276330 - name : Checkout code
@@ -313,8 +367,8 @@ jobs:
313367 # Alternative: .NET SDK Container Build (modern approach)
314368 dotnet-container-build :
315369 runs-on : ubuntu-latest
316- needs : [check-changes, build]
317- if : needs.check-changes.outputs.should-skip != 'true' && (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
370+ needs : [check-changes, build, auto-format ]
371+ if : needs.check-changes.outputs.should-skip != 'true' && always() && (needs.auto-format.result == 'success' || needs.auto-format.result == 'skipped') && (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
318372
319373 steps :
320374 - name : Checkout code
0 commit comments