Skip to content

refactor: use service-toolkit runtime helpers; drop local dupes #49

refactor: use service-toolkit runtime helpers; drop local dupes

refactor: use service-toolkit runtime helpers; drop local dupes #49

Workflow file for this run

name: code-quality
on:
pull_request:
paths-ignore:
- "README.md"
- "CHANGELOG.md"
- "LICENSE"
- "docs/**"
- ".github/dependabot.yml"
- ".github/workflows/build-ghcr.yml"
- ".github/workflows/discord-commit-notify.yml"
push:
branches: [main]
paths-ignore:
- "README.md"
- "CHANGELOG.md"
- "LICENSE"
- "docs/**"
- ".github/dependabot.yml"
- ".github/workflows/build-ghcr.yml"
- ".github/workflows/discord-commit-notify.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
check:
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Ensure native build toolchain
run: |
resolve_compiler() {
for candidate in "$@"; do
if command -v "$candidate" >/dev/null 2>&1; then
command -v "$candidate"
return 0
fi
done
return 1
}
use_existing_toolchain() {
cc_path="$(resolve_compiler cc gcc clang)" || return 1
cxx_path="$(resolve_compiler c++ g++ clang++)" || return 1
toolchain_bin="${RUNNER_TEMP:-/tmp}/native-toolchain/bin"
mkdir -p "$toolchain_bin"
ln -sf "$cc_path" "$toolchain_bin/cc"
ln -sf "$cxx_path" "$toolchain_bin/c++"
echo "$toolchain_bin" >> "$GITHUB_PATH"
echo "CC=$toolchain_bin/cc" >> "$GITHUB_ENV"
echo "CXX=$toolchain_bin/c++" >> "$GITHUB_ENV"
echo "Using compiler pair: $cc_path / $cxx_path"
return 0
}
if use_existing_toolchain; then
exit 0
fi
if ! command -v apt-get >/dev/null 2>&1; then
echo "No usable compiler found and apt-get is unavailable on this runner" >&2
exit 1
fi
if [ "$(id -u)" -eq 0 ]; then
apt-get update
apt-get install -y build-essential pkg-config libssl-dev
elif command -v sudo >/dev/null 2>&1 && sudo -n true >/dev/null 2>&1; then
sudo -n apt-get update
sudo -n apt-get install -y build-essential pkg-config libssl-dev
else
echo "No usable compiler found and runner user has no passwordless sudo" >&2
exit 1
fi
- name: Cache cargo registry & build
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Format check
run: cargo fmt -- --check
- name: Clippy
run: cargo clippy --all-targets -- -D warnings
- name: Tests
run: cargo test