shared-actions/rust-build/action.yml

101 lines
2.4 KiB
YAML

name: rust-build
description: Run Rust CI — fmt, clippy, tests, optional cross-compilation.
inputs:
toolchain:
required: false
default: "stable"
features:
required: false
default: ""
cross-target:
required: false
default: ""
run-fmt:
required: false
default: "true"
run-clippy:
required: false
default: "true"
run-tests:
required: false
default: "true"
run-deny:
required: false
default: "false"
run-semver-checks:
required: false
default: "false"
sccache-enabled:
required: false
default: "true"
working-directory:
required: false
default: "."
runs:
using: composite
steps:
- name: Restore cargo cache
uses: https://data.forgejo.org/actions/cache/restore@v4
with:
path: |
~/.cargo/registry
target/
key: cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Rust CI
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
set -euo pipefail
rustup default ${{ inputs.toolchain }}
if [[ "${{ inputs.sccache-enabled }}" == "true" && -f sccache_ci_setup.sh ]]; then
source sccache_ci_setup.sh
fi
CMD=cargo
if [[ -n "${{ inputs.cross-target }}" ]]; then
cargo install cross
CMD=cross
fi
FEATURES_ARG=""
if [[ -n "${{ inputs.features }}" ]]; then
FEATURES_ARG="--features ${{ inputs.features }}"
fi
TARGET_ARG=""
if [[ -n "${{ inputs.cross-target }}" ]]; then
TARGET_ARG="--target ${{ inputs.cross-target }}"
fi
if [[ "${{ inputs.run-fmt }}" == "true" ]]; then
cargo fmt --check
fi
if [[ "${{ inputs.run-clippy }}" == "true" ]]; then
$CMD clippy $FEATURES_ARG $TARGET_ARG -- -D warnings
fi
if [[ "${{ inputs.run-tests }}" == "true" ]]; then
$CMD test $FEATURES_ARG $TARGET_ARG
fi
if [[ "${{ inputs.run-deny }}" == "true" ]]; then
cargo deny check
fi
if [[ "${{ inputs.run-semver-checks }}" == "true" ]]; then
cargo semver-checks
fi
- name: Save cargo cache
uses: https://data.forgejo.org/actions/cache/save@v4
with:
path: |
~/.cargo/registry
target/
key: cargo-${{ hashFiles('**/Cargo.lock') }}