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

Overview

SwiftPackageWithGithubActionsAsCI

This repo shows how to set up 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 & upload report to 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.
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 ">
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:

Test package, gather code coverage & upload report to Code Climate

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: Test & publish code coverage to Code Climate
        uses: paambaati/[email protected]
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_TOKEN }}
        with:
          coverageCommand: swift test --enable-code-coverage
          debug: true
          coverageLocations: |
            ${{github.workspace}}/.build/debug/codecov/*.json:lcov-json

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...
A Swift implementation of a Flickr-search application that uses MVVM and ReactiveCocoa
A Swift implementation of a Flickr-search application that uses MVVM and ReactiveCocoa

ReactiveCocoa, Swift and MVVM This application is a Swift-port of an MVVM / ReactiveCocoa example application I wrote a few months ago. Instructions T

Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure / Block
Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure / Block

Swift-CAAnimation-Closure Swift extension which adds start, animating and completion closures for CAAnimation objects. Aka, CAAnimation + Closure or C

SignalKit is a reactive Swift framework with focus on clean and readable API.
SignalKit is a reactive Swift framework with focus on clean and readable API.

Abstract SignalKit is a lightweight event and binding framework. The core of SignalKit is the Observable protocol. Each implementation of the Observab

👨‍💻Watch the latest and greatest conference videos on your Mac
👨‍💻Watch the latest and greatest conference videos on your Mac

Conferences.digital is the best way to watch the latest and greatest videos from your favourite developer conferences for free on your Mac. Either sea

A package to help track how often the user opened the app and if they opened it in the current version before.

AppOpenTracker AppOpenTracker provides an observable AppOpenTracker.shared instance that can be used to track the last version that the app was opened

Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.
Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.

SwiftUI-LazyVGrid Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets. Screenshots Samples IP & Credits All those b

This little app aims to help teach me how to implement more then one API in one single application in a reusable and properly structured manner.

LilAPI App News & Weather This little API app combines two of Jordan Singers Lil Software API's into one app. The goal with this app was to learn how

A simple solution to decrease build time and more cleaner codebase

Swift Optional Optimizer A simple Protocol Oriented solution to decrease build time and more cleaner code base. Are you tired of using ?? in your code

SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM
SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM

Jibble SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM Demo Features Reactive Bindings URL / JSON Parameter Encoding Filter Y

Owner
Michał Tynior
My name is Michal Tynior and I am a software engineer, iOS developer, consultant, and trouble maker in general.
Michał Tynior
This repository shows how handle Rest API's in SwiftUI and Combine

SwiftUI-Combine-Networking This repository shows how handle Rest API's in SwiftUI and Combine Endpoints enum includes paths which will be added the en

Abdullah Kardaş 5 Jan 1, 2023
This is Github user search demo app which made by many variety of design patterns.

iOSDesignPatternSamples This is Github user search demo app which made by many variety of design patterns. Application Structure SearchViewController.

Taiki Suzuki 679 Dec 11, 2022
An iOS app for GitHub with exploring trending

GiTiny is iOS app for GitHub with exploring trending. Written in RxSwift and MVVM-C architecture. Features ?? Explore Trending Repositories and Develo

DongHee Kang 263 Dec 26, 2022
Jared Watson 0 Jan 8, 2022
A demo demonstrates how to use combine and MVVM in the SwiftUI app

SwiftUI-MVVM-Combine A demo demonstrates how to use combine and MVVM in the Swif

Asa. Ga 7 Jul 5, 2022
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Koussaïla BEN MAMAR 2 Dec 31, 2021
SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

SwiftLint - A tool to enforce Swift style and conventions, loosely based on Swift Style Guide.

Realm 16.9k Dec 30, 2022
Sweet-swift - Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper Functions and Common Utilities

Sweet Swift Make Swift Sweet by Gracefully Introducing Syntactic Sugar, Helper F

Yanzhan Yang 2 Feb 6, 2022
Explanations and samples about the Swift programming language

About Swift Contents Explanations and samples about: Swift Programming Language Swift Standard Library Target audience Developers familiar with object

Nicola Lancellotti - About 74 Dec 29, 2022
A Swift package that adds some handy functions to String and NSMutableAttributedString

StringBooster StringBooster is a simple Swift package containing a few useful ex

B.T. Franklin 0 Dec 31, 2022