chore: add auto-fix workflow for dotnet format (#166)
Ajoute un workflow auto-fix qui tourne sur les PRs et corrige automatiquement les erreurs de format dotnet format whitespace. ## Changements - Nouveau workflow `auto-fix.yml` qui: - Vérifie le format au build - Si échec, applique le fix et push sur la branche PR - Poste un commentaire récapitulatif ## Activation Le cron `coding-orchestrator` tourne déjà toutes les 5min et gère les auto-fixes. Ce workflow est un filet de sécurité CI. Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/166
This commit is contained in:
1 parent
2d1734114f
commit
e2f77da896
1 file changed
+79
@@ -0,0 +1,79 @@
|
||||
name: Auto-Fix
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
auto-fix:
|
||||
name: Auto-Fix
|
||||
runs-on: debian-12
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- uses: https://forgejo.tordais.cc/actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: https://forgejo.tordais.cc/actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '10.0'
|
||||
|
||||
- name: Cache NuGet
|
||||
continue-on-error: true
|
||||
uses: https://forgejo.tordais.cc/actions/cache@v4
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj', '**/*.slnx') }}
|
||||
restore-keys: nuget-${{ runner.os }}-
|
||||
|
||||
- name: Restore
|
||||
run: dotnet restore Heimdall.slnx --nologo
|
||||
|
||||
- name: Auto-fix dotnet format
|
||||
id: fix
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
dotnet format Heimdall.slnx whitespace --verify-no-changes --no-restore 2>&1 | tee /tmp/format-check.log
|
||||
if [ ${PIPESTATUS[0]} -ne 0 ]; then
|
||||
echo "Format issues found — applying fix..."
|
||||
dotnet format Heimdall.slnx whitespace --no-restore
|
||||
DIFF=$(git diff --stat)
|
||||
if [ -n "$DIFF" ]; then
|
||||
git config user.name "coding-orchestrator"
|
||||
git config user.email "orchestrator@tordais.cc"
|
||||
git add .
|
||||
git commit -m "chore: auto-fix dotnet format whitespace"
|
||||
git push origin HEAD:${{ github.event.pull_request.head.ref }}
|
||||
echo "applied=true" >> $GITHUB_OUTPUT
|
||||
echo "Fixed files:"
|
||||
echo "$DIFF"
|
||||
else
|
||||
echo "applied=false" >> $GITHUB_OUTPUT
|
||||
echo "No actual changes after format"
|
||||
fi
|
||||
else
|
||||
echo "applied=false" >> $GITHUB_OUTPUT
|
||||
echo "Format OK"
|
||||
fi
|
||||
|
||||
- name: Post comment
|
||||
if: always()
|
||||
shell: bash
|
||||
env:
|
||||
FORGEJO_TOKEN: ${{ github.token }}
|
||||
REPO: ${{ github.repository }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
run: |
|
||||
BODY="## 🔧 Auto-Fix"
|
||||
BODY="$BODY\n\n**Projet:** Heimdall"
|
||||
if [ "${{ steps.fix.outputs.applied }}" = "true" ]; then
|
||||
BODY="$BODY\n\n✅ **dotnet format whitespace corrigé et poussé**"
|
||||
else
|
||||
BODY="$BODY\n\nℹ️ Aucun fix nécessaire"
|
||||
fi
|
||||
BODY="$BODY\n\n---\n_Ce commentaire est généré automatiquement par le workflow auto-fix._"
|
||||
curl -s -X POST "https://forgejo.tordais.cc/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" \
|
||||
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"body\": \"$(echo -e "$BODY")\"}" || true
|
||||
Reference in new issue
Block a user