This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 3ce3b84  chore(ci): Refactor code coverage into a docker compose job 
(#182)
3ce3b84 is described below

commit 3ce3b842466813609a2e10bd20d4ee95e7c648e0
Author: Dewey Dunnington <[email protected]>
AuthorDate: Fri Apr 21 15:01:48 2023 -0400

    chore(ci): Refactor code coverage into a docker compose job (#182)
---
 .github/workflows/build-and-test.yaml   |  16 +---
 .github/workflows/coverage.yaml         |  60 +++++++++++++++
 .gitignore                              |   1 +
 CMakeLists.txt                          |  14 ++--
 ci/scripts/coverage.sh                  | 128 ++++++++++++++++++++++++++++++++
 docker-compose.yml                      |  15 ++++
 extensions/nanoarrow_ipc/CMakeLists.txt |   6 +-
 7 files changed, 214 insertions(+), 26 deletions(-)

diff --git a/.github/workflows/build-and-test.yaml 
b/.github/workflows/build-and-test.yaml
index 8f6b423..b3857fc 100644
--- a/.github/workflows/build-and-test.yaml
+++ b/.github/workflows/build-and-test.yaml
@@ -40,7 +40,7 @@ jobs:
       fail-fast: false
       matrix:
         config:
-          - {label: default-build, cmake_args: "-DNANOARROW_CODE_COVERAGE=ON"}
+          - {label: default-build}
           - {label: namespaced-build, cmake_args: 
"-DNANOARROW_NAMESPACE=SomeUserNamespace"}
           - {label: bundled-build, cmake_args: "-DNANOARROW_BUNDLE=ON"}
           - {label: bundled-cpp-build, cmake_args: "-DNANOARROW_BUNDLE=ON 
-DNANOARROW_BUNDLE_AS_CPP=ON"}
@@ -108,20 +108,6 @@ jobs:
           name: nanoarrow-memcheck
           path: build/Testing/Temporary/MemoryChecker.*.log
 
-      - name: Calculate coverage
-        if: success() && matrix.config.label == 'default-build'
-        run: |
-          SOURCE_PREFIX=`pwd`
-          mkdir build/cov
-          cd build/cov
-          gcov -abcfu --source-prefix=$SOURCE_PREFIX `find 
../CMakeFiles/nanoarrow.dir/ -name "*.gcno"`
-
-      - name: Upload coverage
-        if: success() && matrix.config.label == 'default-build'
-        uses: codecov/codecov-action@v2
-        with:
-          directory: build/cov
-
   bundle-dist:
     needs: test-c
     runs-on: ubuntu-latest
diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml
new file mode 100644
index 0000000..25dd1cf
--- /dev/null
+++ b/.github/workflows/coverage.yaml
@@ -0,0 +1,60 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: coverage
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    branches:
+      - main
+    paths:
+      - '.github/workflows/coverage.yaml'
+      - 'ci/scripts/coverage.sh'
+      - 'ci/docker/ubuntu.dockerfile'
+      - 'docker-compose.yml'
+      - 'CMakeLists.txt'
+      - 'src/nanoarrow/**'
+      - 'extensions/nanoarrow_ipc/**'
+      - 'r/**'
+
+jobs:
+  coverage:
+
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v2
+
+      - name: Calculate code coverage
+        run: |
+          echo "::group::Docker Pull"
+          docker compose run --rm -e GITHUB_ACTIONS coverage
+
+      - name: Upload coverage artifacts
+        if: always()
+        uses: actions/upload-artifact@main
+        with:
+          name: nanarrow-coverage
+          path: _coverage
+
+      - name: Upload coverage to codecov
+        uses: codecov/codecov-action@v2
+        with:
+          files: '_coverage/coverage.info,_coverage/r_coverage.json'
diff --git a/.gitignore b/.gitignore
index 1b8597a..5fd5f66 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+_coverage/
 build/
 out/
 arrow-hpp
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0db1682..01b96dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -194,8 +194,6 @@ if(NANOARROW_BUILD_TESTS)
         target_compile_options(coverage_config INTERFACE -O0 -g --coverage)
         target_link_options(coverage_config INTERFACE --coverage)
         target_link_libraries(nanoarrow coverage_config)
-        # Because nanoarrow.hpp is header-only we have to link the test here 
to get coverage
-        target_link_libraries(nanoarrow_hpp_test coverage_config)
     endif()
 
     # On Windows, dynamically linking Arrow is difficult to get right,
@@ -206,12 +204,12 @@ if(NANOARROW_BUILD_TESTS)
         set(NANOARROW_ARROW_TARGET arrow_shared)
     endif()
 
-    target_link_libraries(utils_test nanoarrow gtest_main 
${NANOARROW_ARROW_TARGET})
-    target_link_libraries(buffer_test nanoarrow gtest_main)
-    target_link_libraries(array_test nanoarrow gtest_main 
${NANOARROW_ARROW_TARGET})
-    target_link_libraries(schema_test nanoarrow gtest_main 
${NANOARROW_ARROW_TARGET})
-    target_link_libraries(array_stream_test nanoarrow gtest_main)
-    target_link_libraries(nanoarrow_hpp_test nanoarrow gtest_main)
+    target_link_libraries(utils_test nanoarrow gtest_main 
${NANOARROW_ARROW_TARGET} coverage_config)
+    target_link_libraries(buffer_test nanoarrow gtest_main coverage_config)
+    target_link_libraries(array_test nanoarrow gtest_main 
${NANOARROW_ARROW_TARGET} coverage_config)
+    target_link_libraries(schema_test nanoarrow gtest_main 
${NANOARROW_ARROW_TARGET} coverage_config)
+    target_link_libraries(array_stream_test nanoarrow gtest_main 
coverage_config)
+    target_link_libraries(nanoarrow_hpp_test nanoarrow gtest_main 
coverage_config)
 
     include(GoogleTest)
     gtest_discover_tests(utils_test)
diff --git a/ci/scripts/coverage.sh b/ci/scripts/coverage.sh
new file mode 100755
index 0000000..1a2c78b
--- /dev/null
+++ b/ci/scripts/coverage.sh
@@ -0,0 +1,128 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -e
+set -o pipefail
+
+if [ ${VERBOSE:-0} -gt 0 ]; then
+  set -x
+fi
+
+SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
+NANOARROW_DIR="$(cd "${SOURCE_DIR}/../.." && pwd)"
+
+show_header() {
+  if [ -z "$GITHUB_ACTIONS" ]; then
+    echo ""
+    printf '=%.0s' $(seq ${#1}); printf '\n'
+    echo "${1}"
+    printf '=%.0s' $(seq ${#1}); printf '\n'
+  else
+    echo "::group::${1}"; printf '\n'
+  fi
+}
+
+case $# in
+  0) TARGET_NANOARROW_DIR="${NANOARROW_DIR}"
+     ;;
+  1) TARGET_NANOARROW_DIR="$1"
+     ;;
+  *) echo "Usage:"
+     echo "  Build documentation based on a source checkout elsewhere:"
+     echo "    $0 path/to/arrow-nanoarrow"
+     echo "  Build documentation for this nanoarrow checkout:"
+     echo "    $0"
+     exit 1
+     ;;
+esac
+
+function main() {
+    SANDBOX_DIR="${TARGET_NANOARROW_DIR}/_coverage"
+    if [ -d "${SANDBOX_DIR}" ]; then
+        rm -rf "${SANDBOX_DIR}"
+    fi
+    mkdir "${SANDBOX_DIR}"
+
+    # Bulid + run tests with gcov for core library
+    show_header "Build + test nanoarrow"
+    mkdir "${SANDBOX_DIR}/nanoarrow"
+    pushd "${SANDBOX_DIR}/nanoarrow"
+
+    cmake "${TARGET_NANOARROW_DIR}" \
+        -DNANOARROW_BUILD_TESTS=ON -DNANOARROW_CODE_COVERAGE=ON
+    cmake --build .
+    ctest .
+
+    popd
+
+    # Build + run tests with gcov for IPC extension
+    show_header "Build + test nanoarrow_ipc"
+    mkdir "${SANDBOX_DIR}/nanoarrow_ipc"
+    pushd "${SANDBOX_DIR}/nanoarrow_ipc"
+
+    cmake "${TARGET_NANOARROW_DIR}/extensions/nanoarrow_ipc" \
+        -DNANOARROW_IPC_BUILD_TESTS=ON -DNANOARROW_IPC_CODE_COVERAGE=ON
+    cmake --build .
+    ctest .
+
+    popd
+
+    pushd "${SANDBOX_DIR}"
+
+    # Generate coverage.info file for both cmake projects using lcov
+    show_header "Calculate CMake project coverage"
+    lcov --capture --directory . \
+        --exclude "*_test.cc" \
+        --exclude "/usr/*" \
+        --exclude "*/gtest/*" \
+        --exclude "*/flatcc/*" \
+        --exclude "*_generated.h" \
+        --output-file coverage.info
+
+    # Generate the html coverage while we're here
+    genhtml coverage.info --output-directory html --prefix 
"${TARGET_NANOARROW_DIR}"
+
+    # Stripping the leading /nanoarrow/ out of the path is probably possible 
with
+    # an argument of lcov but none of the obvious ones seem to work so...
+    sed -i.bak coverage.info -e 's|SF:/nanoarrow/|SF:|'
+    rm coverage.info.bak
+
+    # Print a summary
+    show_header "CMake project coverage summary"
+    lcov --list coverage.info
+
+    # Clean up the build directories
+    rm -rf nanoarrow
+    rm -rf nanoarrow_ipc
+
+    popd
+
+    # Build + test R package
+    show_header "Build + test R package"
+    pushd "${SANDBOX_DIR}"
+    TARGET_NANOARROW_R_DIR="${TARGET_NANOARROW_DIR}/r" \
+        Rscript -e 
'saveRDS(covr::package_coverage(Sys.getenv("TARGET_NANOARROW_R_DIR"), 
relative_path = "/nanoarrow/"), "r_coverage.rds")'
+    Rscript -e 'covr:::to_codecov(readRDS("r_coverage.rds")) |> 
brio::write_file("r_coverage.json")'
+
+    show_header "R package coverage summary"
+    Rscript -e 'library(covr); print(readRDS("r_coverage.rds"))'
+    popd
+}
+
+main
diff --git a/docker-compose.yml b/docker-compose.yml
index 2bdaad2..f1e6e63 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -31,6 +31,21 @@ services:
       - ${NANOARROW_SOURCE_DIR}:/nanoarrow
     command: "/bin/bash /nanoarrow/dev/release/verify-release-candidate.sh"
 
+  coverage:
+    image: ${REPO}:ubuntu-${NANOARROW_ARCH}
+    build:
+      context: .
+      cache_from:
+        - ${REPO}:ubuntu-${NANOARROW_ARCH}
+      dockerfile: ci/docker/ubuntu.dockerfile
+      args:
+        NANOARROW_ARCH: ${NANOARROW_ARCH}
+    volumes:
+      # Don't mix the "dev tools" and "source" checkouts
+      - ./ci/scripts/coverage.sh:/coverage.sh
+      - ${NANOARROW_SOURCE_DIR}:/nanoarrow
+    command: "/bin/bash /coverage.sh /nanoarrow"
+
   docs:
     image: ${REPO}:ubuntu-${NANOARROW_ARCH}
     build:
diff --git a/extensions/nanoarrow_ipc/CMakeLists.txt 
b/extensions/nanoarrow_ipc/CMakeLists.txt
index 33640f1..c0b335c 100644
--- a/extensions/nanoarrow_ipc/CMakeLists.txt
+++ b/extensions/nanoarrow_ipc/CMakeLists.txt
@@ -229,13 +229,13 @@ if (NANOARROW_IPC_BUILD_TESTS)
 
   target_link_libraries(
     nanoarrow_ipc_decoder_test
-    nanoarrow_ipc nanoarrow ${NANOARROW_IPC_ARROW_TARGET} gtest_main)
+    nanoarrow_ipc nanoarrow ${NANOARROW_IPC_ARROW_TARGET} gtest_main 
ipc_coverage_config)
   target_link_libraries(
     nanoarrow_ipc_reader_test
-    nanoarrow_ipc nanoarrow gtest_main)
+    nanoarrow_ipc nanoarrow gtest_main ipc_coverage_config)
   target_link_libraries(
     nanoarrow_ipc_files_test
-    nanoarrow_ipc nanoarrow ${NANOARROW_IPC_ARROW_TARGET} gtest_main)
+    nanoarrow_ipc nanoarrow ${NANOARROW_IPC_ARROW_TARGET} gtest_main 
ipc_coverage_config)
 
   include(GoogleTest)
   gtest_discover_tests(nanoarrow_ipc_decoder_test)

Reply via email to