Giter Site home page Giter Site logo

Support Rust stable about grcov HOT 2 OPEN

actions-rs avatar actions-rs commented on August 28, 2024
Support Rust stable

from grcov.

Comments (2)

williamdes avatar williamdes commented on August 28, 2024 4
name: Build and test rust code

on:
    pull_request:
    push:

permissions:
    contents: read

concurrency:
    group: ${{ github.workflow }}-${{ github.ref }}
    cancel-in-progress: true

jobs:
    build_and_test:
        runs-on: ubuntu-latest
        name: Build and test
        steps:
            - name: Cache cargo registry
              uses: actions/cache@v3
              with:
                  path: ~/.cargo/registry
                  key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
            - name: Cache cargo index
              uses: actions/cache@v3
              with:
                  path: ~/.cargo/git
                  key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
            - name: Cache cargo binaries
              uses: actions/cache@v3
              with:
                  path: ~/.cargo/bin
                  key: ${{ runner.os }}-cargo-bin-${{ hashFiles('**/Cargo.lock') }}
            - name: Cache cargo build
              uses: actions/cache@v3
              with:
                  path: target
                  key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
            - name: Checkout repository
              uses: actions/checkout@v3
            - name: Set up toolchain
              uses: actions-rs/toolchain@v1
              with:
                  profile: minimal
                  toolchain: 1.64.0
                  override: true
                  components: rustfmt, llvm-tools-preview
            - name: Build
              uses: actions-rs/cargo@v1
              with:
                  command: build
                  args: --release
              env:
                  CARGO_INCREMENTAL: "0"
                  RUSTFLAGS: "-Cinstrument-coverage"
                  RUSTDOCFLAGS: "-Cinstrument-coverage"
            - name: Test
              uses: actions-rs/cargo@v1
              with:
                  command: test
                  args: --all-features --no-fail-fast
              env:
                  CARGO_INCREMENTAL: "0"
                  RUSTFLAGS: "-Cinstrument-coverage"
                  RUSTDOCFLAGS: "-Cinstrument-coverage"
            - name: Install grcov
              run: if [[ ! -e ~/.cargo/bin/grcov ]]; then cargo install grcov; fi
            - name: Run grcov
              run: grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov
            - uses: codecov/codecov-action@v3
              with:
                  files: ./coverage.lcov
                  flags: rust
                  fail_ci_if_error: true # optional (default = false)

It's an alternative way inspired by #105

from grcov.

williamdes avatar williamdes commented on August 28, 2024

Ref: https://blog.rng0.io/how-to-do-code-coverage-in-rust
A working workflow (added on my PR: williamdes/mariadb-mysql-kbs#288):

name: Build and test rust code

on:
    pull_request:
    push:

permissions:
    contents: read

concurrency:
    group: ${{ github.workflow }}-${{ github.ref }}
    cancel-in-progress: true

jobs:
    build_and_test:
        runs-on: ubuntu-latest
        name: Build and test
        steps:
            - name: Cache cargo registry
              uses: actions/cache@v3
              with:
                  path: ~/.cargo/registry
                  key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
            - name: Cache cargo index
              uses: actions/cache@v3
              with:
                  path: ~/.cargo/git
                  key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
            - name: Cache cargo build
              uses: actions/cache@v3
              with:
                  path: target
                  key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
            - name: Checkout repository
              uses: actions/checkout@v3
            - name: Set up toolchain
              uses: actions-rs/toolchain@v1
              with:
                  profile: minimal
                  toolchain: 1.64.0
                  override: true
                  components: llvm-tools-preview
            - name: Build
              uses: actions-rs/cargo@v1
              with:
                  command: build
                  args: --release
              env:
                CARGO_INCREMENTAL: '0'
                RUSTFLAGS: '-Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cinstrument-coverage'
                RUSTDOCFLAGS: '-Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cinstrument-coverage'
            - name: Test
              uses: actions-rs/cargo@v1
              with:
                  command: test
                  args: --all-features --no-fail-fast
              env:
                CARGO_INCREMENTAL: '0'
                RUSTFLAGS: '-Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cinstrument-coverage'
                RUSTDOCFLAGS: '-Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cinstrument-coverage'
            - name: Download grcov
              run: |
                set -eux;
                mkdir -p "${HOME}/.local/bin"
                curl -sL https://github.com/mozilla/grcov/releases/download/v0.8.13/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf - -C "${HOME}/.local/bin"
                echo "$HOME/.local/bin" >> $GITHUB_PATH
            - name: grcov
              id: coverage
              run: |
                set -eux;
                grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o ./lcov.info
                echo "report=./lcov.info" >> $GITHUB_OUTPUT
              #uses: actions-rs/[email protected]
            - uses: codecov/codecov-action@v3
              with:
                files: ${{ steps.coverage.outputs.report }}
                flags: rust
                fail_ci_if_error: true # optional (default = false)

from grcov.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.