Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(coverage): add script to run test with coverage report #84

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,30 @@ jobs:
build:
runs-on: macos-14

strategy:
matrix:
xcode:
- '16.0'
env:
DEVELOPER_DIR: /Applications/Xcode_16.0.app/Contents/Developer

name: Build

steps:
- name: checkout
uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: .build
key: ${{ runner.os }}-xcode-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
key: ${{ runner.os }}-xcode-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-xcode-${{ matrix.xcode }}
${{ runner.os }}-xcode-

- name: build
run: |
ls -n /Applications/ | grep Xcode*
make build
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer

- name: test
run: |
swift test
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer
./scripts/code-coverage.sh

create_release:
needs:
Expand Down Expand Up @@ -116,6 +113,7 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Update homebrew formula
run: |
git config user.name github-actions[bot]
Expand Down
31 changes: 31 additions & 0 deletions scripts/code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -e

cwd=`pwd`
script_folder=`cd $(dirname $0) && pwd`
build_folder=$script_folder/../.build
output_folder=$script_folder/../.output

mkdir -p $output_folder

swift test --enable-code-coverage

# if in the CI environment, then use llvm-cov report instead
if [ -n "$CI" ]; then
xcrun llvm-cov report \
--ignore-filename-regex='(.build|Tests)[/\\].*' \
-instr-profile "$(swift test --show-codecov-path | xargs dirname)/default.profdata" \
.build/debug/sendkeysPackageTests.xctest/Contents/*/sendkeysPackageTests
exit 0
fi

xcrun llvm-cov export \
--format=lcov \
--ignore-filename-regex='(.build|Tests)[/\\].*' \
-instr-profile "$(swift test --show-codecov-path | xargs dirname)/default.profdata" \
.build/debug/sendkeysPackageTests.xctest/Contents/*/sendkeysPackageTests > "$output_folder/coverage.lcov"

genhtml -o "$output_folder/coverage" "$output_folder/coverage.lcov"

open "file://$output_folder/coverage/index.html"