Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage #96

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version = 1
test_patterns = [
"butane/tests/**",
"butane_core/tests/**",
"example/tests/**",
]

[[analyzers]]
Expand All @@ -9,3 +11,6 @@ name = "rust"
[analyzers.meta]
msrv = "stable"

[[analyzers]]
enabled = true
name = "test-coverage"
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ indent_size = unset

[LICENSE-APACHE.txt]
indent_size = unset

[deepsource.yml]
max_line_length = 140
80 changes: 80 additions & 0 deletions .github/workflows/deepsource.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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
Loading