Skip to content

Commit 3a0201d

Browse files
committed
💻 ci: Fix code coverage issue
1 parent 274aff4 commit 3a0201d

2 files changed

Lines changed: 85 additions & 97 deletions

File tree

.github/workflows/testing.yml

Lines changed: 83 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,110 @@
1-
name: Build Status
1+
name: Build and Test
22
on:
33
push:
44
branches: [main]
55
pull_request:
66
branches: [main]
7+
78
jobs:
8-
build-and-test:
9+
test:
910
runs-on: macos-latest
1011
steps:
11-
- name: Checkout Code
12-
uses: actions/checkout@v2
13-
- name: Setup Xcode
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Select Xcode version
1416
uses: maxim-lobanov/setup-xcode@v1
1517
with:
16-
xcode-version: latest
17-
- name: Add .env file
18+
xcode-version: '15.4'
19+
20+
- name: Setup environment
1821
run: |
1922
touch .env
2023
echo "MarvelPublicKey=$MarvelPublicKey" >> .env
2124
echo "MarvelPrivateKey=$MarvelPrivateKey" >> .env
22-
- name: Install Bundler
23-
run: gem install bundler
24-
- name: Install xcpretty and coverage tools
25-
run: |
26-
gem install xcpretty
27-
gem install slather
28-
# Install xcparse for better xcresult handling
29-
brew install chargepoint/xcparse/xcparse
30-
# Install xccov-to-cobertura-xml for direct conversion
31-
npm install -g xccov-to-cobertura-xml
32-
- name: Install Gems
25+
env:
26+
MarvelPublicKey: ${{ secrets.MarvelPublicKey }}
27+
MarvelPrivateKey: ${{ secrets.MarvelPrivateKey }}
28+
29+
- name: Cache Ruby gems
30+
uses: actions/cache@v4
31+
with:
32+
path: vendor/bundle
33+
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-gems-
36+
37+
- name: Install Ruby dependencies
3338
run: |
34-
bundle install
39+
gem install bundler
40+
bundle config path vendor/bundle
41+
bundle install --jobs 4 --retry 3
3542
bundle binstubs arkana
3643
bin/arkana
37-
- name: Build & Test
44+
45+
- name: Run tests with coverage
3846
run: |
39-
xcodebuild clean build test \
47+
set -o pipefail
48+
NSUnbufferedIO=YES xcodebuild \
4049
-project SwiftyMarvel.xcodeproj \
4150
-scheme SwiftyMarvel \
42-
-destination "platform=iOS Simulator,name=iPhone 15" \
43-
-derivedDataPath ./DerivedData \
44-
-resultBundlePath ./TestResults.xcresult \
45-
CODE_SIGN_IDENTITY="" \
46-
CODE_SIGNING_REQUIRED=NO \
47-
ONLY_ACTIVE_ARCH=YES \
48-
-enableCodeCoverage YES | xcpretty
49-
- name: Debug - List coverage files
50-
run: |
51-
echo "Checking for coverage files..."
52-
find ./DerivedData -name "*.profdata" 2>/dev/null || echo "No .profdata files found in DerivedData"
53-
find ./TestResults.xcresult -name "*.xccovreport" 2>/dev/null || echo "No .xccovreport files found in TestResults"
54-
echo "TestResults.xcresult contents:"
55-
ls -la ./TestResults.xcresult/ || echo "TestResults.xcresult not found"
56-
echo "DerivedData contents:"
57-
find ./DerivedData -type d -name "*coverage*" 2>/dev/null || echo "No coverage directories found"
58-
- name: Prepare code coverage report
51+
-destination 'platform=iOS Simulator,name=iPhone 15,OS=latest' \
52+
-enableCodeCoverage YES \
53+
-derivedDataPath DerivedData \
54+
clean test | xcpretty --report junit --output junit.xml
55+
56+
- name: Generate coverage report
5957
run: |
60-
echo "Trying multiple approaches to extract coverage..."
58+
# Find the profdata file
59+
PROFDATA_FILE=$(find DerivedData -name "*.profdata" | head -n 1)
6160
62-
# Method 1: Try xcparse
63-
echo "1. Trying xcparse..."
64-
if xcparse codecov ./TestResults.xcresult coverage.xml; then
65-
echo "✅ xcparse succeeded"
66-
mv coverage.xml cobertura.xml
67-
else
68-
echo "❌ xcparse failed"
69-
70-
# Method 2: Try xccov-to-cobertura-xml
71-
echo "2. Trying xccov-to-cobertura-xml..."
72-
if xcrun xccov view --report --json ./TestResults.xcresult > coverage-report.json && \
73-
xccov-to-cobertura-xml coverage-report.json > cobertura.xml; then
74-
echo "✅ xccov-to-cobertura-xml succeeded"
75-
else
76-
echo "❌ xccov-to-cobertura-xml failed"
77-
78-
# Method 3: Extract profdata and use slather
79-
echo "3. Trying to extract profdata for slather..."
80-
find ./TestResults.xcresult -name "*.profdata" -exec cp {} ./coverage.profdata \;
81-
82-
if [ -f "./coverage.profdata" ]; then
83-
echo "Found profdata file, copying to DerivedData..."
84-
mkdir -p ./DerivedData/Build/ProfileData
85-
cp ./coverage.profdata ./DerivedData/Build/ProfileData/
86-
87-
echo "Running slather with profdata..."
88-
slather coverage \
89-
--scheme SwiftyMarvel \
90-
--configuration Debug \
91-
--build-directory ./DerivedData \
92-
SwiftyMarvel.xcodeproj
93-
else
94-
echo "❌ No profdata found, trying basic slather..."
95-
slather coverage \
96-
--scheme SwiftyMarvel \
97-
--configuration Debug \
98-
SwiftyMarvel.xcodeproj
99-
fi
100-
fi
61+
if [ -z "$PROFDATA_FILE" ]; then
62+
echo "❌ No profdata file found"
63+
exit 1
10164
fi
102-
- name: Verify coverage file
103-
run: |
104-
if [ -f "cobertura.xml" ]; then
105-
echo "✅ cobertura.xml found"
106-
head -20 cobertura.xml
107-
else
108-
echo "❌ cobertura.xml not found"
109-
ls -la *.xml || echo "No XML files found"
65+
66+
echo "✅ Found profdata: $PROFDATA_FILE"
67+
68+
# Find the test binary
69+
TEST_BINARY=$(find DerivedData -name "SwiftyMarvelTests" -type f | head -n 1)
70+
APP_BINARY=$(find DerivedData -name "SwiftyMarvel.app" -type d | head -n 1)
71+
72+
if [ -z "$TEST_BINARY" ] || [ -z "$APP_BINARY" ]; then
73+
echo "❌ Could not find test or app binaries"
74+
echo "Test binary: $TEST_BINARY"
75+
echo "App binary: $APP_BINARY"
76+
exit 1
11077
fi
111-
- name: Upload Code Coverage to Codecov
112-
uses: codecov/codecov-action@v3
78+
79+
echo "✅ Found test binary: $TEST_BINARY"
80+
echo "✅ Found app binary: $APP_BINARY"
81+
82+
# Generate coverage report using llvm-cov
83+
xcrun llvm-cov export \
84+
-format="lcov" \
85+
-instr-profile="$PROFDATA_FILE" \
86+
"$APP_BINARY/SwiftyMarvel" \
87+
-object "$TEST_BINARY" \
88+
-ignore-filename-regex=".*Tests.*" \
89+
-ignore-filename-regex=".*MockingbirdMocks.*" \
90+
-ignore-filename-regex=".*ArkanaKeys.*" \
91+
> coverage.lcov
92+
93+
echo "✅ Generated coverage.lcov"
94+
95+
- name: Upload coverage to Codecov
96+
uses: codecov/codecov-action@v4
11397
with:
11498
token: ${{ secrets.CODECOV_TOKEN }}
115-
file: ./cobertura.xml
116-
fail_ci_if_error: true
99+
file: ./coverage.lcov
100+
fail_ci_if_error: false
117101
verbose: true
102+
103+
- name: Upload test results
104+
uses: actions/upload-artifact@v4
105+
if: always()
106+
with:
107+
name: test-results
108+
path: |
109+
junit.xml
110+
coverage.lcov

.slather.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1+
# This file is kept for backward compatibility but not used
2+
# The new workflow uses llvm-cov directly
13
coverage_service: cobertura_xml
24
xcodeproj: SwiftyMarvel.xcodeproj
35
scheme: SwiftyMarvel
46
output_directory: ./
5-
build_directory: ./DerivedData
6-
ignore:
7-
- "SwiftyMarvelTests/*"
8-
- "SwiftyMarvelUITests/*"
9-
- "MockingbirdMocks/*"
10-
- "MockingbirdSupport/*"
11-
- "ArkanaKeys/*"

0 commit comments

Comments
 (0)