Skip to content

Commit

Permalink
refactor: Improve test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
khorolets committed Mar 8, 2024
1 parent 5366598 commit 6541ed7
Showing 1 changed file with 39 additions and 73 deletions.
112 changes: 39 additions & 73 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,85 +1,51 @@
name: ci
name: Rust checks

on:
pull_request:
branches: [main]
push:
branches: [main]
# schedule:
# - cron: '00 01 * * *'
jobs:
test:
name: test
env:
# For some builds, we use cross to test on 32-bit and big-endian
# systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS: ""
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
TARGET_DIR: ./target
# For some builds, we disable ledger support
FEATURES_FLAGS:
# Emit backtraces on panics.
RUST_BACKTRACE: 1
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- build: linux-x86_64
os: ubuntu-22.04
rust: stable
target: x86_64-unknown-linux-gnu

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
env:
CARGO_TERM_COLOR: always

- name: Use Cross
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Build cross environment
shell: bash
run: |
if [ -d "./cross/${{ matrix.target }}" ]; then
docker build --tag "cross:${{ matrix.target }}" "./cross/${{ matrix.target }}"
fi
jobs:
check-format-and-lint:
name: Check & Lint
runs-on: ubuntu-22.04-8core
steps:
- uses: actions/checkout@v2

- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
- name: Install Rust toolchain
run: |
rustup update stable
rustup default stable
rustup component add rustfmt clippy
- name: Build near-lake and all crates
run: ${{ env.CARGO }} build --verbose --all ${{ env.TARGET_FLAGS }} ${{ env.FEATURES_FLAGS }}
- name: Check code formatting
run: cargo fmt --all -- --check

- name: Run tests
run: ${{ env.CARGO }} test --verbose --all ${{ env.TARGET_FLAGS }} ${{ env.FEATURES_FLAGS }}
- name: Lint with clippy
run: cargo clippy -- -D warnings

rustfmt:
name: rustfmt
runs-on: ubuntu-22.04
cargo-check:
name: Cargo Check
runs-on: ubuntu-22.04-8core
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: rustfmt
- name: Check formatting
run: |
cargo fmt --all -- --check
- uses: actions/checkout@v2

- name: Install Rust toolchain
run: |
rustup update stable
rustup default stable
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Cargo Check
run: cargo check --all

0 comments on commit 6541ed7

Please sign in to comment.