Skip to content

Add code coverage

Add code coverage #8

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 nightly
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly
components: llvm-tools-preview,rustfmt
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- name: Setup postgres on Linux
# Postgresql setup adapted from Diesel CI
# Disable ssl as server doesn't have a trusted cert
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y postgresql
sudo sed -i "s/scram-sha-256/trust/" /etc/postgresql/14/main/pg_hba.conf
sudo cat /etc/postgresql/14/main/pg_hba.conf
sudo service postgresql restart && sleep 3
echo BUTANE_PG_CONNSTR="host=localhost user=postgres sslmode=disable port=5432" >> $GITHUB_ENV
- name: Run test suite
run: |
cargo +nightly 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