Skip to content

Commit d987ea8

Browse files
committed
feat: add auto-formatting step with rustfmt to CI/CD pipeline
1 parent 1e3bea0 commit d987ea8

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

.github/workflows/rust.yml

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,44 @@ env:
1111
RUST_BACKTRACE: 1
1212

1313
jobs:
14+
format:
15+
name: Auto-format Code
16+
runs-on: ubuntu-latest
17+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Setup Rust
26+
uses: dtolnay/rust-toolchain@stable
27+
with:
28+
components: rustfmt
29+
30+
- name: Run cargo fmt
31+
run: cargo fmt --all
32+
33+
- name: Check for changes
34+
id: git-check
35+
run: |
36+
git diff --exit-code || echo "has_changes=true" >> $GITHUB_OUTPUT
37+
38+
- name: Commit and push if changed
39+
if: steps.git-check.outputs.has_changes == 'true'
40+
run: |
41+
git config user.name "github-actions[bot]"
42+
git config user.email "github-actions[bot]@users.noreply.github.com"
43+
git add -A
44+
git commit -m "style: auto-format code with rustfmt [skip ci]"
45+
git push
46+
1447
test:
1548
name: Test
1649
runs-on: ubuntu-latest
50+
needs: format
51+
if: always()
1752

1853
services:
1954
postgres:
@@ -68,9 +103,6 @@ jobs:
68103
run: |
69104
psql -h localhost -U postgres -d e2ee -f sql_models/seed.sql
70105
71-
- name: Check formatting
72-
run: cargo fmt --all -- --check
73-
74106
- name: Clippy
75107
run: cargo clippy --all-targets --all-features -- -D warnings
76108

0 commit comments

Comments
 (0)