on:
  pull_request:
  push:
  workflow_dispatch:

jobs:
  build_ubuntu:
    runs-on: ubuntu-latest
    steps:
    - name: gitconfig
      run: |
        git config --global core.autocrlf input

    - name: checkout
      uses: actions/checkout@v4
      with:
        fetch-depth: 0

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable
      with:
        toolchain: stable
        targets: x86_64-unknown-linux-gnu
        components: rustfmt, clippy

    - name: Set up cargo cache
      uses: Swatinem/rust-cache@v2
      continue-on-error: false
      with:
        key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
        shared-key: ${{ runner.os }}-cargo-
        workspaces: |
          rustybits/

    - name: validate-1m-linux
      env:
        CC: 'gcc'
        CXX: 'g++'
        BRANCH: ${{  github.ref_name }}
      run: |
        sudo apt update && sudo apt install -y valgrind xmlstarlet gcovr iperf3 tree
        make one ZT_COVERAGE=1 ZT_TRACE=1
        sudo chmod +x ./.github/workflows/validate-linux.sh
        sudo ./.github/workflows/validate-linux.sh

    - name: Archive test results
      uses: actions/upload-artifact@v4
      with:
        name: ${{github.sha}}-test-results
        path: "*test-results*"

    - name: final-report
      run: |
        sudo chmod +x ./.github/workflows/validate-report.sh
        sudo ./.github/workflows/validate-report.sh