From 86cbfd55cdd06662d09338866008da66769832d6 Mon Sep 17 00:00:00 2001 From: razinkele Date: Sun, 4 Jan 2026 21:21:40 +0200 Subject: [PATCH 1/4] chore(ci): add workflow to auto-fix formatting and open diagnostic PRs for CI failures --- .github/workflows/ci-auto-fix.yml | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 .github/workflows/ci-auto-fix.yml diff --git a/.github/workflows/ci-auto-fix.yml b/.github/workflows/ci-auto-fix.yml new file mode 100644 index 0000000..88e7059 --- /dev/null +++ b/.github/workflows/ci-auto-fix.yml @@ -0,0 +1,79 @@ +name: CI Auto-Fix + +on: + workflow_run: + workflows: ["CI"] + types: [completed] + +jobs: + auto_fix: + if: github.event.workflow_run.conclusion == 'failure' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install dev deps + run: python -m pip install -e '.[dev]' + + - name: Run ruff and black auto-fixes + run: | + set -e + ruff format --quiet --fix . || true + black --quiet . || true + + - name: Check for formatting changes + id: git-check + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + if [ -n "$(git status --porcelain)" ]; then echo "changed=true" >> $GITHUB_OUTPUT; else echo "changed=false" >> $GITHUB_OUTPUT; fi + + - name: Create branch and PR for formatting fixes + if: steps.git-check.outputs.changed == 'true' + env: + BRANCH_NAME: auto/ci-fix/format-${{ github.run_id }} + run: | + git checkout -b "$BRANCH_NAME" + git add -A + git commit -m "style: apply ruff/black fixes from CI auto-fix" + git push origin "$BRANCH_NAME" + gh pr create --title "style: apply ruff/black fixes (auto)" --body "Automated formatting fixes (ruff/black) applied by CI Auto-Fix workflow. This PR will be auto-merged when checks pass." --base main --head "$BRANCH_NAME" --label "chore" --web || true + + - name: Run tests to check if fixes pass + run: python -m pytest -q || true + + - name: Create draft PR on other failures + if: steps.git-check.outputs.changed == 'false' + run: | + echo "Opening draft PR for CI failure diagnostics" + BRANCH=auto/ci-fix/failure-${{ github.run_id }} + git checkout -b "$BRANCH" + # Add a short diagnostic file for human triage + echo "CI failure triggered by workflow_run id: ${{ github.event.workflow_run.id }}" > CI_FAILURE.md + git add CI_FAILURE.md + git commit -m "ci: record CI failure for diagnostics" + git push origin "$BRANCH" + gh pr create --title "ci: investigate failing CI run #${{ github.event.workflow_run.id }}" --body "Draft PR created automatically to investigate CI failure (workflow_run id: ${{ github.event.workflow_run.id }}). Please see workflow run logs for details." --base main --head "$BRANCH" --draft --label "ci-fail" --web || true + + - name: Comment on original run + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const runId = context.payload.workflow_run.id + const owner = context.repo.owner + const repo = context.repo.repo + await github.rest.actions.createWorkflowRunComment({ + owner, repo, run_id: runId, body: 'CI Auto-Fix ran: formatting fixes applied or diagnostic PR created.' + }) From a74c3e60597d7adedb5ab37b64b6ddba54c47232 Mon Sep 17 00:00:00 2001 From: razinkele Date: Sun, 4 Jan 2026 21:23:30 +0200 Subject: [PATCH 2/4] ci: enable auto-merge for formatting-fix PRs created by CI --- .github/workflows/ci-auto-fix.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-auto-fix.yml b/.github/workflows/ci-auto-fix.yml index 88e7059..2b95ed8 100644 --- a/.github/workflows/ci-auto-fix.yml +++ b/.github/workflows/ci-auto-fix.yml @@ -48,7 +48,8 @@ jobs: git add -A git commit -m "style: apply ruff/black fixes from CI auto-fix" git push origin "$BRANCH_NAME" - gh pr create --title "style: apply ruff/black fixes (auto)" --body "Automated formatting fixes (ruff/black) applied by CI Auto-Fix workflow. This PR will be auto-merged when checks pass." --base main --head "$BRANCH_NAME" --label "chore" --web || true + # Create PR and enable auto-merge so formatting fixes are merged automatically when checks pass + gh pr create --title "style: apply ruff/black fixes (auto)" --body "Automated formatting fixes (ruff/black) applied by CI Auto-Fix workflow. This PR will be auto-merged when checks pass." --base main --head "$BRANCH_NAME" --auto || true - name: Run tests to check if fixes pass run: python -m pytest -q || true From 3f819ec71b0393e2516050ef0fdb9b3d35a5c8d5 Mon Sep 17 00:00:00 2001 From: razinkele Date: Sun, 4 Jan 2026 21:24:35 +0200 Subject: [PATCH 3/4] ci: add auto-fix label when creating formatting PRs --- .github/workflows/ci-auto-fix.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-auto-fix.yml b/.github/workflows/ci-auto-fix.yml index 2b95ed8..949c3a3 100644 --- a/.github/workflows/ci-auto-fix.yml +++ b/.github/workflows/ci-auto-fix.yml @@ -48,8 +48,9 @@ jobs: git add -A git commit -m "style: apply ruff/black fixes from CI auto-fix" git push origin "$BRANCH_NAME" - # Create PR and enable auto-merge so formatting fixes are merged automatically when checks pass - gh pr create --title "style: apply ruff/black fixes (auto)" --body "Automated formatting fixes (ruff/black) applied by CI Auto-Fix workflow. This PR will be auto-merged when checks pass." --base main --head "$BRANCH_NAME" --auto || true + # Ensure auto-fix label exists then create PR and enable auto-merge so formatting fixes are merged automatically when checks pass + gh label create "auto-fix" --color ffcc00 --description "Automated formatting fixes from CI" || true + gh pr create --title "style: apply ruff/black fixes (auto)" --body "Automated formatting fixes (ruff/black) applied by CI Auto-Fix workflow. This PR will be auto-merged when checks pass." --base main --head "$BRANCH_NAME" --label "auto-fix" --auto || true - name: Run tests to check if fixes pass run: python -m pytest -q || true From b910870a55bb45e156f9c9ea982a3f795ebd2df3 Mon Sep 17 00:00:00 2001 From: razinkele Date: Sun, 4 Jan 2026 21:25:48 +0200 Subject: [PATCH 4/4] ci: create non-draft diagnostic PRs and ensure 'ci-fail' label --- .github/workflows/ci-auto-fix.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-auto-fix.yml b/.github/workflows/ci-auto-fix.yml index 949c3a3..6315ac6 100644 --- a/.github/workflows/ci-auto-fix.yml +++ b/.github/workflows/ci-auto-fix.yml @@ -55,10 +55,10 @@ jobs: - name: Run tests to check if fixes pass run: python -m pytest -q || true - - name: Create draft PR on other failures + - name: Create PR on other failures (diagnostic) if: steps.git-check.outputs.changed == 'false' run: | - echo "Opening draft PR for CI failure diagnostics" + echo "Opening PR for CI failure diagnostics" BRANCH=auto/ci-fix/failure-${{ github.run_id }} git checkout -b "$BRANCH" # Add a short diagnostic file for human triage @@ -66,7 +66,9 @@ jobs: git add CI_FAILURE.md git commit -m "ci: record CI failure for diagnostics" git push origin "$BRANCH" - gh pr create --title "ci: investigate failing CI run #${{ github.event.workflow_run.id }}" --body "Draft PR created automatically to investigate CI failure (workflow_run id: ${{ github.event.workflow_run.id }}). Please see workflow run logs for details." --base main --head "$BRANCH" --draft --label "ci-fail" --web || true + # Ensure ci-fail label exists and create a non-draft PR for triage + gh label create "ci-fail" --color ee0000 --description "CI failure requires human triage" || true + gh pr create --title "ci: investigate failing CI run #${{ github.event.workflow_run.id }}" --body "PR created automatically to investigate CI failure (workflow_run id: ${{ github.event.workflow_run.id }}). Please see workflow run logs for details." --base main --head "$BRANCH" --label "ci-fail" --web || true - name: Comment on original run uses: actions/github-script@v7