name: concrete-cpu test

on:
  workflow_dispatch:
  pull_request:
      paths:
        - .github/workflows/concrete_cpu_test.yml
        - backends/concrete-cpu/**
  push:
    branches:
      - 'main'
      - 'release/*'

concurrency:
  group: concrete_cpu_test_${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

env:
  CARGO_TERM_COLOR: always
jobs:
  tests-linux:
    strategy:
      fail-fast: false
      matrix:
        runson: ["ubuntu-20.04"]
    runs-on: ubuntu-20.04
    env:
      RUSTFLAGS: -D warnings
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Rust install
        uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
        with:
          toolchain: nightly-2024-09-30
          override: true
          components: rustfmt, clippy

      - name: Download cargo cache
        uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5

      - name: Formatting
        run: |
          cd backends/concrete-cpu/implementation
          cargo fmt --check

      - name: Remove header to force regeneration
        run: |
          cd backends/concrete-cpu/implementation
          rm include/concrete-cpu.h

      - name: Build
        run: |
          cd backends/concrete-cpu/implementation
          cargo build --all-targets

      - name: Check regenerated header is unchanged
        run: |
          cd backends/concrete-cpu/implementation
          git diff --exit-code

      - name: Lint
        run: |
          cd backends/concrete-cpu/implementation
          cargo clippy --all-targets

      - name: Tests
        run: |
          cd backends/concrete-cpu/implementation
          cargo test --no-fail-fast --all-targets --features=nightly
