Skip to content

Snapp-Mobile/swift-coverage-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Swift Coverage Action

Release License: MIT SPM Platform

macOS Xcode

What It Does

Automated code coverage reporting for Swift packages

┌───────┐      ┌───────┐      ┌─────────┐
│ Setup │ ───▶ │ Tests │ ───▶ │ Analyze │
└───────┘      └───────┘      └─────────┘
                                    │
                                    │
                                    ▼
                              ┌────────┐
                              │ Report │
                              └────────┘
Example PR comment

Quick Start

As a GitHub Marketplace Action

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.1

As a Reusable Workflow

Alternatively, you can use the reusable workflow:

jobs:
  coverage:
    uses: Snapp-Mobile/swift-coverage-action/.github/workflows/swift-coverage.yml@main

Permissions are inherited automatically when needed.

Templates

Check out templates/ for ready-to-use examples:

Configuration

All inputs are optional with sensible defaults. Choose your preferred usage method:

As GitHub Marketplace Action

- 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 threshold

As Reusable Workflow

jobs:
  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: false

Skipping Workflow

Add 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.

Requirements

  • Swift Package with Package.swift
  • Swift Testing framework
  • macOS runner (configurable, default: latest)
  • Xcode (uses system default or specify version)

Output Examples

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%
Details

Threshold - 80%

  • ⚠️ below
  • ✅ meets
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%
Details

Threshold - 80%

  • ⚠️ below
  • ✅ meets
Single Target Package

For packages with one target, no Total row is shown:

Target Lines Coverage
1 MyLibrary 45 73.33%

PR Comment Management

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.

All Inputs

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

Permissions

Required for private repositories to post PR comments:

permissions:
  contents: read
  pull-requests: write
  • contents: read - Checkout code and read coverage data
  • pull-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.

Changelog

See CHANGELOG.md for version history and release notes.

License

MIT License - see LICENSE file.

About

A reusable GitHub Actions workflow for generating Swift test coverage reports with PR comments.

Topics

Resources

License

Stars

Watchers

Forks