Skip to content

Add cargo fmt and cargo clippy to CI workflows #2475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 12, 2025
17 changes: 15 additions & 2 deletions .github/workflows/ci-aptos-contract.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
on:
pull_request:
paths:
- .github/workflows/ci-aptos-contract.yml
- target_chains/aptos/contracts/**
push:
branches:
Expand All @@ -19,10 +20,22 @@ jobs:
- uses: actions/checkout@v3

- name: Download CLI
run: wget https://github.com/aptos-labs/aptos-core/releases/download/aptos-cli-v3.1.0/aptos-cli-3.1.0-Ubuntu-22.04-x86_64.zip
run: wget https://github.com/aptos-labs/aptos-core/releases/download/aptos-cli-v6.1.1/aptos-cli-6.1.1-Ubuntu-22.04-x86_64.zip
Copy link
Contributor

Choose a reason for hiding this comment

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

we had different versions in pre-commit and in this workflow.


- name: Unzip CLI
run: unzip aptos-cli-3.1.0-Ubuntu-22.04-x86_64.zip
run: unzip aptos-cli-6.1.1-Ubuntu-22.04-x86_64.zip

- name: Install movefmt
run: ./aptos update movefmt

- name: Check Formatting
run: ./aptos move fmt
if: success() || failure()
Copy link
Contributor

Choose a reason for hiding this comment

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

this if condition runs the job regardless of what happened before, so you get feedback on formatting / lint / tests no matter what.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we just remove the condition? Seems redundant...

Copy link
Contributor

Choose a reason for hiding this comment

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

(aside) for posterity: this condition is false when the workflow is cancelled


- name: Lint
run: ./aptos move lint --check-test-code --dev
if: success() || failure()

- name: Run tests
run: ./aptos move test
if: success() || failure()
9 changes: 9 additions & 0 deletions .github/workflows/ci-cosmwasm-contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Test CosmWasm Contract
on:
pull_request:
paths:
- .github/workflows/ci-cosmwasm-contract.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought I already added all of these paths, but I guess not

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think these need to be here, IIUC Github should automatically run workflows when their definition changes, but I could be wrong...

Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't :( . I only added these after the workflows failed to trigger on the first push of this PR

- target_chains/cosmwasm/**
- wormhole_attester/sdk/rust/**
push:
Expand All @@ -26,7 +27,15 @@ jobs:
toolchain: 1.82.0
components: rustfmt, clippy
override: true
- name: Format check
run: cargo fmt --all -- --check
if: success() || failure()
- name: Clippy check
run: cargo clippy --tests -- --deny warnings
if: success() || failure()
- name: Build
run: cargo build --verbose
if: success() || failure()
- name: Run tests
run: cargo test --verbose
if: success() || failure()
15 changes: 13 additions & 2 deletions .github/workflows/ci-fortuna.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ name: Check Fortuna
on:
pull_request:
paths:
- .github/workflows/ci-fortuna.yml
- apps/fortuna/**
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/fortuna
Copy link
Contributor

Choose a reason for hiding this comment

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

this working-directory field was missing on a few workflows... not sure how they worked before (perhaps they didnt?)

steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v2
Expand All @@ -19,5 +23,12 @@ jobs:
profile: minimal
toolchain: 1.82.0
override: true
- name: Run executor tests
run: cargo test --manifest-path ./apps/fortuna/Cargo.toml
- name: Format check
run: cargo fmt --all -- --check
if: success() || failure()
- name: Clippy check
run: cargo clippy --tests -- --deny warnings
if: success() || failure()
- name: Run tests
run: cargo test
if: success() || failure()
13 changes: 12 additions & 1 deletion .github/workflows/ci-hermes-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ name: Check Hermes Server
on:
pull_request:
paths:
- .github/workflows/ci-hermes-server.yml
- apps/hermes/server/**
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/hermes/server
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v2
Expand All @@ -24,5 +28,12 @@ jobs:
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Format check
run: cargo fmt --all -- --check
if: success() || failure()
- name: Clippy check
run: cargo clippy --tests -- --deny warnings
if: success() || failure()
- name: Run executor tests
run: cargo test --manifest-path ./apps/hermes/server/Cargo.toml
run: cargo test
if: success() || failure()
9 changes: 9 additions & 0 deletions .github/workflows/ci-lazer-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- main
pull_request:
paths:
- .github/workflows/ci-lazer-rust.yml
- lazer/**

jobs:
Expand Down Expand Up @@ -36,7 +37,15 @@ jobs:
echo "$HOME/.local/share/solana/install/active_release/bin" >> "$GITHUB_PATH"
- name: check Cargo.toml formatting
run: find . -name Cargo.toml -exec taplo fmt --check --diff {} \;
- name: Format check
run: cargo fmt --all -- --check
if: success() || failure()
- name: Clippy check
run: cargo clippy --all-targets -- --deny warnings
if: success() || failure()
- name: Build Solana programs
run: cargo build-sbf
if: success() || failure()
- name: test
run: cargo test
if: success() || failure()
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Message Buffer IDL Check
name: Message Buffer Check
on:
pull_request:
paths:
- .github/workflows/ci-message-buffer.yml
- pythnet/message_buffer/**
push:
branches:
- main
jobs:
abi-check:
name: Check Message Buffer IDL files are up to date
name: Check Message Buffer formatting & IDL files
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -33,10 +34,10 @@ jobs:
- name: Install Anchor
run: |
cargo install --git https://github.com/coral-xyz/anchor --tag v0.27.0 anchor-cli --locked
- name: Build and generate IDLs
run: anchor build
- name: Copy anchor target files
run: cp ./target/idl/message_buffer.json idl/ && cp ./target/types/message_buffer.ts idl/
- name: Install g++ 12
run: |
sudo apt-get install g++-12
echo "CXX=/usr/bin/g++-12" >> "${GITHUB_ENV}"
# Libusb is a build requirement for the node-hid package and so pnpm
# install will fail if this isn't in the build environment and if a
# precompiled binary isn't found.
Expand All @@ -46,10 +47,21 @@ jobs:
name: Install pnpm
- name: Install prettier globally
run: pnpm install -g prettier@2.7.1
- name: Build and generate IDLs
run: anchor build
- name: Copy anchor target files
run: cp ./target/idl/message_buffer.json idl/ && cp ./target/types/message_buffer.ts idl/
- name: Run prettier (to avoid pre-commit failures)
run: |
pnpm dlx prettier@2.7.1 --write "./idl/*"
- name: Check IDL changes
# Fails if the IDL files are not up to date. Please use anchor build to regenerate the IDL files for
# the current version of the contract and update idl directory.
run: git diff --exit-code idl/*
if: success() || failure()
- name: Cargo format
run: cargo fmt --all -- --check
if: success() || failure()
- name: Cargo clippy
run: cargo clippy --tests -- --deny warnings
if: success() || failure()
34 changes: 34 additions & 0 deletions .github/workflows/ci-pythnet-sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Check Pythnet SDK

on:
pull_request:
paths:
- .github/workflows/ci-pythnet-sdk.yml
- pythnet/pythnet_sdk/**
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: pythnet/pythnet_sdk
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v2
with:
workspaces: "pythnet/pythnet_sdk -> target"
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.82.0
override: true
- name: Format check
run: cargo fmt --all -- --check
if: success() || failure()
- name: Clippy check
run: cargo clippy --tests -- --deny warnings
if: success() || failure()
- name: Run executor tests
run: cargo test
if: success() || failure()
13 changes: 12 additions & 1 deletion .github/workflows/ci-remote-executor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ name: Check Remote Executor
on:
pull_request:
paths:
- .github/workflows/ci-remote-executor.yml
- governance/remote_executor/**
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: governance/remote_executor
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand All @@ -25,5 +29,12 @@ jobs:
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.18.23/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
- name: Format check
run: cargo fmt --all -- --check
if: success() || failure()
- name: Clippy check
run: cargo clippy --tests -- --deny warnings
if: success() || failure()
- name: Run executor tests
run: cargo test-sbf --manifest-path ./governance/remote_executor/Cargo.toml
run: cargo test-sbf
if: success() || failure()
10 changes: 10 additions & 0 deletions .github/workflows/ci-solana-contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Test Solana Contract
on:
pull_request:
paths:
- .github/workflows/ci-solana-contract.yml
- target_chains/solana/**
- pythnet/pythnet_sdk/**
push:
Expand Down Expand Up @@ -32,9 +33,18 @@ jobs:
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.16.20/install)"
echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
- name: Format check
run: cargo fmt --all -- --check
if: success() || failure()
- name: Clippy check
run: cargo clippy --tests -- --deny warnings
if: success() || failure()
- name: Build
run: cargo-build-sbf
if: success() || failure()
- name: Run tests
run: cargo-test-sbf
if: success() || failure()
- name: Run sdk tests
run: cargo test --package pyth-solana-receiver-sdk
if: success() || failure()
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module pyth::governance_action {
value: u8,
}

#[lint::skip(unnecessary_numerical_extreme_comparison)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think something changed with Aptos again and there's a new lint error because CONTRACT_UPGRADE=0. The comparison is intentional though, so we want to ignore.

public fun from_u8(value: u8): GovernanceAction {
assert!(CONTRACT_UPGRADE <= value && value <= SET_STALE_PRICE_THRESHOLD, error::invalid_governance_action());
GovernanceAction { value }
Expand Down
Loading