diff --git a/.github/workflows/format-apply.yml b/.github/workflows/format-apply.yml new file mode 100644 index 00000000..5b7ceb71 --- /dev/null +++ b/.github/workflows/format-apply.yml @@ -0,0 +1,43 @@ +name: Format Apply + +on: + workflow_run: + workflows: ["Format Check"] + types: [completed] + +jobs: + apply: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' + permissions: + contents: write + + steps: + - name: Download diff artifact + uses: actions/download-artifact@v4 + with: + name: format-diff + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + path: ${{ runner.temp }}/format-diff + + - name: Read PR head + id: head + run: | + echo "repo=$(cat ${{ runner.temp }}/format-diff/head-repo.txt)" >> "$GITHUB_OUTPUT" + echo "branch=$(cat ${{ runner.temp }}/format-diff/head-branch.txt)" >> "$GITHUB_OUTPUT" + + - name: Checkout PR head + uses: actions/checkout@v6 + with: + repository: ${{ steps.head.outputs.repo }} + ref: ${{ steps.head.outputs.branch }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Apply diff + run: git apply ${{ runner.temp }}/format-diff/format.diff + + - name: Commit and push + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Automatically apply formatting and lint fixes" diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 85a91e23..81a790c5 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -11,13 +11,13 @@ jobs: format: runs-on: ubuntu-latest permissions: - contents: write + contents: read steps: - name: Checkout code uses: actions/checkout@v6 - - name: Setup LLVM 22 + - name: Setup LLVM uses: ZhongRuoyu/setup-llvm@v0 with: llvm-version: 22 @@ -50,11 +50,29 @@ jobs: cargo fmt --manifest-path libcc2rs/Cargo.toml find tests -name '*.rs' -print0 | xargs -0 rustfmt - - name: Commit auto-fixes - if: github.ref != 'refs/heads/master' - uses: stefanzweifel/git-auto-commit-action@v5 + - name: Capture diff for later auto-commit + id: diff + if: github.event_name == 'pull_request' + run: | + git diff > /tmp/format.diff + echo "${{ github.event.pull_request.head.repo.full_name }}" > /tmp/head-repo.txt + echo "${{ github.event.pull_request.head.ref }}" > /tmp/head-branch.txt + if [ -s /tmp/format.diff ]; then + echo "has_diff=true" >> "$GITHUB_OUTPUT" + else + echo "has_diff=false" >> "$GITHUB_OUTPUT" + fi + + - name: Upload diff artifact + if: github.event_name == 'pull_request' && steps.diff.outputs.has_diff == 'true' + uses: actions/upload-artifact@v4 with: - commit_message: "Automatically apply formatting and lint fixes" + name: format-diff + path: | + /tmp/format.diff + /tmp/head-repo.txt + /tmp/head-branch.txt + retention-days: 1 - name: Check C++ formatting run: find cpp2rust tests -name '*.cpp' -o -name '*.h' -o -name '*.c' | xargs clang-format --dry-run --Werror diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 359210aa..18062284 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -6,10 +6,10 @@ #include #include #include -#include #include #include +#include #include "compiler.h" #include "converter/converter_lib.h"