Selaa lähdekoodia

Add cargo fmt and cargo clippy to CI workflows (#2475)

* Add cargo fmt and cargo clippy to CI workflows

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

* refactor: remove toolchain version arguments from cargo commands

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

* update worfklows

* trigger workflows on edit

* fix workflows

* fix aptos

* hm

* hm

* ci: remove workflow file paths from PR triggers and redundant if conditions

Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz>

* Revert "ci: remove workflow file paths from PR triggers and redundant if conditions"

This reverts commit 37b0de90191d1130ef92eee639d34e86be8d1553.

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Jayant Krishnamurthy <jayant@dourolabs.xyz>
Co-authored-by: Jayant Krishnamurthy <jayantkrishnamurthy@gmail.com>
devin-ai-integration[bot] 8 kuukautta sitten
vanhempi
sitoutus
2699171dc1

+ 15 - 2
.github/workflows/ci-aptos-contract.yml

@@ -1,6 +1,7 @@
 on:
   pull_request:
     paths:
+      - .github/workflows/ci-aptos-contract.yml
       - target_chains/aptos/contracts/**
   push:
     branches:
@@ -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
 
       - 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()
+
+      - name: Lint
+        run: ./aptos move lint --check-test-code --dev
+        if: success() || failure()
 
       - name: Run tests
         run: ./aptos move test
+        if: success() || failure()

+ 9 - 0
.github/workflows/ci-cosmwasm-contract.yml

@@ -3,6 +3,7 @@ name: Test CosmWasm Contract
 on:
   pull_request:
     paths:
+      - .github/workflows/ci-cosmwasm-contract.yml
       - target_chains/cosmwasm/**
       - wormhole_attester/sdk/rust/**
   push:
@@ -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()

+ 13 - 2
.github/workflows/ci-fortuna.yml

@@ -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
     steps:
       - uses: actions/checkout@v2
       - uses: Swatinem/rust-cache@v2
@@ -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()

+ 12 - 1
.github/workflows/ci-hermes-server.yml

@@ -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
@@ -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 - 0
.github/workflows/ci-lazer-rust.yml

@@ -5,6 +5,7 @@ on:
       - main
   pull_request:
     paths:
+      - .github/workflows/ci-lazer-rust.yml
       - lazer/**
 
 jobs:
@@ -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()

+ 18 - 6
.github/workflows/ci-message-buffer-idl.yml → .github/workflows/ci-message-buffer.yml

@@ -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:
@@ -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.
@@ -46,6 +47,10 @@ 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/*"
@@ -53,3 +58,10 @@ jobs:
         # 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 - 0
.github/workflows/ci-pythnet-sdk.yml

@@ -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()

+ 12 - 1
.github/workflows/ci-remote-executor.yml

@@ -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
@@ -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 - 0
.github/workflows/ci-solana-contract.yml

@@ -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:
@@ -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()

+ 1 - 0
target_chains/aptos/contracts/sources/governance/governance_action.move

@@ -11,6 +11,7 @@ module pyth::governance_action {
         value: u8,
     }
 
+    #[lint::skip(unnecessary_numerical_extreme_comparison)]
     public fun from_u8(value: u8): GovernanceAction {
         assert!(CONTRACT_UPGRADE <= value && value <= SET_STALE_PRICE_THRESHOLD, error::invalid_governance_action());
         GovernanceAction { value }