Skip to content

Commit f176db5

Browse files
authored
ci: enable code coverage with tarpaulin uploading to gh-pages (#78)
1 parent 2887003 commit f176db5

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

.github/workflows/rust.yml

+94-1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,98 @@ jobs:
6666

6767
steps:
6868
- uses: actions/checkout@v1
69-
- uses: dtolnay/rust-toolchain@nightly
69+
- uses: dtolnay/rust-toolchain@stable
7070
- run: cargo test --package influxdb --package influxdb_derive --all-features --no-fail-fast
71+
72+
coverage:
73+
name: Code Coverage (stable/ubuntu-20.04)
74+
runs-on: ubuntu-20.04
75+
services:
76+
influxdb:
77+
image: influxdb
78+
ports:
79+
- 8086:8086
80+
authed_influxdb:
81+
image: influxdb
82+
ports:
83+
- 9086:8086
84+
env:
85+
INFLUXDB_HTTP_AUTH_ENABLED: true
86+
INFLUXDB_ADMIN_USER: admin
87+
INFLUXDB_ADMIN_PASSWORD: password
88+
INFLUXDB_USER: nopriv_user
89+
INFLUXDB_USER_PASSWORD: password
90+
91+
steps:
92+
- uses: actions/checkout@v2
93+
- uses: dtolnay/rust-toolchain@stable
94+
95+
- name: Get Rust Version
96+
id: rust-version
97+
run: echo "::set-output name=VERSION::$(cargo -V | head -n1 | awk '{print $2}')"
98+
99+
- name: Get Tarpaulin Version
100+
id: tarpaulin-version
101+
run: echo "::set-output name=VERSION::$(wget -qO- 'https://api.github.com/repos/xd009642/tarpaulin/releases/latest' | jq -r '.tag_name')"
102+
103+
- uses: actions/cache@v2
104+
with:
105+
path: |
106+
~/.cargo/bin
107+
~/.cargo/git
108+
~/.cargo/registry
109+
target
110+
key: ${{ runner.os }}-cargo-${{ steps.rust-version.outputs.VERSION }}-tarpaulin-${{ steps.tarpaulin-version.outputs.VERSION }} }}
111+
112+
- name: Install Tarpaulin
113+
run: |
114+
ls -lh ~/.cargo || true
115+
ls -lh ~/.cargo/bin || true
116+
cargo install cargo-tarpaulin --version ${{ steps.tarpaulin-version.outputs.VERSION }}
117+
118+
- name: Run Tarpaulin coverage tests
119+
run: |
120+
cargo tarpaulin -v \
121+
--target-dir target/tarpaulin \
122+
--workspace \
123+
--all-features \
124+
--exclude-files 'derive/*' \
125+
--exclude-files 'target/*' \
126+
--ignore-panics --ignore-tests \
127+
--out Html --out Json
128+
env:
129+
RUST_BACKTRACE: 1
130+
RUST_LOG: info
131+
132+
- uses: actions/upload-artifact@v2
133+
with:
134+
name: tarpaulin-report
135+
path: |
136+
tarpaulin-report.json
137+
tarpaulin-report.html
138+
139+
pages:
140+
runs-on: ubuntu-20.04
141+
needs:
142+
- coverage
143+
if: github.ref == 'refs/heads/master'
144+
steps:
145+
- uses: actions/checkout@v2
146+
with:
147+
ref: gh-pages
148+
149+
- uses: actions/download-artifact@v2
150+
with:
151+
name: tarpaulin-report
152+
153+
- run: |
154+
coverage=$(jq '.files | { covered: map(.covered) | add, coverable: map(.coverable) | add } | .covered / .coverable * 10000 | round | . / 100' tarpaulin-report.json)
155+
color=$([[ $coverage < 80 ]] && printf yellow || printf brightgreen)
156+
wget -qO coverage.svg "https://img.shields.io/badge/coverage-$coverage%25-$color"
157+
158+
git add coverage.svg tarpaulin-report.html
159+
git status
160+
161+
- uses: stefanzweifel/git-auto-commit-action@v4
162+
with:
163+
commit_message: "GitHub Pages for ${{ github.sha }}"

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<a href="https://travis-ci.org/Empty2k12/influxdb-rust">
1717
<img src="https://travis-ci.org/Empty2k12/influxdb-rust.svg?branch=master" alt='Build Status' />
1818
</a>
19+
<a href="https://Empty2k12.github.io/influxdb-rust/tarpaulin-report.html">
20+
<img src="https://Empty2k12.github.io/influxdb-rust/coverage.svg" alt="Coverage Report" />
21+
</a>
1922
<a href="https://docs.rs/crate/influxdb">
2023
<img src="https://docs.rs/influxdb/badge.svg" alt='Documentation Status' />
2124
</a>

README.tpl

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<a href="https://travis-ci.org/Empty2k12/influxdb-rust">
1717
<img src="https://travis-ci.org/Empty2k12/influxdb-rust.svg?branch=master" alt='Build Status' />
1818
</a>
19+
<a href="https://Empty2k12.github.io/influxdb-rust/tarpaulin-report.html">
20+
<img src="https://Empty2k12.github.io/influxdb-rust/coverage.svg" alt="Coverage Report" />
21+
</a>
1922
<a href="https://docs.rs/crate/influxdb">
2023
<img src="https://docs.rs/influxdb/badge.svg" alt='Documentation Status' />
2124
</a>

0 commit comments

Comments
 (0)