Skip to content

Commit 260f1a0

Browse files
committed
Migrate from Fastlane to GitHub Actions
1 parent f619d31 commit 260f1a0

File tree

12 files changed

+200
-392
lines changed

12 files changed

+200
-392
lines changed

.github/workflows/continuous_integration.yml

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

.github/workflows/test.yml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
name: Test Suite
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
test:
12+
name: Run Tests
13+
runs-on: macos-latest
14+
15+
env:
16+
IOS_SIMULATOR_DEVICE: "iPhone 16"
17+
PROJECT_NAME: "OSInAppBrowserLib" # Name used for output files
18+
SCHEME_NAME: "OSInAppBrowserLib" # Xcode scheme to build/test
19+
XCODEPROJ_PATH: "OSInAppBrowserLib.xcodeproj" # Path to .xcodeproj file
20+
COVERAGE_TARGET_FILTER: "OSInAppBrowserLib" # Target name for coverage filtering
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Install Dependencies
27+
run: |
28+
# Install SwiftLint
29+
if ! command -v swiftlint &> /dev/null; then
30+
brew install swiftlint
31+
fi
32+
33+
# Install xcbeautify for better output formatting
34+
if ! command -v xcbeautify &> /dev/null; then
35+
brew install xcbeautify
36+
fi
37+
38+
# Install slather for coverage conversion
39+
if ! gem list slather -i &> /dev/null; then
40+
gem install slather
41+
fi
42+
43+
- name: Run Unit Tests
44+
run: |
45+
mkdir -p build/reports
46+
set -o pipefail
47+
xcodebuild test \
48+
-project ${{ env.XCODEPROJ_PATH }} \
49+
-scheme ${{ env.SCHEME_NAME }} \
50+
-destination "platform=iOS Simulator,name=${{ env.IOS_SIMULATOR_DEVICE }}" \
51+
-configuration Debug \
52+
-enableCodeCoverage YES \
53+
-resultBundlePath TestResults.xcresult \
54+
SKIP_SCRIPT_PHASES=YES \
55+
CODE_SIGNING_ALLOWED=NO | xcbeautify --report junit --report-path build/reports/junit.xml
56+
57+
- name: Extract Code Coverage
58+
run: |
59+
# Extract target-specific coverage percentage
60+
coverage_percentage=$(xcrun xccov view --report TestResults.xcresult | grep "${{ env.COVERAGE_TARGET_FILTER }}" | head -1 | grep -o '[0-9]\+\.[0-9]\+%' | head -1)
61+
62+
if [ -n "$coverage_percentage" ]; then
63+
echo "✅ Code coverage (${{ env.COVERAGE_TARGET_FILTER }}): $coverage_percentage"
64+
else
65+
coverage_percentage="N/A"
66+
echo "⚠️ Could not extract coverage percentage for ${{ env.COVERAGE_TARGET_FILTER }}"
67+
fi
68+
69+
# Save coverage to environment for later use
70+
echo "COVERAGE_PERCENTAGE=$coverage_percentage" >> $GITHUB_ENV
71+
72+
- name: Generate Code Coverage Report for SonarQube
73+
run: |
74+
# Create sonar-reports directory
75+
mkdir -p sonar-reports
76+
77+
# Use Slather to convert coverage to SonarQube format
78+
if slather coverage \
79+
--sonarqube-xml \
80+
--output-directory sonar-reports \
81+
--scheme ${{ env.SCHEME_NAME }} \
82+
${{ env.XCODEPROJ_PATH }}; then
83+
84+
# Verify coverage file was generated
85+
if [ -f "sonar-reports/sonarqube-generic-coverage.xml" ]; then
86+
echo "✅ Coverage converted successfully with Slather"
87+
echo "📄 Generated: sonar-reports/sonarqube-generic-coverage.xml"
88+
else
89+
echo "⚠️ Slather succeeded but output file not found in expected location"
90+
echo "📁 Files in sonar-reports:"
91+
ls -la sonar-reports/ || echo "Directory doesn't exist"
92+
fi
93+
else
94+
echo "❌ Slather failed to generate coverage report"
95+
echo "ℹ️ SonarCloud will run without coverage data"
96+
echo "🔍 This is usually due to no test coverage or build issues"
97+
fi
98+
99+
- name: Run SwiftLint for SonarQube
100+
run: |
101+
swiftlint --reporter checkstyle > sonar-reports/${{ env.PROJECT_NAME }}-swiftlint.xml || true
102+
103+
- name: Setup SonarQube Scanner
104+
uses: warchant/setup-sonar-scanner@v8
105+
106+
- name: Send to SonarCloud
107+
id: sonarcloud
108+
continue-on-error: true
109+
run: |
110+
if [ -f "sonar-project.properties" ]; then
111+
SONAR_PROJECT_KEY=$(grep "^sonar.projectKey=" sonar-project.properties | cut -d'=' -f2)
112+
echo "🔍 Attempting to send results to SonarCloud..."
113+
echo "📋 Project Key: $SONAR_PROJECT_KEY"
114+
echo "🌿 Branch: ${{ github.ref_name }}"
115+
116+
sonar-scanner \
117+
-Dsonar.projectKey="$SONAR_PROJECT_KEY" \
118+
-Dsonar.branch.name=${{ github.ref_name }} \
119+
-Dsonar.projectVersion=${{ github.sha }}
120+
else
121+
echo "⚠️ sonar-project.properties not found, skipping SonarCloud upload"
122+
exit 0
123+
fi
124+
env:
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
127+
128+
- name: Upload Test Results
129+
uses: actions/upload-artifact@v4
130+
if: always()
131+
with:
132+
name: test-results
133+
path: |
134+
TestResults.xcresult
135+
sonar-reports/
136+
build/reports/
137+
138+
- name: Comment Test Results
139+
if: github.event_name == 'pull_request' && always()
140+
uses: actions/github-script@v7
141+
with:
142+
script: |
143+
const { execSync } = require('child_process');
144+
145+
// Get Xcode version dynamically
146+
const xcodeVersion = execSync('xcodebuild -version | head -1', { encoding: 'utf8' }).trim();
147+
148+
// Get coverage percentage from environment
149+
const coveragePercentage = process.env.COVERAGE_PERCENTAGE || 'N/A';
150+
151+
// Check if SonarCloud step succeeded by checking job status
152+
const sonarStepSucceeded = '${{ steps.sonarcloud.outcome }}' === 'success';
153+
154+
// Dynamic message based on SonarCloud success/failure
155+
const sonarMessage = sonarStepSucceeded
156+
? '☁️ **SonarCloud**: Analysis completed - [View detailed report →](https://sonarcloud.io)'
157+
: '⚠️ **SonarCloud**: Upload failed - check workflow logs for details';
158+
159+
const nextStepsMessage = sonarStepSucceeded
160+
? '📋 **Next Steps**: Review the SonarCloud analysis for code quality insights and coverage details.'
161+
: '📋 **Next Steps**: Coverage data is available in test artifacts. SonarCloud integration needs attention.';
162+
163+
await github.rest.issues.createComment({
164+
issue_number: context.issue.number,
165+
owner: context.repo.owner,
166+
repo: context.repo.repo,
167+
body: `## 🧪 Test Results
168+
169+
✅ **Tests**: All tests passed successfully!
170+
📊 **Code Coverage**: ${coveragePercentage}
171+
${sonarMessage}
172+
173+
**Environment:**
174+
- ${xcodeVersion}
175+
- iOS Simulator (${{ env.IOS_SIMULATOR_DEVICE }})
176+
- macOS runner: ${{ runner.os }}
177+
178+
${nextStepsMessage}`
179+
});

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ iOSInjectionProject/
9191

9292
# macOS
9393
.DS_Store
94+
95+
# GitHub Actions CI/CD artifacts
96+
# Generated by test workflow
97+
TestResults.xcresult/
98+
build/reports/
99+
sonar-reports/

Gemfile

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

0 commit comments

Comments
 (0)