Skip to content

Commit f20ea2e

Browse files
authored
ci: add auto-commit of rustfmt changes action to CI APMSP-2770 (#1548)
# What does this PR do? Introduces a new GH workflow that uses [rustfmt-check](https://github.com/mbrobbel/rustfmt-check) and can automatically apply `rustfmt` changes via a commit on your PR. This is currently opt-in via the `commit-rustfmt-changes` label. The existing validation workflow still exists and is required to pass. # Motivation What inspired you to submit this pull request? # Additional Notes Anything else we should know when reviewing? # How to test the change? Describe here in detail how the change can be validated. Co-authored-by: edmund.kump <edmund.kump@datadoghq.com>
1 parent 9b42048 commit f20ea2e

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

.github/workflows/all-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ jobs:
1616
delay: '3'
1717
retries: '45'
1818
polling_interval: '1'
19-
checks_exclude: 'devflow/merge,dd-gitlab/default-pipeline'
19+
checks_exclude: 'devflow/merge,dd-gitlab/default-pipeline,Rustfmt Auto / rustfmt'

.github/workflows/rustfmt-auto.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Rustfmt Auto
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened, labeled]
5+
6+
jobs:
7+
rustfmt:
8+
runs-on: ubuntu-latest
9+
if: >-
10+
contains(github.event.pull_request.labels.*.name, 'commit-rustfmt-changes') &&
11+
!startsWith(github.head_ref, 'mq-working-branch')
12+
permissions:
13+
id-token: write
14+
contents: write
15+
steps:
16+
- name: Checkout sources
17+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
18+
with:
19+
ref: ${{ github.head_ref }}
20+
- name: Get GitHub App token
21+
uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
22+
id: octo-sts
23+
with:
24+
scope: DataDog/libdatadog
25+
policy: self.write.rustfmt
26+
- name: Install nightly-2026-02-08 toolchain and rustfmt
27+
run: rustup install nightly-2026-02-08 && rustup default nightly-2026-02-08 && rustup component add rustfmt
28+
- name: Run rustfmt and commit changes
29+
uses: mbrobbel/rustfmt-check@e7ac5685995bd39fb14f6c83fa6f10627e92e680 # master
30+
with:
31+
token: ${{ steps.octo-sts.outputs.token }}

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ We also recommend that you share in your description:
7878
If at any point you have a question or need assistance with your pull request, feel free to mention a project member!
7979
We're always happy to help contributors with their pull requests.
8080

81+
## Code Formatting
82+
83+
All Rust code must be formatted with `rustfmt` using the project's configuration in `rustfmt.toml`. You can format your
84+
code locally by running:
85+
86+
```bash
87+
cargo +nightly fmt --all
88+
```
89+
90+
If you'd like CI to automatically format your code and commit the changes to your PR, add the `commit-rustfmt-changes`
91+
label to your pull request. This will trigger an automatic formatting commit if any changes are needed.
92+
8193
## Commit Message Guidelines
8294

8395
This project uses [Conventional Commits](https://www.conventionalcommits.org/) for commit messages and pull request titles.

0 commit comments

Comments
 (0)