Skip to content

Commit 6b0a0ea

Browse files
authored
ci: upload coverage to coveralls (#642)
* ci: upload coverage to coveralls * add missing make dot-env * merge profraw files and use coveralls ci action * fix unwrapping nil value in ci * add generate-coverage.sh script for merging and exporting coverage files * install lcov * ignore .derivedData * config coveralls action * remove coverage.info * add coverage badge
1 parent d1c308a commit 6b0a0ea

File tree

7 files changed

+103
-217
lines changed

7 files changed

+103
-217
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
platform: [IOS, MACOS]
2424
xcode: ["16.2"]
2525
include:
26-
- {command: test, skip_release: 1}
26+
- { command: test, skip_release: 1 }
2727
steps:
2828
- uses: actions/checkout@v4
2929
- name: Select Xcode ${{ matrix.xcode }}
@@ -49,6 +49,19 @@ jobs:
4949
- name: Release
5050
if: matrix.skip_release != '1'
5151
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Release PLATFORM="${{ matrix.platform }}" xcodebuild
52+
- name: Instal lcov
53+
if: matrix.command == 'test' && matrix.platform == 'IOS'
54+
run: brew install lcov
55+
- name: Export code coverage
56+
id: coverage
57+
if: matrix.command == 'test' && matrix.platform == 'IOS'
58+
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Debug PLATFORM="${{ matrix.platform }}" coverage
59+
- uses: coverallsapp/[email protected]
60+
if: steps.coverage.outcome == 'success'
61+
with:
62+
github-token: ${{ secrets.GITHUB_TOKEN }}
63+
file: lcov.info
64+
5265

5366
xcodebuild:
5467
name: xcodebuild (15)
@@ -59,13 +72,13 @@ jobs:
5972
platform: [IOS, MAC_CATALYST, MACOS, TVOS, VISIONOS, WATCHOS]
6073
xcode: [15.2, 15.4]
6174
exclude:
62-
- {xcode: 15.2, command: test}
63-
- {xcode: 15.2, platform: MAC_CATALYST}
64-
- {xcode: 15.2, platform: TVOS}
65-
- {xcode: 15.2, platform: VISIONOS}
66-
- {xcode: 15.2, platform: WATCHOS}
75+
- { xcode: 15.2, command: test }
76+
- { xcode: 15.2, platform: MAC_CATALYST }
77+
- { xcode: 15.2, platform: TVOS }
78+
- { xcode: 15.2, platform: VISIONOS }
79+
- { xcode: 15.2, platform: WATCHOS }
6780
include:
68-
- {command: test, skip_release: 1}
81+
- { command: test, skip_release: 1 }
6982
steps:
7083
- uses: actions/checkout@v4
7184
- name: Select Xcode ${{ matrix.xcode }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@ iOSInjectionProject/
100100
.env
101101
Secrets.swift
102102
DotEnv.swift
103+
lcov.info
104+
temp_coverage

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CONFIG = Debug
22

33
DERIVED_DATA_PATH = ~/.derivedData/$(CONFIG)
4+
TEMP_COVERAGE_DIR := temp_coverage
45

56
PLATFORM_IOS = iOS Simulator,id=$(call udid_for,iOS,iPhone \d\+ Pro [^M])
67
PLATFORM_MACOS = macOS
@@ -25,7 +26,7 @@ XCODEBUILD_FLAGS = \
2526
-destination $(DESTINATION) \
2627
-scheme "$(SCHEME)" \
2728
-skipMacroValidation \
28-
-workspace $(WORKSPACE)
29+
-workspace $(WORKSPACE) \
2930

3031
XCODEBUILD_COMMAND = xcodebuild $(XCODEBUILD_ARGUMENT) $(XCODEBUILD_FLAGS)
3132

@@ -100,6 +101,10 @@ build-linux:
100101

101102
.PHONY: build-for-library-evolution format xcodebuild test-docs test-integration
102103

104+
.PHONY: coverage
105+
coverage:
106+
@DERIVED_DATA_PATH=$(DERIVED_DATA_PATH) ./scripts/generate-coverage.sh
107+
103108
define udid_for
104109
$(shell xcrun simctl list devices available '$(1)' | grep '$(2)' | sort -r | head -1 | awk -F '[()]' '{ print $$(NF-3) }')
105110
endef

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# supabase-swift
22
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsupabase%2Fsupabase-swift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/supabase/supabase-swift)
33
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fsupabase%2Fsupabase-swift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/supabase/supabase-swift)
4+
[![Coverage Status](https://coveralls.io/repos/github/supabase/supabase-swift/badge.svg?branch=coveralls)](https://coveralls.io/github/supabase/supabase-swift?branch=coveralls)
45

56
Supabase client for Swift. Mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md).
67

Supabase.xcworkspace/xcshareddata/xcschemes/Supabase.xcscheme

Lines changed: 0 additions & 208 deletions
This file was deleted.

Tests/IntegrationTests/RealtimeIntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class RealtimeIntegrationTests: XCTestCase {
2929
let testClock = TestClock<Duration>()
3030

3131
let client = SupabaseClient(
32-
supabaseURL: URL(string: DotEnv.SUPABASE_URL)!,
32+
supabaseURL: URL(string: DotEnv.SUPABASE_URL) ?? URL(string: "http://localhost:54321")!,
3333
supabaseKey: DotEnv.SUPABASE_ANON_KEY
3434
)
3535

scripts/generate-coverage.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# Define variables
4+
SCHEME="Supabase" # Replace with your Xcode scheme name
5+
OUTPUT_FILE="lcov.info" # Output coverage file name
6+
TEMP_COVERAGE_DIR="temp_coverage" # Temporary directory for intermediate coverage files
7+
8+
# Step 2: Find the profdata file
9+
PROFDATA_DIR="$DERIVED_DATA_PATH/Build/ProfileData"
10+
PROFDATA_FILE=$(find "$PROFDATA_DIR" -name "*.profdata" | head -n 1)
11+
12+
if [ -z "$PROFDATA_FILE" ]; then
13+
echo "No profdata file found. Exiting."
14+
exit 1
15+
fi
16+
17+
echo "Found profdata file: $PROFDATA_FILE"
18+
19+
# Step 3: Get all test bundles
20+
echo "Searching for test bundles in Debug-iphonesimulator..."
21+
TEST_BUNDLES=$(find "$DERIVED_DATA_PATH/Build/Products/Debug-iphonesimulator" -type d -name "*.xctest")
22+
23+
if [ -z "$TEST_BUNDLES" ]; then
24+
echo "No test bundles found. Ensure the tests are built successfully."
25+
exit 1
26+
fi
27+
28+
echo "Found test bundles:"
29+
echo "$TEST_BUNDLES"
30+
31+
# Step 4: Export coverage data for each test bundle
32+
mkdir -p "$TEMP_COVERAGE_DIR"
33+
for TEST_BUNDLE in $TEST_BUNDLES; do
34+
BINARY_NAME=$(basename "$TEST_BUNDLE" .xctest)
35+
BINARY_PATH="$TEST_BUNDLE/$BINARY_NAME"
36+
37+
if [ ! -f "$BINARY_PATH" ]; then
38+
echo "No binary found in $TEST_BUNDLE. Skipping..."
39+
continue
40+
fi
41+
42+
echo "Exporting coverage data for binary: $BINARY_PATH"
43+
xcrun llvm-cov export \
44+
-format=lcov \
45+
-instr-profile "$PROFDATA_FILE" \
46+
-ignore-filename-regex "Tests/|.build|DerivedData|.derivedData" \
47+
"$BINARY_PATH" > "$TEMP_COVERAGE_DIR/$BINARY_NAME.info"
48+
49+
if [ $? -ne 0 ]; then
50+
echo "Failed to export coverage for $BINARY_NAME. Skipping..."
51+
continue
52+
fi
53+
done
54+
55+
# Step 5: Merge coverage data into a single file
56+
echo "Merging coverage data..."
57+
rm -f "$OUTPUT_FILE" # Ensure the output file doesn't already exist
58+
59+
for INFO_FILE in "$TEMP_COVERAGE_DIR"/*.info; do
60+
if [ -f "$INFO_FILE" ]; then
61+
lcov --add-tracefile "$INFO_FILE" --output-file "$OUTPUT_FILE"
62+
if [ $? -ne 0 ]; then
63+
echo "Failed to merge $INFO_FILE into $OUTPUT_FILE. Exiting."
64+
exit 1
65+
fi
66+
fi
67+
done
68+
69+
echo "Coverage data exported to $OUTPUT_FILE"
70+
71+
# Step 6: Clean up
72+
rm -rf "$TEMP_COVERAGE_DIR"
73+
echo "Temporary files cleaned up."

0 commit comments

Comments
 (0)