Skip to content

Suggest changes instead of automatically fixing them #157

Suggest changes instead of automatically fixing them

Suggest changes instead of automatically fixing them #157

Workflow file for this run

name: Format Check
on:
push:
branches:
- master
pull_request:
branches: [ "**" ]
jobs:
format:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup LLVM
uses: ZhongRuoyu/setup-llvm@v0
with:
llvm-version: 22
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.95.0
components: rustfmt, clippy
- name: Setup nightly Rust for rule-preprocessor clippy
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rustfmt, clippy, rustc-dev
- name: Apply C++ formatting fixes
run: find cpp2rust tests -name '*.cpp' -o -name '*.h' -o -name '*.c' | xargs clang-format -i
- name: Apply Rust lint fixes
run: |
cargo clippy --fix --allow-dirty --manifest-path rules/Cargo.toml --all-targets
cargo +nightly clippy --fix --allow-dirty --manifest-path rule-preprocessor/Cargo.toml --all-targets
cargo clippy --fix --allow-dirty --manifest-path libcc2rs/Cargo.toml --all-targets
- name: Apply Rust formatting fixes
run: |
cargo fmt --manifest-path rules/Cargo.toml
cargo fmt --manifest-path rule-preprocessor/Cargo.toml
cargo fmt --manifest-path libcc2rs/Cargo.toml
find tests -name '*.rs' -print0 | xargs -0 rustfmt
- 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:
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
- name: Check Rust formatting
run: |
cargo fmt --manifest-path rules/Cargo.toml -- --check
cargo fmt --manifest-path rule-preprocessor/Cargo.toml -- --check
cargo fmt --manifest-path libcc2rs/Cargo.toml -- --check
find tests -name '*.rs' -print0 | xargs -0 rustfmt --check
- name: Check Rust lints
run: |
cargo clippy --manifest-path rules/Cargo.toml --all-targets --all-features -- -Dwarnings
cargo +nightly clippy --manifest-path rule-preprocessor/Cargo.toml --all-targets --all-features -- -Dwarnings
cargo clippy --manifest-path libcc2rs/Cargo.toml --all-targets --all-features -- -Dwarnings