managed-lhapdf 0.4.2

(Unofficial) Rust bindings for the LHAPDF C++ library
Documentation
name: Rust

on:
  push:

defaults:
  run:
    shell: bash

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest
    container: ghcr.io/nnpdf/pineappl-ci:latest
    steps:
      # checkout@v4 uses a newer version of Node that's incompatible with our container's GLIBC
      - uses: actions/checkout@v4

      - name: Run tests
        env:
          RUSTFLAGS: '-Cinstrument-coverage'
        run: |
          # we need stderr, but we can't run test twice because it'll regenerate/modify the binaries which interferes with `llvm-cov`
          cargo test --no-fail-fast 2> >(tee stderr 1>&2)
          # from https://stackoverflow.com/a/51141872/812178
          sed -i 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g' stderr

      - name: Generate code coverage
        run: |
          find . -name '*.profraw' -exec $(rustc --print target-libdir)/../bin/llvm-profdata merge -sparse -o lhapdf.profdata {} +
          ( sed -nE 's/[[:space:]]+Running( unittests|) [^[:space:]]+ \(([^)]+)\)/\2/p' stderr | tr ' ' "\n" ) | \
              xargs printf ' --object %s' | \
              xargs $(rustc --print target-libdir)/../bin/llvm-cov export \
                  --ignore-filename-regex=index.crates.io \
                  --ignore-filename-regex=rustc \
                  --instr-profile=lhapdf.profdata \
                  --skip-functions \
                  --format lcov > lcov.info
          # print all files for which coverage has been generated
          grep SF lcov.info | sort -u | sed 's/SF://'

      - name: Upload to codecov.io
        uses: codecov/codecov-action@v4
        with:
          token: ${{secrets.CODECOV_TOKEN}}