diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 311009d6..f2ebec78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: platform: [IOS, MACOS] xcode: ["16.2"] include: - - {command: test, skip_release: 1} + - { command: test, skip_release: 1 } steps: - uses: actions/checkout@v4 - name: Select Xcode ${{ matrix.xcode }} @@ -49,6 +49,19 @@ jobs: - name: Release if: matrix.skip_release != '1' run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Release PLATFORM="${{ matrix.platform }}" xcodebuild + - name: Instal lcov + if: matrix.command == 'test' && matrix.platform == 'IOS' + run: brew install lcov + - name: Export code coverage + id: coverage + if: matrix.command == 'test' && matrix.platform == 'IOS' + run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Debug PLATFORM="${{ matrix.platform }}" coverage + - uses: coverallsapp/github-action@v2.3.4 + if: steps.coverage.outcome == 'success' + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: lcov.info + xcodebuild: name: xcodebuild (15) @@ -59,13 +72,13 @@ jobs: platform: [IOS, MAC_CATALYST, MACOS, TVOS, VISIONOS, WATCHOS] xcode: [15.2, 15.4] exclude: - - {xcode: 15.2, command: test} - - {xcode: 15.2, platform: MAC_CATALYST} - - {xcode: 15.2, platform: TVOS} - - {xcode: 15.2, platform: VISIONOS} - - {xcode: 15.2, platform: WATCHOS} + - { xcode: 15.2, command: test } + - { xcode: 15.2, platform: MAC_CATALYST } + - { xcode: 15.2, platform: TVOS } + - { xcode: 15.2, platform: VISIONOS } + - { xcode: 15.2, platform: WATCHOS } include: - - {command: test, skip_release: 1} + - { command: test, skip_release: 1 } steps: - uses: actions/checkout@v4 - name: Select Xcode ${{ matrix.xcode }} diff --git a/.gitignore b/.gitignore index e4db282d..3c09847f 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,5 @@ iOSInjectionProject/ .env Secrets.swift DotEnv.swift +lcov.info +temp_coverage \ No newline at end of file diff --git a/Makefile b/Makefile index ef5c1620..6e582059 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CONFIG = Debug DERIVED_DATA_PATH = ~/.derivedData/$(CONFIG) +TEMP_COVERAGE_DIR := temp_coverage PLATFORM_IOS = iOS Simulator,id=$(call udid_for,iOS,iPhone \d\+ Pro [^M]) PLATFORM_MACOS = macOS @@ -25,7 +26,7 @@ XCODEBUILD_FLAGS = \ -destination $(DESTINATION) \ -scheme "$(SCHEME)" \ -skipMacroValidation \ - -workspace $(WORKSPACE) + -workspace $(WORKSPACE) \ XCODEBUILD_COMMAND = xcodebuild $(XCODEBUILD_ARGUMENT) $(XCODEBUILD_FLAGS) @@ -100,6 +101,10 @@ build-linux: .PHONY: build-for-library-evolution format xcodebuild test-docs test-integration +.PHONY: coverage +coverage: + @DERIVED_DATA_PATH=$(DERIVED_DATA_PATH) ./scripts/generate-coverage.sh + define udid_for $(shell xcrun simctl list devices available '$(1)' | grep '$(2)' | sort -r | head -1 | awk -F '[()]' '{ print $$(NF-3) }') endef diff --git a/README.md b/README.md index 5792f3a8..4f12c401 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # supabase-swift [![](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) [![](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) +[![Coverage Status](https://coveralls.io/repos/github/supabase/supabase-swift/badge.svg?branch=coveralls)](https://coveralls.io/github/supabase/supabase-swift?branch=coveralls) Supabase client for Swift. Mirrors the design of [supabase-js](https://github.com/supabase/supabase-js/blob/master/README.md). diff --git a/Supabase.xcworkspace/xcshareddata/xcschemes/Supabase.xcscheme b/Supabase.xcworkspace/xcshareddata/xcschemes/Supabase.xcscheme deleted file mode 100644 index 932de571..00000000 --- a/Supabase.xcworkspace/xcshareddata/xcschemes/Supabase.xcscheme +++ /dev/null @@ -1,208 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tests/IntegrationTests/RealtimeIntegrationTests.swift b/Tests/IntegrationTests/RealtimeIntegrationTests.swift index 259de27d..d153b9e1 100644 --- a/Tests/IntegrationTests/RealtimeIntegrationTests.swift +++ b/Tests/IntegrationTests/RealtimeIntegrationTests.swift @@ -29,7 +29,7 @@ final class RealtimeIntegrationTests: XCTestCase { let testClock = TestClock() let client = SupabaseClient( - supabaseURL: URL(string: DotEnv.SUPABASE_URL)!, + supabaseURL: URL(string: DotEnv.SUPABASE_URL) ?? URL(string: "http://localhost:54321")!, supabaseKey: DotEnv.SUPABASE_ANON_KEY ) diff --git a/scripts/generate-coverage.sh b/scripts/generate-coverage.sh new file mode 100755 index 00000000..53b85795 --- /dev/null +++ b/scripts/generate-coverage.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# Define variables +SCHEME="Supabase" # Replace with your Xcode scheme name +OUTPUT_FILE="lcov.info" # Output coverage file name +TEMP_COVERAGE_DIR="temp_coverage" # Temporary directory for intermediate coverage files + +# Step 2: Find the profdata file +PROFDATA_DIR="$DERIVED_DATA_PATH/Build/ProfileData" +PROFDATA_FILE=$(find "$PROFDATA_DIR" -name "*.profdata" | head -n 1) + +if [ -z "$PROFDATA_FILE" ]; then + echo "No profdata file found. Exiting." + exit 1 +fi + +echo "Found profdata file: $PROFDATA_FILE" + +# Step 3: Get all test bundles +echo "Searching for test bundles in Debug-iphonesimulator..." +TEST_BUNDLES=$(find "$DERIVED_DATA_PATH/Build/Products/Debug-iphonesimulator" -type d -name "*.xctest") + +if [ -z "$TEST_BUNDLES" ]; then + echo "No test bundles found. Ensure the tests are built successfully." + exit 1 +fi + +echo "Found test bundles:" +echo "$TEST_BUNDLES" + +# Step 4: Export coverage data for each test bundle +mkdir -p "$TEMP_COVERAGE_DIR" +for TEST_BUNDLE in $TEST_BUNDLES; do + BINARY_NAME=$(basename "$TEST_BUNDLE" .xctest) + BINARY_PATH="$TEST_BUNDLE/$BINARY_NAME" + + if [ ! -f "$BINARY_PATH" ]; then + echo "No binary found in $TEST_BUNDLE. Skipping..." + continue + fi + + echo "Exporting coverage data for binary: $BINARY_PATH" + xcrun llvm-cov export \ + -format=lcov \ + -instr-profile "$PROFDATA_FILE" \ + -ignore-filename-regex "Tests/|.build|DerivedData|.derivedData" \ + "$BINARY_PATH" > "$TEMP_COVERAGE_DIR/$BINARY_NAME.info" + + if [ $? -ne 0 ]; then + echo "Failed to export coverage for $BINARY_NAME. Skipping..." + continue + fi +done + +# Step 5: Merge coverage data into a single file +echo "Merging coverage data..." +rm -f "$OUTPUT_FILE" # Ensure the output file doesn't already exist + +for INFO_FILE in "$TEMP_COVERAGE_DIR"/*.info; do + if [ -f "$INFO_FILE" ]; then + lcov --add-tracefile "$INFO_FILE" --output-file "$OUTPUT_FILE" + if [ $? -ne 0 ]; then + echo "Failed to merge $INFO_FILE into $OUTPUT_FILE. Exiting." + exit 1 + fi + fi +done + +echo "Coverage data exported to $OUTPUT_FILE" + +# Step 6: Clean up +rm -rf "$TEMP_COVERAGE_DIR" +echo "Temporary files cleaned up." \ No newline at end of file