Skip to content

Commit 93a147c

Browse files
committed
Add code coverage
1 parent 317fb36 commit 93a147c

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed

.deepsource.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
version = 1
22
test_patterns = [
3-
"butane/tests/**",
3+
"butane/tests/**",
4+
"butane_core/tests/**",
5+
"example/tests/**",
46
]
57

68
[[analyzers]]
@@ -9,3 +11,6 @@ name = "rust"
911
[analyzers.meta]
1012
msrv = "stable"
1113

14+
[[analyzers]]
15+
enabled = true
16+
name = "test-coverage"

.github/workflows/deepsource.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# yamllint disable rule:truthy
2+
# yamllint disable rule:empty-lines
3+
---
4+
name: Code Coverage
5+
6+
on:
7+
pull_request:
8+
push:
9+
branches:
10+
- main
11+
12+
# this allows a subsequently queued workflow run to interrupt previous runs in pull_requests only
13+
concurrency:
14+
group: "${{ github.workflow }}-${{ github.ref }}"
15+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
16+
17+
jobs:
18+
deepsource:
19+
name: Test and submit
20+
runs-on: ubuntu-22.04
21+
steps:
22+
# The checkout must be the PR 'head' sha for deepsource to work
23+
- name: Checkout PR
24+
if: ${{ github.event_name == 'pull_request' }}
25+
uses: actions/checkout@v3
26+
with:
27+
ref: ${{ github.event.pull_request.head.sha }}
28+
29+
- name: Checkout PUSH
30+
if: ${{ github.event_name == 'push' }}
31+
uses: actions/checkout@v3
32+
33+
- uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: nightly
36+
components: rustfmt
37+
38+
- uses: actions/cache@v3
39+
with:
40+
path: |
41+
~/.cargo/bin/
42+
~/.cargo/registry/index/
43+
~/.cargo/registry/cache/
44+
~/.cargo/git/db/
45+
~/.cargo/advisory-dbs/
46+
key: ${{ runner.os }}-coverage-${{ hashFiles('**/Cargo.lock') }}
47+
restore-keys: |
48+
${{ runner.os }}-coverage
49+
50+
# coverage needs a nightly toolchain
51+
- name: Run test suite
52+
run: |
53+
rustup toolchain install nightly --allow-downgrade
54+
cargo +nightly test --all-features --no-fail-fast ||:
55+
env:
56+
CARGO_INCREMENTAL: "0"
57+
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=unwind"
58+
RUSTDOCFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=unwind"
59+
60+
- name: Install grcov
61+
run: |
62+
cargo +stable install grcov || true
63+
64+
- name: Run coverage
65+
id: coverage
66+
uses: actions-rs/[email protected]
67+
with:
68+
config: .grcov.yaml
69+
70+
# DeepSource limits the size of the coverage data file to 50 MB
71+
- name: Move coverage file
72+
run: |
73+
mv ${{ steps.coverage.outputs.report }} ./coverage.xml
74+
ls -al ./coverage.xml
75+
76+
- name: Install deepsource cli
77+
run: |
78+
RELEASE_ID=$(curl -fsSL https://api.github.com/repos/deepsourcelabs/cli/releases/latest | jq -r '.tag_name')
79+
curl -fsSL -o ./deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz \
80+
https://github.com/deepsourcelabs/cli/releases/download/"${RELEASE_ID}"/deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz
81+
curl -fsSL -o ./ds_checksums.txt \
82+
https://github.com/deepsourcelabs/cli/releases/download/"${RELEASE_ID}"/checksums.txt
83+
cat ds_checksums.txt | grep deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz > ds-sha256chk.txt
84+
sha256sum -c --strict ds-sha256chk.txt
85+
tar -xvf deepsource_"${RELEASE_ID//v}"_linux_x86_64.tar.gz deepsource
86+
chmod 755 deepsource
87+
88+
- name: Report test-coverage to DeepSource
89+
if: ${{ !env.ACT }}
90+
env:
91+
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}
92+
run: |
93+
./deepsource report --analyzer test-coverage --key rust --value-file coverage.xml

.grcov.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
branch: true
2+
ignore-not-existing: true
3+
llvm: true

0 commit comments

Comments
 (0)