Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/format-apply.yml
Original file line number Diff line number Diff line change
@@ -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

Check failure

Code scanning / CodeQL

Checkout of untrusted code in trusted context High

Potential execution of untrusted code on a privileged workflow (
workflow_run
)
Comment on lines +30 to +37
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"
30 changes: 24 additions & 6 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include <clang/AST/APValue.h>
#include <clang/AST/ParentMapContext.h>
#include <llvm/ADT/DenseMap.h>
#include <llvm/Support/ConvertUTF.h>

#include <format>
#include <regex>
#include <llvm/Support/ConvertUTF.h>

#include "compiler.h"
#include "converter/converter_lib.h"
Expand Down
Loading