From 7edc968b2f63d9a7365c7444318069a799c2b3fa Mon Sep 17 00:00:00 2001 From: Allain Magyar Date: Thu, 28 Mar 2024 18:05:42 -0300 Subject: [PATCH] test: add coveralls integration (#123) --- .github/workflows/build.yml | 24 ++++++++++------ README.md | 2 ++ build_test.sh | 55 +++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 9 deletions(-) create mode 100755 build_test.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index df566414..03849a6a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ --- -name: Build +name: Build and test on: push: @@ -12,6 +12,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +env: + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 + jobs: lint: name: build @@ -34,16 +38,18 @@ jobs: - name: Adding Known Hosts run: ssh-keyscan -H github.com >> ~/.ssh/known_hosts - - name: Build + - name: Install lcov + run: brew install lcov + + - name: Build and test env: GITHUB_ACTOR: ${{ github.actor }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: xcodebuild build test -scheme "AtalaPRISMSDK-Package" -destination "platform=iOS Simulator,name=IPhone 14" -resultBundlePath TestResults + run: ./build_test.sh - - name: Publish tests results - uses: kishikawakatsumi/xcresulttool@v1.7.1 + - name: Publish to coveralls + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: coverallsapp/github-action@v2 with: - path: TestResults.xcresult - token: ${{ secrets.GITHUB_TOKEN }} - show-code-coverage: true - if: success() || failure() + file: "lcov.info" diff --git a/README.md b/README.md index 8b1f4cb9..1ec80386 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Coverage Status](https://coveralls.io/repos/github/input-output-hk/atala-prism-wallet-sdk-swift/badge.svg?branch=main)](https://coveralls.io/github/input-output-hk/atala-prism-wallet-sdk-swift?branch=main) + # Welcome to Atala PRISM Swift SDK The following will explain how to use the SDK in your project, how to prepare your development environment if you wish to contribute and some basic considerations around the project. diff --git a/build_test.sh b/build_test.sh new file mode 100755 index 00000000..fac873b1 --- /dev/null +++ b/build_test.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -e + +DERIVED_DATA_DIR="$HOME/.derivedData" +DESTINATION="platform=iOS Simulator,name=IPhone 14" +SCHEME="AtalaPRISMSDK-Package" +LCOV_DIR="$DERIVED_DATA_DIR/lcov" + +echo "Derived data directory: $DERIVED_DATA_DIR" +echo "lcov partials directory: $LCOV_DIR" + +# Clean derived data dir +echo "Cleaning derived data directory" +rm -rf "$DERIVED_DATA_DIR" +mkdir "$DERIVED_DATA_DIR" + +# Clean lcov dir +echo "Cleaning lcov partials directory" +rm -rf "$LCOV_DIR" +mkdir "$LCOV_DIR" + +# Run build and test +echo "Running build and test" +xcodebuild -scheme "AtalaPRISMSDK-Package" \ + -destination "$DESTINATION" \ + -derivedDataPath "$DERIVED_DATA_DIR" \ + -enableCodeCoverage YES \ + clean build test | xcpretty +echo "Execution completed" + +# Find profdata +PROF_DATA=$(find "$DERIVED_DATA_DIR" -name Coverage.profdata) +echo "Profdata found: $PROF_DATA" + +# Find all binaries +BINARIES=$(find ~/.derivedData -type f -name "*Tests") + +# Print all binaries found +for BINARY in $BINARIES; do + echo "Binary found: $BINARY" +done + +# Generate lcov for each target +for BINARY in $BINARIES; do + BASE_NAME=$(basename "$BINARY") + echo "Generating coverage for $BASE_NAME" + LCOV_NAME="${BASE_NAME}.lcov" + xcrun llvm-cov export --format=lcov \ + -instr-profile "$PROF_DATA" "$BINARY" > "$LCOV_DIR/$LCOV_NAME" +done + +# Merge all coverage +echo "Merging partials to lcov.info" +lcov -o lcov.info -a "$LCOV_DIR/*.lcov" --include AtalaPrismSDK/ --exclude Tests > /dev/null