This repo shows how to setup and use GitHub Actions as a CI for Swift Packages

Overview

GACalc

This repo shows how to setup and use GitHub Actions as a CI for Swift Packages.

Available environments on GitHib

List of the all available environments and tools is here

Actions

Below you will find a list of actions that can be used for Swift Package Development. Simply create a new action on GitHub, and copy & paste the code.

Build package

name: Build Package

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:
    runs-on: macos-11

    steps:
    - uses: actions/checkout@v2
        
    - name: Build
      run: swift build -v

Test package

name: Test Package

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: macos-11

    steps:
    - uses: actions/checkout@v2
        
    - name: Build Package
      run: swift build -v
      
    - name: Run tests
      run: swift test -v

Test package & Gather Code Coverage using codecov.io

Replace the {YOUR_PACKAGE_NAME} with the name of your package. For example if the name of the package is gacalc, then replace the fragment {YOUR_PACKAGE_NAME}PackageTests with GacalcPackageTests.

Note: Although the name of the package is all lowercased, the replaced name starts with uppercased first letter!
You can double check the name locally. Run the `swift build` command in the Terminal. Then open the `.build` folder: `open .build`.
Inside the `.build/debug` folder you will find either `{YOUR_PACKAGE_NAME}PackageTests.product` or `{YOUR_PACKAGE_NAME}PackageTests.xctest` file.
name: Test Package

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: macos-11

    steps:
      - name: Get Sources
        uses: actions/checkout@v2

      - name: Build Package
        run: swift build -v

      - name: Run tests
        run: swift test --enable-code-coverage -v
      
      - name: Setup Xcode
        uses: maxim-lobanov/[email protected]
        with:
          xcode-version: "13.1"

      - name: Gather code coverage
        run: xcrun llvm-cov export -format="lcov" .build/debug/{YOUR_PACKAGE_NAME}PackageTests.xctest/Contents/MacOS/{YOUR_PACKAGE_NAME}PackageTests -instr-profile .build/debug/codecov/default.profdata > coverage_report.lcov

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: true
          files: ./coverage_report.lcov
          verbose: true

When this action is executed for a pull request, the codevcov bot will add a comment with a new code coverage statistics:

Code linting using SwiftLint

Linting using macOS as host machine:

name: Lint code

on:
  pull_request:
    paths:
      - '.github/workflows/codelint.yml'
      - '.swiftlint.yml'
      - '**/*.swift'

jobs:
  SwiftLint:
    runs-on: macos-11
    steps:
      - uses: actions/checkout@v1
      
      - name: Lint code using SwiftLint
        run: swiftlint lint --reporter github-actions-logging

Linting using ubuntu as host machine with a SwiftLint Github Action:

name: Lint code

on:
  pull_request:
    paths:
      - '.github/workflows/codelint.yml'
      - '.swiftlint.yml'
      - '**/*.swift'

jobs:
  SwiftLint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      
      - name: Lint code using SwiftLint
        uses: norio-nomura/[email protected]

Both options lint the code. If there are any warnings or errors they will be added, as comments, to the PR's code:

You might also like...
Enable autocomplete use resources in swift project.

ResourceKit Enable autocomplete use resources in swift project. まだハードコードで消耗してるの? ResourceKitで安全コーディング! How does ResourceKit work? ResouceKit makes you

Use this package in order to ease up working with Combine URLSession.

Use this package in order to ease up working with Combine URLSession. We support working with Codable for all main HTTP methods GET, POST, PUT and DELETE. We also support MultipartUpload

LibAuthentication will simplify your code when if you want to use FaceID/TouchID in your tweaks.

LibAuthentication will simplify your code when if you want to use FaceID/TouchID in your tweaks.

Alert popup to notify your users if they use an unsupported iOS version

UnsupportedOSVersionAlert This source code alerts your users if they use your app with an unsupported version of iOS (e.g. iOS 10.0 beta). The alert l

SwiftExtensionsPlayground - This playground includes some extensions that I like to use

This playground includes some extensions that I like to use. You can find exampl

WholesomeExtensions - A SPM package that provides some extensions that I like to use

WholesomeExtensions This package includes some extensions that I like to use. Yo

BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

A handy collection of Swift method and Tools to build project faster and more efficient.

SwifterKnife is a collection of Swift extension method and some tools that often use in develop project, with them you might build project faster and

TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.
TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.

TypeStyle TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app. Featu

Owner
Michał Tynior
My name is Michal Tynior and I am a software engineer, iOS developer, consultant, and trouble maker in general.
Michał Tynior
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
A software bill of materials (SBoM) generator for Swift packages

Swift Package SBoM A software bill of materials (SBoM) generator for Swift packages. Run this command to print a JSON representation of a CycloneDX SB

Mattt 17 Dec 12, 2022
Write Emacs packages in Swift!

EmacsSwiftModule A Swift library to write Emacs plugins in Swift! Overview Emacs Swift module provides a convenient API for writing dynamic modules fo

Valeriy Savchenko 15 Nov 29, 2022
Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Gary M 0 May 6, 2022
Zip - A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip.

Zip A Swift framework for zipping and unzipping files. Simple and quick to use. Built on top of minizip. Usage Import Zip at the top of the Swift file

Roy Marmelstein 2.3k Jan 3, 2023
Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects

SwiftyPick ?? ?? Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects. Purpose The idea behind t

Manu Herrera 19 May 12, 2022
An open source Instapaper clone that features apps and extensions that use native UI Components for Mac and iOS.

TODO: Screenshot outdated Hipstapaper - iOS and Mac Reading List App A macOS, iOS, and iPadOS app written 100% in SwiftUI. Hipstapaper is an app that

Jeffrey Bergier 51 Nov 15, 2022
🗃 Powerful and easy to use Swift Query Builder for Vapor 3.

⚠️ This lib is DEPRECATED ⚠️ please use SwifQL with Bridges Quick Intro struct PublicUser: Codable { var name: String var petName: String

iMike 145 Sep 10, 2022
SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

Gymshark 1 Jul 6, 2021
SwiftRegressor - A linear regression tool that’s flexible and easy to use

SwiftRegressor - A linear regression tool that’s flexible and easy to use

null 3 Jul 10, 2022