From e2f77da896dea090535e9ebe406e9b2b6c50ae5d Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Wed, 26 Aug 2026 12:25:50 +0200 Subject: [PATCH] chore: add auto-fix workflow for dotnet format (#166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .forgejo/workflows/auto-fix.yml | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .forgejo/workflows/auto-fix.yml diff --git a/.forgejo/workflows/auto-fix.yml b/.forgejo/workflows/auto-fix.yml new file mode 100644 index 0000000..414057c --- /dev/null +++ b/.forgejo/workflows/auto-fix.yml @@ -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