Skip to content

Commit

Permalink
Separate coverage tests and use cargo-tarpaulin (#290)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergio Arroutbi <sarroutb@redhat.com>
  • Loading branch information
sarroutbi authored Nov 7, 2024
1 parent c3254ed commit 0c724a7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 46 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: "Coverage"
"on":
push:
branches: ["main"]
paths-ignore:
- '**.md'
- '.wordlist.txt'
pull_request:
paths-ignore:
- '**.md'
- '.wordlist.txt'

env:
CARGO_TERM_COLOR: always

jobs:
tests-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install build dependencies
run: bash .github/workflows/install-dependencies
- name: Setup toolchain (coverage)
uses: dtolnay/rust-toolchain@nightly
- name: Install cargo-tarpaulin (coverage)
run: cargo install cargo-tarpaulin
- name: Run tests (coverage)
run: cargo tarpaulin -o Json
env:
RUSTFLAGS: --cfg procmacro2_semver_exempt
- name: Output show (coverage)
run: |
set -eu
coverage=$(cat tarpaulin-report.json | jq .coverage | egrep -o "[0-9]{1,2}\.{1}[0-9]{2}" | sed 's/ //g')

Check failure on line 35 in .github/workflows/coverage.yaml

View workflow job for this annotation

GitHub Actions / Yamllint

35:81 [line-length] line too long (114 > 80 characters)
echo "COVERAGE:${coverage}"
env:
COV_REPORT_DIR: ${{ steps.coverage.outputs.report }}
- name: Report in PR status for the current commit (coverage)
if: github.ref_name != 'main'
run: |
set -eu
total=$(cat tarpaulin-report.json | jq .coverage | egrep -o "[0-9]{1,2}\.{1}[0-9]{2}" | sed 's/ //g')

Check failure on line 43 in .github/workflows/coverage.yaml

View workflow job for this annotation

GitHub Actions / Yamllint

43:81 [line-length] line too long (111 > 80 characters)
echo "TOTAL:${total}"
curl -s "https://sarroutbi:${GITHUB_TOKEN}@api.github.com/repos/sarroutbi/koji-retriever/statuses/${COMMIT_SHA}"\

Check failure on line 45 in .github/workflows/coverage.yaml

View workflow job for this annotation

GitHub Actions / Yamllint

45:81 [line-length] line too long (123 > 80 characters)
-d "{\"state\": \"success\",\"target_url\": \"https://github.com/sarroutbi/koji-retriever/pull/${PULL_NUMBER}/checks?check_run_id=${RUN_ID}\",\"description\": \"${total}%\",\"context\": \"Measured coverage\"}"

Check failure on line 46 in .github/workflows/coverage.yaml

View workflow job for this annotation

GitHub Actions / Yamllint

46:81 [line-length] line too long (221 > 80 characters)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
RUN_ID: ${{ github.run_id }}
PULL_NUMBER: ${{ github.event.pull_request.number }}
COV_REPORT_DIR: ${{ steps.coverage.outputs.report }}
8 changes: 6 additions & 2 deletions .github/workflows/install-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
COMMON="git file bzip2 g++ pkg-config openssl valgrind tree"
COMMON="git file bzip2 g++ pkg-config openssl valgrind tree jq"
DEBIAN_UBUNTU="curl libssl-dev"
FEDORA_CENTOS="openssl-devel"
FEDORA_CENTOS="openssl-devel openssl-libs"

case "${DISTRO}" in
debian:*|ubuntu:*)
Expand All @@ -48,4 +48,8 @@ esac
echo "================= SYSTEM ================="
cat /etc/os-release
uname -a
# For cargo-tarpaulin
libssl_where=$(find /usr/lib* -iname "libssl.so" | tail -1)
ln -s "${libssl_where}" /usr/lib64/libssl.so.1.1
ls -l /usr/lib64/libssl.so.1.1
echo "=========================================="
45 changes: 1 addition & 44 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
matrix:
os:
- fedora:latest
- quay.io/centos/centos:stream9
- quay.io/centos/centos:stream10-development
- debian:latest
- ubuntu:latest
stable: [true]
Expand Down Expand Up @@ -52,49 +52,6 @@ jobs:
run: cargo clippy -- --deny "warnings"
- name: Check formatting
run: cargo fmt --all -- --check
- name: Clean (coverage)
run: cargo clean
- name: Install grcov (coverage)
run: cargo install grcov
- name: Run tests (coverage)
run: cargo test --all --no-fail-fast
env:
CARGO_INCREMENTAL: '0'
RUSTFLAGS: >
-Zprofile -Ccodegen-units=1 -Cinline-threshold=0
-Clink-dead-code -Coverflow-checks=off -Cpanic=abort
-Zpanic_abort_tests -Cinstrument-coverage
RUSTDOCFLAGS: >
-Zprofile -Ccodegen-units=1 -Cinline-threshold=0
-Clink-dead-code -Coverflow-checks=off -Cpanic=abort
-Zpanic_abort_tests -Cinstrument-coverage
- name: Gather data (coverage)
id: coverage
uses: sarroutbi/grcov@v0.1.6
- name: Output show (coverage)
run: |
set -eu
echo "COVERAGE:$(cat ${COV_REPORT_DIR}/badges/flat.svg \
| egrep '<title>coverage: ' | egrep -o "[0-9]{1,2}%" \
| sed 's/ //g')"
env:
COV_REPORT_DIR: ${{ steps.coverage.outputs.report }}
- name: Report in PR status for the current commit (coverage)
if: github.ref_name != 'main'
run: |
set -eu
tree ${COV_REPORT_DIR}
total=$(cat ${COV_REPORT_DIR}/badges/flat.svg | \
egrep '<title>coverage: ' | \
egrep -o "[0-9]{1,2}" | sed 's/ //g')
curl -s "https://sarroutbi:${GITHUB_TOKEN}@api.github.com/repos/sarroutbi/koji-retriever/statuses/${COMMIT_SHA}"\
-d "{\"state\": \"success\",\"target_url\": \"https://github.com/sarroutbi/koji-retriever/pull/${PULL_NUMBER}/checks?check_run_id=${RUN_ID}\",\"description\": \"${total}%\",\"context\": \"Measured coverage\"}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
RUN_ID: ${{ github.run_id }}
PULL_NUMBER: ${{ github.event.pull_request.number }}
COV_REPORT_DIR: ${{ steps.coverage.outputs.report }}
container:
image: ${{matrix.os}}
env:
Expand Down

0 comments on commit 0c724a7

Please sign in to comment.