Automated code coverage reporting for Swift packages
┌───────┐ ┌───────┐ ┌─────────┐
│ Setup │ ───▶ │ Tests │ ───▶ │ Analyze │
└───────┘ └───────┘ └─────────┘
│
│
▼
┌────────┐
│ Report │
└────────┘
Add this action to your workflow:
name: Coverage
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
coverage:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: Snapp-Mobile/swift-coverage-action@v1.0.1Alternatively, you can use the reusable workflow:
jobs:
coverage:
uses: Snapp-Mobile/swift-coverage-action/.github/workflows/swift-coverage.yml@mainPermissions are inherited automatically when needed.
Check out templates/ for ready-to-use examples:
minimal.yml- Simplest setupbasic.yml- Common optionsmatrix.yml- Multiple Xcode/macOS versionscombined.yml- Multi-job, single comment
All inputs are optional with sensible defaults. Choose your preferred usage method:
- uses: Snapp-Mobile/swift-coverage-action@v1.0.1
with:
# Environment
macos-version: "latest" # "latest", "15", "14", etc.
xcode-version: "16.4" # Specific version or system default
working-directory: "./my-package" # Defaults to repo root
# Project identification
project-name-override: "MyPackage" # Override project name
source-path-override: "Sources" # Override source path pattern
# PR comments
coverage-comment-header: "### 📊 Coverage"
post-comment: true # Set false for combined multi-job comments
job-name: "Config Name" # Identifier for combined reports
skip-label: "skip-coverage" # Label to skip workflow
# Quality gates
coverage-threshold: "80" # Enables ✅/⚠️ indicators
fail-on-low-coverage: false # Fail if below thresholdjobs:
coverage:
uses: Snapp-Mobile/swift-coverage-action/.github/workflows/swift-coverage.yml@main
with:
# Environment
macos-version: "latest"
xcode-version: "16.4"
working-directory: "./my-package"
# Project identification
project-name-override: "MyPackage"
source-path-override: "Sources"
# PR comments
coverage-comment-header: "### 📊 Coverage"
post-comment: true
job-name: "Config Name"
skip-label: "skip-coverage"
# Quality gates
coverage-threshold: "80"
fail-on-low-coverage: falseAdd the skip-coverage label (or custom label via skip-label input) to your PR to skip workflow execution. For example, for documentation-only changes.
Note: To re-enable the workflow after removing the label, push a new commit or close and reopen the PR. Manually re-running a skipped workflow will not work.
- Swift Package with
Package.swift - Swift Testing framework
- macOS runner (configurable, default: latest)
- Xcode (uses system default or specify version)
Basic Coverage (no threshold)
| № | Target | Lines | Coverage |
|---|---|---|---|
| 1 | CoreLibrary | 58 | 85.66% |
| 2 | NetworkLibrary | 35 | 70.00% |
| 3 | UtilsLibrary | 77 | 49.35% |
Total |
170 | 68.34% |
With Threshold - Passing (coverage-threshold: "80")
When threshold is met, header shows ✅:
| № | Target | Lines | ✅ |
|---|---|---|---|
| 1 | CoreLibrary | 58 | 92.00% |
| 2 | NetworkLibrary | 35 | 85.00% |
| 3 | UtilsLibrary | 77 | 81.00% |
Total |
170 | 86.00% |
With Threshold - Failing (coverage-threshold: "80")
When threshold is not met, header shows
| № | Target | Lines | |
|---|---|---|---|
| 1 | CoreLibrary | 58 | 85.66% |
| 2 | NetworkLibrary | 35 | 70.00% |
| 3 | UtilsLibrary | 77 | 49.35% |
Total |
170 | 68.34% |
Single Target Package
For packages with one target, no Total row is shown:
| № | Target | Lines | Coverage |
|---|---|---|---|
| 1 | MyLibrary | 45 | 73.33% |
Each job posts a uniquely identified comment that only deletes its own previous comments. Multiple jobs (e.g., matrix configurations) can post comments simultaneously without interfering with each other.
| Input | Default | Description |
|---|---|---|
macos-version |
latest |
macOS runner: latest, 15, 14 |
xcode-version |
system default | Xcode version: 16.4, 15.2 |
working-directory |
. |
Package directory |
project-name-override |
repo name | Override project name |
skip-label |
skip-coverage |
PR label to skip execution |
post-comment |
true |
Post PR comment (false for combined) |
job-name |
(empty) | Job identifier for combined reports |
coverage-comment-header |
### 🛡️ Code Coverage Report |
PR comment header |
coverage-threshold |
(empty) | Threshold % (enables ✅/ |
fail-on-low-coverage |
false |
Fail if below threshold |
Required for private repositories to post PR comments:
permissions:
contents: read
pull-requests: writecontents: read- Checkout code and read coverage datapull-requests: write- Post and update PR comments
Public repositories typically don't require explicit permission declaration (GitHub's default permissions are sufficient).
If PR comments fail with a 403 error, add the permissions block above.
See CHANGELOG.md for version history and release notes.
MIT License - see LICENSE file.