datahaven/.github/workflows/task-rust-lint.yml

93 lines
2.7 KiB
YAML

# Lint and Format: CI for Rust components (DataHaven runtime and node Rust tests)
#
# Overview:
# 1. Check Rust Format: Check that the Rust code is formatted correctly
# 2. Check Rust Lint: Check that the Rust code is linted correctly
name: Lint and Format
on:
workflow_call:
workflow_dispatch:
inputs:
pull_request:
description: set to pull_request number to execute on external pr
required: false
env:
CARGO_TERM_COLOR: always
WORKING_DIR: operator
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"
jobs:
cargo-fmt:
name: "Check format with rustfmt"
runs-on:
group: DH-runners
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/actions/setup-env
with:
cache-key: FMT
install-deps: false # Self-hosted runners have deps pre-installed
- name: Run cargo fmt
run: cargo fmt --all -- --check
check-rust-lint:
name: "Check lint with clippy"
runs-on:
group: DH-runners
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/actions/setup-env
with:
cache-key: LINT
install-deps: false # Self-hosted runners have deps pre-installed
- name: Set build flags
run: echo "RUSTFLAGS=${{ env.RUSTFLAGS }} -C linker=clang -C link-arg=-fuse-ld=mold" >> $GITHUB_ENV
- name: Run cargo clippy
run: SKIP_WASM_BUILD=1 cargo clippy --features try-runtime,runtime-benchmarks --locked --release
check-cargo-sort:
name: "Check Cargo sort"
runs-on:
group: DH-runners
defaults:
run:
working-directory: ${{ env.WORKING_DIR }}
steps:
- name: Check out the repository to the runner
uses: actions/checkout@v4
- name: Install taplo locally
run: |
# Install taplo in user space without sudo
TAPLO_VERSION="0.8.1"
if ! command -v taplo &> /dev/null || [[ $(taplo --version | grep -oP '\d+\.\d+\.\d+' | head -1) != "$TAPLO_VERSION" ]]; then
echo "Installing taplo $TAPLO_VERSION in ~/.local/bin"
mkdir -p ~/.local/bin
curl -Ls "https://github.com/tamasfe/taplo/releases/download/${TAPLO_VERSION}/taplo-full-linux-x86_64.gz" | \
gzip -d > ~/.local/bin/taplo
chmod +x ~/.local/bin/taplo
echo "$HOME/.local/bin" >> $GITHUB_PATH
export PATH="$HOME/.local/bin:$PATH"
else
echo "taplo is already installed: $(taplo --version)"
fi
- run: taplo fmt --check
- run: taplo lint