ci: hold the Rust files a pull request adds to rustfmt.toml #474

Open
github-bot wants to merge 1 commit from github-bot/gh-474 into a-publier AGit
Owner

@⁠booomxd on GitHub · 2026-11-27 04:56 UTC · original
booomxd:fmt-new-files → a-publier · +34 −3 · 1 files · 1 commits · open

Why

cargo fmt --check fails on most of the tree: 146 of the 237 Rust files, and #142 noticed it on main too. Formatting everything at once would conflict with nearly every one of the 236 open pull requests. This change stops the problem from growing without touching existing code.

What

  • A new fmt-new-files job runs on pull requests only, on ubuntu-latest with the toolchain pinned in rust-toolchain.toml. It runs rustfmt --edition 2024 --check on the .rs files the PR adds, compared with the merge base of its target branch. It doesn't check files the PR edits.
  • The check gate now also requires this job. On pushes the job is skipped, because there's no base to compare with, and the gate counts a skipped job as passed.

Known limit

rustfmt follows mod x; declarations from the files it's given. A new file that declares out-of-line modules would therefore also have those existing child files checked. That's rare, and the fix is to run rustfmt on them.

Testing

I ran the job's script locally against a branch that adds two formatted files, and it passed. I added a deliberately badly formatted file, and it failed, showing the diff. The YAML parses. On a fork, the job and the rest of CI passed: https://github.com/booomxd/VIctory-Belobug-AMD/pull/2

**@⁠booomxd** on GitHub · 2026-11-27 04:56 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/474) `booomxd:fmt-new-files` → `a-publier` · +34 −3 · 1 files · 1 commits · open ## Why `cargo fmt --check` fails on most of the tree: 146 of the 237 Rust files, and #142 noticed it on `main` too. Formatting everything at once would conflict with nearly every one of the 236 open pull requests. This change stops the problem from growing without touching existing code. ## What - A new `fmt-new-files` job runs on pull requests only, on `ubuntu-latest` with the toolchain pinned in `rust-toolchain.toml`. It runs `rustfmt --edition 2024 --check` on the `.rs` files the PR **adds**, compared with the merge base of its target branch. It doesn't check files the PR edits. - The `check` gate now also requires this job. On pushes the job is skipped, because there's no base to compare with, and the gate counts a skipped job as passed. ## Known limit rustfmt follows `mod x;` declarations from the files it's given. A new file that declares out-of-line modules would therefore also have those existing child files checked. That's rare, and the fix is to run `rustfmt` on them. ## Testing I ran the job's script locally against a branch that adds two formatted files, and it passed. I added a deliberately badly formatted file, and it failed, showing the diff. The YAML parses. On a fork, the job and the rest of CI passed: https://github.com/booomxd/VIctory-Belobug-AMD/pull/2
`cargo fmt --check` fails on most of the tree (146 of 237 Rust files),
and formatting it all at once would conflict with nearly every open
pull request. So the new job checks only the .rs files a pull request
adds, against the merge base with its target branch; edited files are
left alone. It runs on Ubuntu with the pinned toolchain in a minute or
so, and the `check` gate counts it as passed when it is skipped (on
pushes, where there is no base to compare with).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 04:58:46 +00:00
Author
Owner

@⁠AccelArch on GitHub · 2026-11-27 12:02 UTC · original

Read 9e49887 against a-publier (4eb6cfd). I could not run the workflow or rustfmt (no Rust toolchain here), so this covers the two parts I could reproduce.

The git step, run in bash (Git for Windows) in a temp repo whose PR branch adds three .rs files, edits one and renames one: git diff --name-only --diff-filter=A "$base" HEAD -- '*.rs' lists only the added files, a path with a space survives mapfile, the edited file and the renamed one (R100) are not listed, and a PR with no new .rs prints "This pull request adds no Rust files." and exits 0. One edge: for a new file with a non-ASCII name, git's default core.quotepath prints "src/\303\251.rs" (quoted and escaped), and that string is then passed to rustfmt as a path that does not exist. git -c core.quotepath=false diff ..., or -z with mapfile -d '', avoids it. There are no non-ASCII .rs paths in a-publier today, so this only concerns future files.

The check condition, copied into Windows PowerShell 5.1 with sample results: all three existing jobs successful with fmt-new-files success or skipped passes; fmt-new-files failure or cancelled fails; a clippy failure with fmt-new-files skipped fails. The existing check job has if: always(), so a skipped fmt-new-files (pushes) does not skip the gate.

--edition 2024 matches edition = "2024" in Cargo.toml, and the toolchain is the one pinned in rust-toolchain.toml.

AI-assisted.

**@⁠AccelArch** on GitHub · 2026-11-27 12:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/474#issuecomment-7217776176) Read 9e49887 against a-publier (4eb6cfd). I could not run the workflow or rustfmt (no Rust toolchain here), so this covers the two parts I could reproduce. The git step, run in bash (Git for Windows) in a temp repo whose PR branch adds three .rs files, edits one and renames one: `git diff --name-only --diff-filter=A "$base" HEAD -- '*.rs'` lists only the added files, a path with a space survives `mapfile`, the edited file and the renamed one (R100) are not listed, and a PR with no new .rs prints "This pull request adds no Rust files." and exits 0. One edge: for a new file with a non-ASCII name, git's default core.quotepath prints `"src/\303\251.rs"` (quoted and escaped), and that string is then passed to rustfmt as a path that does not exist. `git -c core.quotepath=false diff ...`, or `-z` with `mapfile -d ''`, avoids it. There are no non-ASCII .rs paths in a-publier today, so this only concerns future files. The `check` condition, copied into Windows PowerShell 5.1 with sample results: all three existing jobs successful with fmt-new-files success or skipped passes; fmt-new-files failure or cancelled fails; a clippy failure with fmt-new-files skipped fails. The existing `check` job has `if: always()`, so a skipped fmt-new-files (pushes) does not skip the gate. `--edition 2024` matches `edition = "2024"` in Cargo.toml, and the toolchain is the one pinned in rust-toolchain.toml. AI-assisted.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/474/head:github-bot/gh-474'
git switch 'github-bot/gh-474'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-474'
git switch 'github-bot/gh-474'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-474'
git switch 'github-bot/gh-474'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-474'
git switch 'a-publier'
git merge --squash 'github-bot/gh-474'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-474'
git switch 'a-publier'
git merge 'github-bot/gh-474'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.