Skip to content

Commit

Permalink
feat: Add code coverage to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
RedEtherbloom committed Nov 13, 2024
1 parent 927f7b3 commit f207773
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 95 deletions.
13 changes: 8 additions & 5 deletions .github/actions/install-taskwarrior/action.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
80 changes: 5 additions & 75 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
34 changes: 19 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -76,4 +80,4 @@ jobs:
- uses: clechasseur/rs-cargo@v2
with:
command: clippy
args: -- -D warnings
args: -- -D warnings
62 changes: 62 additions & 0 deletions .github/workflows/generate_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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
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: 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@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./target/debug/coverage/lcov

0 comments on commit f207773

Please sign in to comment.