Skip to content

Add code coverage

Add code coverage #4

Workflow file for this run

# yamllint disable rule:truthy
# yamllint disable rule:empty-lines
---
name: Code Coverage
on:
pull_request:
push:
branches:
- main
# this allows a subsequently queued workflow run to interrupt previous runs in pull_requests only
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
deepsource:
name: Test and submit
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
steps:
# The checkout must be the PR 'head' sha for deepsource to work
- name: Checkout PR
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout PUSH
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4
- name: Install Rust stable with llvm-tools-preview
uses: actions-rust-lang/setup-rust-toolchain@v1.8.0
with:
components: llvm-tools-preview
- name: Install Rust nightly with rustfmt
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rustfmt
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2.26.8
with:
tool: cargo-llvm-cov
- name: Run test suite
run: |
cargo llvm-cov test --cobertura --output-path coverage.xml --branch --workspace --no-fail-fast --all-features
- name: Install deepsource cli
run: |
RELEASE_ID=$(curl -fsSL https://api.github.com/repos/deepsourcelabs/cli/releases/latest | jq -r '.tag_name')
curl -fsSL -o ./deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz \
https://github.com/deepsourcelabs/cli/releases/download/"${RELEASE_ID}"/deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz
curl -fsSL -o ./ds_checksums.txt \
https://github.com/deepsourcelabs/cli/releases/download/"${RELEASE_ID}"/checksums.txt
cat ds_checksums.txt | grep deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz > ds-sha256chk.txt
sha256sum -c --strict ds-sha256chk.txt
tar -xvf deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz deepsource
chmod 755 deepsource
- name: Report test-coverage to DeepSource
if: ${{ !env.ACT }}
env:
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
run: |
./deepsource report --analyzer test-coverage --key rust --value-file coverage.xml