Skip to content

Commit af11b1a

Browse files
authored
support coverage report (#3)
* support coverage report * temporary comment out run conditions * update on * add sonar properties * updated CI
1 parent 318d38e commit af11b1a

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
jobs:
88
validate:
9+
name: "Validate"
910
runs-on: ubuntu-latest
1011
steps:
1112
- name: Checkout repository
@@ -25,6 +26,7 @@ jobs:
2526
- name: Execute Pre-Commit
2627
run: pre-commit run --show-diff-on-failure --color=always --all-files
2728
pyton_tests:
29+
name: "Python Tests"
2830
runs-on: ubuntu-latest
2931
strategy:
3032
fail-fast: true
@@ -58,17 +60,50 @@ jobs:
5860
- name: Test
5961
run: poetry run pytest
6062
rust_tests:
63+
name: "Rust Tests"
6164
runs-on: ubuntu-latest
6265
steps:
6366
- name: Checkout Repository
6467
uses: actions/checkout@v3
6568
- name: Install Rust
6669
uses: actions-rs/toolchain@v1
6770
with:
68-
profile: minimal
6971
toolchain: stable
7072
override: true
71-
- name: Install Rust Dependencies
72-
uses: actions-rs/cargo@v1
73+
target: x86_64-unknown-linux-musl
74+
components: llvm-tools-preview
75+
- name: Download grcov
76+
run: |
77+
mkdir -p "${HOME}/.local/bin"
78+
curl -sL https://github.com/mozilla/grcov/releases/download/v0.8.10/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf - -C "${HOME}/.local/bin"
79+
echo "$HOME/.local/bin" >> $GITHUB_PATH
80+
- name: Test with Coverage
81+
run: CARGO_INCREMENTAL=0 RUSTFLAGS='-Cinstrument-coverage' LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' cargo test
82+
- name: Generate Coverage Report
83+
run: mkdir coverage && grcov . --binary-path ./target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../*' --ignore "/*" -o coverage.lcov
84+
- uses: actions/upload-artifact@v3
7385
with:
74-
command: test
86+
name: coverage-lcov
87+
path: coverage.lcov
88+
sonar:
89+
name: "Sonar"
90+
needs:
91+
- pyton_tests
92+
- rust_tests
93+
- validate
94+
if: github.event.pull_request.head.repo.fork == false
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Check out repository
98+
uses: actions/checkout@v3
99+
- name: Download Artifacts
100+
uses: actions/download-artifact@v3
101+
with:
102+
name: coverage-lcov
103+
- name: Fix coverage file for sonarcloud
104+
run: sed -i "s/home\/runner\/work\/http_utils\/src/github\/workspace/g" coverage.lcov
105+
- name: SonarCloud Scan
106+
uses: sonarsource/sonarcloud-github-action@master
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ __pycache__/
33
.pytest_cache/
44
*.iml
55
.idea
6+
*.profraw
7+
coverage*

sonar-project.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sonar.projectKey=starlite-api_http-utils
2+
sonar.organization=starlite-api
3+
sonar.javascript.lcov.reportPaths==coverage.lcov
4+
sonar.sourceEncoding=UTF-8
5+
sonar.sources=src

0 commit comments

Comments
 (0)