From 9b2ec95c6254e809992f99bc57e31691d2c50118 Mon Sep 17 00:00:00 2001 From: RedEtherbloom Date: Wed, 13 Nov 2024 17:02:07 +0100 Subject: [PATCH] feat: Add code coverage to CI --- .../actions/install-taskwarrior/action.yml | 13 +-- .github/workflows/cd.yml | 80 ++----------------- .github/workflows/ci.yml | 34 ++++---- .github/workflows/generate_coverage.yml | 68 ++++++++++++++++ 4 files changed, 100 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/generate_coverage.yml diff --git a/.github/actions/install-taskwarrior/action.yml b/.github/actions/install-taskwarrior/action.yml index 67d663a3..038c2b44 100644 --- a/.github/actions/install-taskwarrior/action.yml +++ b/.github/actions/install-taskwarrior/action.yml @@ -1,7 +1,7 @@ # This action definition may look complicated, but it only builds taskwarrior from the latest source release and installs it. # The rest of the file is caching of results and checks to avoid ambiguous failure in case taskwarrior changes their release strategy. -name: 'Install Taskwarrior' -description: 'Builds latests stable taskwarrior release install it' +name: Install Taskwarrior +description: Builds latests stable taskwarrior release install it inputs: secret_gh_token: description: "GH token used for downloading the release asset" @@ -13,7 +13,7 @@ runs: using: "composite" steps: - name: Update apt - run: sudo apt get update + run: sudo apt-get update shell: bash - name: Install libuuid run: sudo apt-get install uuid-dev uuid-runtime @@ -51,13 +51,13 @@ runs: uses: actions/cache/restore@v4 with: path: /tmp/task.deb - key: ${{ runner.os }}-taskwarrior-${{ steps.calculate-task-sha256.outputs.task_sha256 }} + key: ${{ runner.os }}-taskwarrior-${{ steps.calculate-task-sha256.outputs.task_sha256 }}-rust-${{ inputs.rust_toolchain }} - name: Install rust toolchain and rust cache if: steps.cache-taskwarrior-restore.outputs.cache-hit != 'true' uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: inputs.rust_toolchain + toolchain: ${{ inputs.rust_toolchain }} override: false - name: Extract taskwarrior source code if: steps.cache-taskwarrior-restore.outputs.cache-hit != 'true' @@ -101,3 +101,6 @@ runs: - name: Install taskwarrior run: sudo dpkg -i /tmp/task.deb shell: bash + - name: Test if installation worked + run: task --version + shell: bash \ No newline at end of file diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index cbe506e8..f1b29e5c 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -11,9 +11,12 @@ permissions: contents: write jobs: - call_build: + build: uses: ./.github/workflows/build.yml + generate_coverage: + uses: ./.github/workflows/generate_coverage.yml + homebrew: name: Bump Homebrew formula runs-on: macos-latest @@ -96,77 +99,4 @@ jobs: - name: Install cargo-aur run: cargo install cargo-aur - name: Build aur package - run: cargo aur - - grcov: - runs-on: ubuntu-latest - env: - TASKRC: taskwarrior-testdata/.taskrc - TASKDATA: taskwarrior-testdata/.task - RUST_BACKTRACE: full - steps: - - uses: actions/checkout@v4 - - run: sudo apt-get update - - name: 'Install Taskwarrior' - uses: ./.github/actions/install-taskwarrior - with: - secret_gh_token: ${{ secrets.GITHUB_TOKEN }} - - run: | - task --version - - uses: actions/checkout@v4 - with: - repository: kdheepak/taskwarrior-testdata - path: taskwarrior-testdata - - run: | - # prepare taskwarrior, initial setup - task rc.confirmation=off || echo 0 - - name: Install Rust toolchain - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - toolchain: nightly - override: true - components: llvm-tools-preview - - name: Clean environment for grcov - uses: clechasseur/rs-cargo@v2 - with: - command: clean - - name: Build taskwarrior-tui with coverage - uses: clechasseur/rs-cargo@v2 - with: - command: build - env: - RUSTFLAGS: "-Cinstrument-coverage" - - name: Run taskwarrior-tui tests in coverage environment - uses: clechasseur/rs-cargo@v2 - with: - command: test - args: --worksoace - env: - RUSTFLAGS: "-Cinstrument-coverage" - LLVM_PROFILE_FILE: "your_name-%p-%m.profraw" - - name: Install grcov - uses: clechasseur/rs-cargo@v2 - with: - command: install - args: grcov - - name: Gather coverage data - run: | - mkdir ./target/debug/coverage/ - grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./target/debug/coverage/ - shell: bash - - name: Coveralls upload - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - parallel: true - file: ./target/debug/coverage/lcov - - grcov_finalize: - runs-on: ubuntu-latest - needs: grcov - steps: - - name: Coveralls finalization - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - parallel-finished: true + run: cargo aur \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23728a6d..7f66c6ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,37 +19,41 @@ jobs: test: name: Test Suite runs-on: ubuntu-latest - env: - TASKRC: taskwarrior-testdata/.taskrc - TASKDATA: taskwarrior-testdata/.task - RUST_BACKTRACE: full steps: - uses: actions/checkout@v4 - - run: sudo apt-get update - - name: 'Install Taskwarrior' + - name: Install Taskwarrior uses: ./.github/actions/install-taskwarrior with: secret_gh_token: ${{ secrets.GITHUB_TOKEN }} - - run: | - task --version - - uses: actions/checkout@v4 - with: - repository: kdheepak/taskwarrior-testdata - path: taskwarrior-testdata - run: | # prepare taskwarrior, initial setup task rc.confirmation=off || echo 0 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: stable - override: true + override: true + - name: Install testdata + uses: actions/checkout@v4 + with: + repository: kdheepak/taskwarrior-testdata + path: taskwarrior-testdata - uses: clechasseur/rs-cargo@v2 with: command: test args: --workspace -- --nocapture + env: + TASKRC: taskwarrior-testdata/.taskrc + TASKDATA: taskwarrior-testdata/.task + RUST_BACKTRACE: full + + + generate_coverage: + uses: ./.github/workflows/generate_coverage.yml + # Avoid double-compiling taskwarrior if not cached, or wasting CI time if tests fail + needs: test fmt: - name: Rustfmt + name: Rustfm runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -76,4 +80,4 @@ jobs: - uses: clechasseur/rs-cargo@v2 with: command: clippy - args: -- -D warnings + args: -- -D warnings \ No newline at end of file diff --git a/.github/workflows/generate_coverage.yml b/.github/workflows/generate_coverage.yml new file mode 100644 index 00000000..d0ad46b2 --- /dev/null +++ b/.github/workflows/generate_coverage.yml @@ -0,0 +1,68 @@ +name: generate_coverage + +on: + workflow_call + +jobs: + grcov: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Taskwarrior + uses: ./.github/actions/install-taskwarrior + with: + secret_gh_token: ${{ secrets.GITHUB_TOKEN }} + - run: | + # prepare taskwarrior, initial setup + task rc.confirmation=off || echo 0 + + - name: Install Rust toolchain for grcov compilation + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + override: true + - name: Install grcov + uses: clechasseur/rs-cargo@v2 + with: + command: install + args: grcov + + - name: Install Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: nightly + override: true + components: llvm-tools-preview + - name: Checkout testdata + uses: actions/checkout@v4 + with: + repository: kdheepak/taskwarrior-testdata + path: taskwarrior-testdata + - name: Build taskwarrior-tui with coverage + uses: clechasseur/rs-cargo@v2 + with: + command: build + env: + RUSTFLAGS: "-Cinstrument-coverage" + - name: Run taskwarrior-tui tests in coverage environment + uses: clechasseur/rs-cargo@v2 + with: + command: test + args: --workspace -- --nocapture + env: + TASKRC: taskwarrior-testdata/.taskrc + TASKDATA: taskwarrior-testdata/.task + RUST_BACKTRACE: full + RUSTFLAGS: "-Cinstrument-coverage" + LLVM_PROFILE_FILE: "your_name-%p-%m.profraw" + + - name: Gather coverage data + run: | + mkdir ./target/debug/coverage/ + grcov . -s . --binary-path ./target/debug/ -t lcov --branch --ignore-not-existing -o ./target/debug/coverage/ + shell: bash + - name: Coveralls upload + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: ./target/debug/coverage/lcov \ No newline at end of file