Skip to content

Commit

Permalink
feat (ci): Add Rust formatting command (#1552)
Browse files Browse the repository at this point in the history
# Motivation
CI has no rust formatter.  As a result we have had PRs that contain changes that are just rust formatting.

# Changes
- Define rust and cargo formatting commands
- Format

# Tests

<!-- Please provide any information or screenshots about the tests that have been done -->
  • Loading branch information
bitdivine authored Jun 25, 2024
1 parent 01e6c5b commit a9f0e2d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,31 @@ jobs:
working-directory: .
run: ./scripts/test.backend.sh

format:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-backend-tests-${{ hashFiles('Cargo.lock', 'rust-toolchain.toml') }}
- name: Install cargo dependency sorter
run: cargo install [email protected]
- name: Format
run: ./scripts/format.sh
- name: Check formatted
run: |
test -z "$(git status --porcelain)" || {
echo "FIX: Please run ./scripts/format.sh"
git diff
exit 1
}
may-merge:
needs: [ 'tests' ]
needs: [ 'tests', 'format' ]
runs-on: ubuntu-20.04
steps:
- name: Cleared for merging
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ candid = "0.10.0"
ic-cdk = "0.12.0"
ic-cdk-macros = "0.8.1"
serde = "1"
serde_bytes = "0.11"
serde_bytes = "0.11"
3 changes: 3 additions & 0 deletions scripts/format.cargo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

cargo sort --grouped --workspace
3 changes: 3 additions & 0 deletions scripts/format.rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

cargo fmt
9 changes: 9 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euxo pipefail
cd "$(dirname "$(realpath "$0")")/.."

set -x
time xargs -P8 -I{} bash -c "{}" <<EOF
./scripts/format.cargo.sh
./scripts/format.rust.sh
EOF
16 changes: 8 additions & 8 deletions src/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
ic-cdk.workspace = true
ic-cdk-macros.workspace = true
candid.workspace = true
serde.workspace = true
serde_bytes.workspace = true
ic-stable-structures = "0.6.4"
candid = { workspace = true }
ethers-core = "= 2.0.11"
futures = "0.3"
k256 = "0.13"
hex = "0.4"
getrandom = { version = "0.2", features = ["custom"] }
hex = "0.4"
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-stable-structures = "0.6.4"
k256 = "0.13"
serde = { workspace = true }
serde_bytes = { workspace = true }
shared = { path = "../shared" }

[dev-dependencies]
Expand Down
10 changes: 5 additions & 5 deletions src/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.0.2"
edition = "2021"

[dependencies]
ic-cdk.workspace = true
ic-cdk-macros.workspace = true
candid.workspace = true
serde.workspace = true
serde_bytes.workspace = true
candid = { workspace = true }
ic-cdk = { workspace = true }
ic-cdk-macros = { workspace = true }
ic-metrics-encoder = "1.1.1"
serde = { workspace = true }
serde_bytes = { workspace = true }

0 comments on commit a9f0e2d

Please sign in to comment.