Skip to content

CSHARP-6147: Add a dotnet format check - #2086

Merged
papafe merged 7 commits into
mongodb:mainfrom
papafe:csharp6147
Aug 3, 2026
Merged

CSHARP-6147: Add a dotnet format check#2086
papafe merged 7 commits into
mongodb:mainfrom
papafe:csharp6147

Conversation

@papafe

@papafe papafe commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

https://jira.mongodb.org/browse/CSHARP-6147

We also looked at running the check as a commit/push git hook, so problems would be caught before CI. Unfortunately dotnet format is quite slow on projects of this size, so it is not included here.

Copilot AI review requested due to automatic review settings July 30, 2026 10:39
@papafe
papafe requested a review from a team as a code owner July 30, 2026 10:39
@papafe
papafe requested a review from ajcvickers July 30, 2026 10:39
@papafe papafe added the maintenance Non-code maintenance (deps, docs, configs, etc.). label Jul 30, 2026
Comment thread .github/workflows/format.yml Outdated
with:
persist-credentials: false

- uses: actions/setup-dotnet@v4

@semgrep-code-mongodb semgrep-code-mongodb Bot Jul 30, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608.

🎈 Fixed in commit 86cbb94 🎈

Comment thread .github/workflows/format.yml Outdated
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4

@semgrep-code-mongodb semgrep-code-mongodb Bot Jul 30, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions step uses a mutable tag or branch reference. Tags and branch names can be silently repointed by the action owner, enabling supply-chain attacks — as seen in the trivy-action and kics-github-action compromises. Pin the reference to a full 40-character commit SHA instead, e.g. uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608.

🌟 Fixed in commit 86cbb94 🌟

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds automated formatting/code-style validation to the mongo-csharp-driver contributor workflow by introducing a dedicated dotnet format GitHub Actions check and an optional local pre-push hook, with contributor documentation updates to match.

Changes:

  • Add a new CI workflow that runs dotnet format ... --verify-no-changes on pull requests.
  • Add a repo-local .githooks/pre-push hook to run dotnet format only against pushed .cs files.
  • Document formatting expectations and hook enablement in CONTRIBUTING.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
CONTRIBUTING.md Documents how formatting/style are enforced and how to enable the repo git hooks.
.github/workflows/format.yml New PR workflow that verifies dotnet format has no pending changes.
.githooks/pre-push New pre-push hook that runs dotnet format on changed .cs files before pushing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .githooks/pre-push Outdated
…tation

dotnet format's indentation of an `else` followed by an `if` on the next line
changed between SDK 10.0.100 and 10.0.302, so the check disagreed with the
formatting already on main. Writing it as `else if` formats identically under
both. Pinning the SDK keeps the check from breaking on a runner image update.
@papafe
papafe marked this pull request as draft July 30, 2026 12:28
papafe added 3 commits July 30, 2026 14:33
dotnet format needs to compile each project once per target framework, so
checking even a single changed file costs 10-50s depending on the project. That
is too slow to sit on every push - it would just get bypassed with --no-verify.
CI stays the only automated checkpoint.
A tag can be repointed by its owner, which would run unreviewed code in the
workflow. Flagged by semgrep.
@papafe papafe changed the title CSHARP-6147: Add a dotnet format check to CI and a local pre-push hook CSHARP-6147: Add a dotnet format check Jul 30, 2026

@sanych-sun sanych-sun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The v3.x branch has not had the formatting applied, so the check would fail on
every pull request against it.
@papafe
papafe marked this pull request as ready for review July 31, 2026 12:21
@papafe
papafe merged commit 8b699a5 into mongodb:main Aug 3, 2026
22 of 29 checks passed
@papafe
papafe deleted the csharp6147 branch August 13, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Non-code maintenance (deps, docs, configs, etc.).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants