ares/.github/workflows/ares-shared.yml
2023-12-18 17:46:29 -06:00

94 lines
3.1 KiB
YAML

on:
workflow_call:
env:
CARGO_TERM_COLOR: always
ACTIONS_ALLOW_UNSECURE_COMMANDS: "true"
defaults:
run:
working-directory: rust/ares
jobs:
build:
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
# Determine proper nix platform attribute for runner
- name: Determine Nix platform
id: set-nix-platform
working-directory: .
run:
.github/scripts/arch/get-runner-arch ${{ runner.arch }} ${{ runner.os }} > $GITHUB_OUTPUT
# Install nix, required by nix-shell-action
- uses: cachix/install-nix-action@v23
name: Install Nix
with:
extra_nix_config: "extra-experimental-features = nix-command flakes"
- name: Set cache key for dev env
id: set-cache-key
run: |
echo "Determining devshell path for platform ${{ steps.set-nix-platform.outputs.nix-arch }}"
echo "nix-devshell-path=$(nix eval --raw ".#devShells.${{ steps.set-nix-platform.outputs.nix-arch }}.default.outPath")" >> $GITHUB_OUTPUT
- name: Cache nix build artifacts
id: nix-cache
uses: actions/cache@v3
with:
path: |
nix-devshell.nixstore
key: nix-${{ steps.set-cache-key.outputs.nix-devshell-path }}
- name: Restore cached nix artifacts
if: steps.nix-cache.outputs.cache-hit == 'true'
working-directory: .
run: |
pwd
ls
nix-store --import < nix-devshell.nixstore
- name: Cache rust build artifacts
id: cache_rust
uses: Swatinem/rust-cache@v2
with:
key: rust-${{ steps.set-cache-key.outputs.nix-devshell-path }}
workspaces: "rust/ares -> target"
# Check formatting
- name: Format
run: |
nix develop --command bash -c "cargo fmt --check"
# See clippy linter docs: https://github.com/rust-lang/rust-clippy
#
# First linter is set to fail for all warnings, then ignored warnings are
# explicitly listed
#
# XX TODO make a script with all the flags for the linter
- name: Lint
run: |
nix develop --command bash -c "cargo clippy --all-targets --no-deps -- -D warnings -A clippy::missing_safety_doc"
# Build Ares
- name: Build
run: |
nix develop --command bash -c "cargo build --release --verbose"
# Run tests
- name: Test
run: |
nix develop --command bash -c "cargo test --verbose -- --test-threads=1"
- name: Build nix cache export
if: steps.nix-cache.outputs.cache-hit != 'true'
run: |
pwd
nix eval --json ".#devShells.${{ steps.set-nix-platform.outputs.nix-arch }}.default.buildInputs" 2>/dev/null
nix eval --json ".#devShells.${{ steps.set-nix-platform.outputs.nix-arch }}.default.buildInputs" 2>/dev/null | jq -r '.[]' | xargs nix-store --query --requisites
nix-store --export $(nix eval --json ".#devShells.${{ steps.set-nix-platform.outputs.nix-arch }}.default.buildInputs" 2>/dev/null | jq -r '.[]' | xargs nix-store --query --requisites) > ../../nix-devshell.nixstore
ls -lh