-D clippy (#252)

* -D clippy

* scripts

* fmt

* commented out

* diff clippy and build

* fix

* push -> main
This commit is contained in:
Aniket Prajapati 2023-12-08 03:26:41 +05:30 committed by GitHub
parent f16731ace8
commit a4fdc1554a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 204 additions and 16 deletions

View File

@ -2,6 +2,8 @@ name: Cargo Build & Test
on:
push:
branches:
- main
pull_request:
env:
@ -25,8 +27,6 @@ jobs:
# The toolchain action should definitely be run before the cache action
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# use toolchain version from rust-toolchain.toml
components: rustfmt, clippy
cache: true
# avoid the default "-D warnings" which thrashes cache
rustflags: ""
@ -47,10 +47,5 @@ jobs:
run: |
cargo build --locked --workspace --all-targets
- name: Run fmt+clippy
run: |
cargo fmt --all --check
cargo clippy --locked --workspace --all-targets
- name: Run Tests
run: RUST_LOG=info cargo test

52
.github/workflows/clippy_test.yml vendored Normal file
View File

@ -0,0 +1,52 @@
name: Cargo Nightly Clippy
on:
push:
branches:
- main
pull_request:
env:
CARGO_TERM_COLOR: always
SCCACHE_GHA_ENABLED: true
RUSTC_WRAPPER: sccache
SCCACHE_CACHE_SIZE: "1G"
jobs:
build_and_test:
name: lite-rpc full build
runs-on: ubuntu-22.04
steps:
- name: Install Linux Packages
run: |
sudo apt-get update -y
sudo apt-get install libssl-dev openssl -y
- uses: actions/checkout@v4
# The toolchain action should definitely be run before the cache action
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
# use toolchain version from rust-toolchain.toml
toolchain: nightly
components: rustfmt, clippy
cache: true
# avoid the default "-D warnings" which thrashes cache
rustflags: ""
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.3
# https://github.com/actions/cache/blob/main/examples.md#rust---cargo
# https://blog.arriven.wtf/posts/rust-ci-cache/
- uses: Swatinem/rust-cache@v2
with:
# will be covered by sscache
cache-targets: false
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Run fmt+clippy
run: |
cargo fmt --all --check
cargo clippy --locked --workspace --all-targets -- -D warnings

View File

@ -2,6 +2,8 @@ name: Integration Test with Validator
on:
push:
branches:
- main
pull_request:
env:

75
ci/cargo-command.sh Executable file
View File

@ -0,0 +1,75 @@
#!/bin/bash
# Function to display help message
show_help() {
echo "Usage: $0 [stable|nightly] [command]"
echo
echo "This script is used to run a specified cargo command with either the stable or nightly Rust toolchain."
echo
echo "Arguments:"
echo " stable - Use the stable Rust toolchain."
echo " nightly - Use the nightly Rust toolchain."
echo " command - The cargo command to run (e.g., clippy, build)."
echo
echo "Examples:"
echo " $0 stable clippy - Run clippy with the stable Rust version."
echo " $0 nightly build - Build with the nightly Rust version."
}
# Function to run a specified cargo command with a specified toolchain
run_cargo_command() {
local toolchain=$1
local command=$2
echo "Running cargo $command with Rust $toolchain version..."
cargo +"$toolchain" "$command"
}
# Check if the first argument is -h or --help
if [[ $1 == "-h" || $1 == "--help" ]]; then
show_help
exit 0
fi
# Check if the second argument is not provided
if [[ -z $2 ]]; then
echo "Error: No command specified."
show_help
exit 1
fi
# Path to the rust-version.sh script
rust_version_script="./ci/rust-version.sh"
# Check if rust-version.sh exists and is executable
if [[ -f "$rust_version_script" && -x "$rust_version_script" ]]; then
# Source the rust-version.sh script
source "$rust_version_script"
else
echo "Error: rust-version.sh not found or not executable."
exit 1
fi
# Main execution logic based on passed arguments
case $1 in
stable)
# Check if Rust stable version is set
if [[ -z $rust_stable ]]; then
echo "Error: Rust stable version is not set."
exit 1
fi
run_cargo_command "$rust_stable" "$2"
;;
nightly)
# Check if Rust nightly version is set
if [[ -z $rust_nightly ]]; then
echo "Error: Rust nightly version is not set."
exit 1
fi
run_cargo_command "$rust_nightly" "$2"
;;
*)
echo "Usage: $0 [stable|nightly] [command]"
exit 1
;;
esac

62
ci/rust-version.sh Executable file
View File

@ -0,0 +1,62 @@
readCargoVariable() {
declare variable="$1"
declare Cargo_toml="$2"
while read -r name equals value _; do
if [[ $name = "$variable" && $equals = = ]]; then
echo "${value//\"/}"
return
fi
done < <(cat "$Cargo_toml")
echo "Unable to locate $variable in $Cargo_toml" 1>&2
}
if [[ -n $RUST_STABLE_VERSION ]]; then
stable_version="$RUST_STABLE_VERSION"
else
# read rust version from rust-toolchain.toml file
base="$(dirname "${BASH_SOURCE[0]}")"
stable_version=$(readCargoVariable channel "$base/../rust-toolchain.toml")
fi
if [[ -n $RUST_NIGHTLY_VERSION ]]; then
nightly_version="$RUST_NIGHTLY_VERSION"
else
nightly_version=2023-11-16
fi
echo "stable_version: $stable_version"
echo "nightly_version: $nightly_version"
export rust_stable="$stable_version"
export rust_nightly=nightly-"$nightly_version"
[[ -z $1 ]] || (
rustup_install() {
declare toolchain=$1
if ! cargo +"$toolchain" -V > /dev/null; then
echo "$0: Missing toolchain? Installing...: $toolchain" >&2
rustup install "$toolchain"
cargo +"$toolchain" -V
fi
}
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
case $1 in
stable)
rustup_install "$rust_stable"
;;
nightly)
rustup_install "$rust_nightly"
;;
all)
rustup_install "$rust_stable"
rustup_install "$rust_nightly"
;;
*)
echo "$0: Note: ignoring unknown argument: $1" >&2
;;
esac
)

View File

@ -370,8 +370,8 @@ pub fn create_grpc_subscription(
let message = message?;
let Some(update) = message.update_oneof else {
continue;
};
continue;
};
match update {
UpdateOneof::Slot(slot) => {

View File

@ -60,9 +60,11 @@ impl EpochCache {
let res_epoch = rpc_client
.get_account(&solana_sdk::sysvar::epoch_schedule::id())
.await?;
let Some(SysvarAccountType::EpochSchedule(epoch_schedule)) = bincode::deserialize(&res_epoch.data[..])
.ok()
.map(SysvarAccountType::EpochSchedule) else {
let Some(SysvarAccountType::EpochSchedule(epoch_schedule)) =
bincode::deserialize(&res_epoch.data[..])
.ok()
.map(SysvarAccountType::EpochSchedule)
else {
bail!("Error during bootstrap epoch. SysvarAccountType::EpochSchedule can't be deserilized. Epoch can't be calculated.");
};

View File

@ -88,9 +88,9 @@ impl BlockStorageInterface for PostgresBlockStore {
Ok(())
}
async fn get(&self, slot: Slot, _config: RpcBlockConfig) -> Result<ProducedBlock> {
let range = self.get_slot_range().await;
if range.contains(&slot) {}
async fn get(&self, _slot: Slot, _config: RpcBlockConfig) -> Result<ProducedBlock> {
//let _range = self.get_slot_range().await;
//if range.contains(&slot) {}
todo!()
}

View File

@ -1,2 +1,2 @@
[toolchain]
channel = "1.70.0"
channel = "1.73.0"