gha 0.1.8

Utilities for developing custom GitHub Actions.
Documentation
on:
  pull_request:
  push:
    branches:
      - main

name: Rust CI

jobs:
  lint:
    name: Check formatting and run clippy
    runs-on: ubuntu-latest
    steps:
      - name: Check out the source code
        uses: actions/checkout@v4
      - name: Cache tools
        uses: actions/cache@v4
        with:
          key: ${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy
      - name: Check formatting
        run: cargo fmt --all -- --check
      - name: Run clippy
        run: cargo clippy --all -- -D warnings

  coverage:
    name: Run tests with coverage
    runs-on: ubuntu-latest
    steps:
      - name: Check out the source code
        uses: actions/checkout@v4
      - name: Cache tools
        uses: actions/cache@v4
        with:
          key: ${{ runner.os }}-${{ hashFiles('Cargo.toml') }}
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      - name: Build the binary
        run: cargo build
        env:
          CARGO_INCREMENTAL: '0'
          RUSTC_BOOTSTRAP: '1'
          RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
          RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
      - name: Run unit tests
        run: cargo test
        env:
          CARGO_INCREMENTAL: '0'
          RUSTC_BOOTSTRAP: '1'
          RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
          RUSTDOCFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests'
      - name: Install grcov
        run: |
            if [ ! -x  ~/.cargo/bin/grcov ]
            then
                wget -O /tmp/grcov.tar.bz2 https://github.com/mozilla/grcov/releases/download/v0.8.19/grcov-x86_64-unknown-linux-gnu.tar.bz2
                tar xjf /tmp/grcov.tar.bz2
                chmod +x grcov
                mv grcov ~/.cargo/bin/
            fi
      - name: Run grcov
        run: grcov . -s . --binary-path ./target/debug/ --excl-start '^mod\s+tests\s*\{$' -t covdir --branch --ignore-not-existing --keep-only 'src/**' -o ./target/covdir.json
      - name: Generate coverage report
        uses: ecliptical/covdir-report-action@v0.2
        with:
          file: ./target/covdir.json
          summary: 'true'
          out: ./target/coverage.md
      - name: Add coverage comment to the pull request
        uses: marocchino/sticky-pull-request-comment@v2
        if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' 
        with:
          hide_and_recreate: true
          hide_classify: "OUTDATED"
          path: ./target/coverage.md