mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
The prior version would fail if the last entry in the final array was not originally the last entry.
212 lines
8.4 KiB
YAML
212 lines
8.4 KiB
YAML
name: Lint
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- develop
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
clippy:
|
|
strategy:
|
|
matrix:
|
|
os: [ubuntu-latest, macos-13, macos-14, windows-latest]
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
|
|
|
- name: Get nightly version to use
|
|
id: nightly
|
|
shell: bash
|
|
run: echo "version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build Dependencies
|
|
uses: ./.github/actions/build-dependencies
|
|
|
|
- name: Install nightly rust
|
|
run: rustup toolchain install ${{ steps.nightly.outputs.version }} --profile minimal -t wasm32v1-none -c rust-src -c clippy
|
|
|
|
- name: Run Clippy
|
|
run: cargo +${{ steps.nightly.outputs.version }} clippy --all-features --all-targets -- -D warnings -A clippy::items_after_test_module
|
|
|
|
# Also verify the lockfile isn't dirty
|
|
# This happens when someone edits a Cargo.toml yet doesn't do anything
|
|
# which causes the lockfile to be updated
|
|
# The above clippy run will cause it to be updated, so checking there's
|
|
# no differences present now performs the desired check
|
|
- name: Verify lockfile
|
|
shell: bash
|
|
run: git diff | wc -l | LC_ALL="en_US.utf8" grep -x -e "^[ ]*0"
|
|
|
|
deny:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
|
|
|
- name: Advisory Cache
|
|
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809
|
|
with:
|
|
path: ~/.cargo/advisory-db
|
|
key: rust-advisory-db
|
|
|
|
- name: Install cargo deny
|
|
run: cargo +1.89 install cargo-deny --version =0.18.3
|
|
|
|
- name: Run cargo deny
|
|
run: cargo deny -L error --all-features check --hide-inclusion-graph
|
|
|
|
fmt:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
|
|
|
- name: Get nightly version to use
|
|
id: nightly
|
|
shell: bash
|
|
run: echo "version=$(cat .github/nightly-version)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Install nightly rust
|
|
run: rustup toolchain install ${{ steps.nightly.outputs.version }} --profile minimal -c rustfmt
|
|
|
|
- name: Run rustfmt
|
|
run: cargo +${{ steps.nightly.outputs.version }} fmt -- --check
|
|
|
|
- name: Install foundry
|
|
uses: foundry-rs/foundry-toolchain@8f1998e9878d786675189ef566a2e4bf24869773
|
|
with:
|
|
version: nightly-41d4e5437107f6f42c7711123890147bc736a609
|
|
cache: false
|
|
|
|
- name: Run forge fmt
|
|
run: FOUNDRY_FMT_SORT_INPUTS=false FOUNDRY_FMT_LINE_LENGTH=100 FOUNDRY_FMT_TAB_WIDTH=2 FOUNDRY_FMT_BRACKET_SPACING=true FOUNDRY_FMT_INT_TYPES=preserve forge fmt --check $(find . -iname "*.sol")
|
|
|
|
machete:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
|
- name: Verify all dependencies are in use
|
|
run: |
|
|
cargo +1.89 install cargo-machete --version =0.8.0
|
|
cargo +1.89 machete
|
|
|
|
msrv:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
|
- name: Verify claimed `rust-version`
|
|
shell: bash
|
|
run: |
|
|
cargo +1.89 install cargo-msrv --version =0.18.4
|
|
|
|
function check_msrv {
|
|
# We `cd` into the directory passed as the first argument, but will return to the
|
|
# directory called from.
|
|
return_to=$(pwd)
|
|
echo "Checking $1"
|
|
cd $1
|
|
|
|
# We then find the existing `rust-version` using `grep` (for the right line) and then a
|
|
# regex (to strip to just the major and minor version).
|
|
existing=$(cat ./Cargo.toml | grep "rust-version" | grep -Eo "[0-9]+\.[0-9]+")
|
|
|
|
# We then backup the `Cargo.toml`, allowing us to restore it after, saving time on future
|
|
# MSRV checks (as they'll benefit from immediately exiting if the queried version is less
|
|
# than the declared MSRV).
|
|
mv ./Cargo.toml ./Cargo.toml.bak
|
|
|
|
# We then use an inverted (`-v`) grep to remove the existing `rust-version` from the
|
|
# `Cargo.toml`, as required because else earlier versions of Rust won't even attempt to
|
|
# compile this crate.
|
|
cat ./Cargo.toml.bak | grep -v "rust-version" > Cargo.toml
|
|
|
|
# We then find the actual `rust-version` using `cargo-msrv` (again stripping to just the
|
|
# major and minor version).
|
|
actual=$(cargo msrv find --output-format minimal | grep -Eo "^[0-9]+\.[0-9]+")
|
|
|
|
# Finally, we compare the two.
|
|
echo "Declared rust-version: $existing"
|
|
echo "Actual rust-version: $actual"
|
|
[ $existing == $actual ]
|
|
result=$?
|
|
|
|
# Restore the original `Cargo.toml`.
|
|
rm Cargo.toml
|
|
mv ./Cargo.toml.bak ./Cargo.toml
|
|
|
|
# Return to the directory called from and return the result.
|
|
cd $return_to
|
|
return $result
|
|
}
|
|
|
|
# Check each member of the workspace
|
|
function check_workspace {
|
|
# Get the members array from the workspace's `Cargo.toml`
|
|
cargo_toml_lines=$(cat ./Cargo.toml | wc -l)
|
|
# Keep all lines after the start of the array, then keep all lines before the next "]"
|
|
members=$(cat Cargo.toml | grep "members\ \=\ \[" -m1 -A$cargo_toml_lines | grep "]" -m1 -B$cargo_toml_lines)
|
|
# Prune `members = [` to `[` by replacing the first line with just `[`
|
|
members=$(echo "$members" | sed "1s/.*/\[/")
|
|
|
|
# Parse out any comments, whitespace, including comments post-fixed on the same line as an entry
|
|
# We accomplish the latter by pruning all characters after the entry's ","
|
|
members=$(echo "$members" | grep -Ev "^[[:space:]]*(#|$)" | awk -F',' '{print $1","}')
|
|
# Correct the last line, which was malleated to "],"
|
|
members=$(echo "$members" | sed "$(echo "$members" | wc -l)s/\]\,/\]/")
|
|
|
|
# Don't check the patches
|
|
members=$(echo "$members" | grep -v "patches")
|
|
# Don't check the following
|
|
# Most of these are binaries, with the exception of the Substrate runtime which has a
|
|
# bespoke build pipeline
|
|
members=$(echo "$members" | grep -v "networks/ethereum/relayer\"")
|
|
members=$(echo "$members" | grep -v "message-queue\"")
|
|
members=$(echo "$members" | grep -v "processor/bin\"")
|
|
members=$(echo "$members" | grep -v "processor/bitcoin\"")
|
|
members=$(echo "$members" | grep -v "processor/ethereum\"")
|
|
members=$(echo "$members" | grep -v "processor/monero\"")
|
|
members=$(echo "$members" | grep -v "coordinator\"")
|
|
members=$(echo "$members" | grep -v "substrate/runtime\"")
|
|
members=$(echo "$members" | grep -v "substrate/node\"")
|
|
members=$(echo "$members" | grep -v "orchestration\"")
|
|
|
|
# Don't check the tests
|
|
members=$(echo "$members" | grep -v "mini\"")
|
|
members=$(echo "$members" | grep -v "tests/")
|
|
|
|
# Remove the trailing comma by replacing the last line's "," with ""
|
|
members=$(echo "$members" | sed "$(($(echo "$members" | wc -l) - 1))s/\,//")
|
|
|
|
echo $members | jq -r ".[]" | while read -r member; do
|
|
check_msrv $member
|
|
correct=$?
|
|
if [ $correct -ne 0 ]; then
|
|
return $correct
|
|
fi
|
|
done
|
|
}
|
|
check_workspace
|
|
|
|
slither:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
|
|
- name: Slither
|
|
run: |
|
|
python3 -m pip install solc-select
|
|
solc-select install 0.8.26
|
|
solc-select use 0.8.26
|
|
|
|
python3 -m pip install slither-analyzer
|
|
|
|
slither --include-paths ./networks/ethereum/schnorr/contracts/Schnorr.sol
|
|
slither --include-paths ./networks/ethereum/schnorr/contracts ./networks/ethereum/schnorr/contracts/tests/Schnorr.sol
|
|
slither processor/ethereum/deployer/contracts/Deployer.sol
|
|
slither processor/ethereum/erc20/contracts/IERC20.sol
|
|
|
|
cp networks/ethereum/schnorr/contracts/Schnorr.sol processor/ethereum/router/contracts/
|
|
cp processor/ethereum/erc20/contracts/IERC20.sol processor/ethereum/router/contracts/
|
|
cd processor/ethereum/router/contracts
|
|
slither Router.sol
|