From 4a4f7d482bf054db305a41a1fb9c9826e756c161 Mon Sep 17 00:00:00 2001 From: Allain Magyar Date: Wed, 13 Mar 2024 12:17:30 -0300 Subject: [PATCH] changed to shell script --- .github/workflows/build.yml | 33 ++++------------------ build_test.sh | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 28 deletions(-) create mode 100755 build_test.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1caa84e9..f0838c0e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,37 +38,14 @@ jobs: - name: Adding Known Hosts run: ssh-keyscan -H github.com >> ~/.ssh/known_hosts - - name: Build - env: - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - xcodebuild -scheme "AtalaPRISMSDK-Package" \ - -destination "platform=iOS Simulator,name=IPhone 14" \ - -derivedDataPath "~/.derivedData" \ - -enableCodeCoverage YES \ - -resultBundlePath TestResults.xcresult \ - clean build test | xcpretty - - name: Install lcov run: brew install lcov - - name: Generate lcov and aggregate - run: | - BINARIES=$(find ~/.derivedData -type f -name "*Tests") - PROF_DATA=$(find ~/.derivedData -name Coverage.profdata) - mkdir partial - for BINARY in "$BINARIES"; do - # Extract the base name of the binary without the path - BASE_NAME=$(basename "$BINARY") - OUTPUT_LCOV="${BASE_NAME}.lcov" - xcrun llvm-cov export --format=lcov \ - --ignore-filename-regex=/.derivedData/ \ - --ignore-filename-regex=/*Tests/ \ - --ignore-filename-regex=/Core/ \ - -instr-profile "$PROF_DATA" "$BINARY" > "partial/$OUTPUT_LCOV" - done - lcov -o lcov.info -a "partial/*.lcov" + - name: Build and test + env: + GITHUB_ACTOR: ${{ github.actor }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: build_test.sh - name: Publish to coveralls env: diff --git a/build_test.sh b/build_test.sh new file mode 100755 index 00000000..8abf5696 --- /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 \ + -quiet clean build test +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