Swift All-Stars: a GitHub Action for CI with auto-corrections support

I have released a new GitHub Action for Swift CI: Swift All-Stars. It covers unit-testing, linting, and committing of auto-corrections where needed.

The name Swift All-Stars was chosen to reflect that it is mainly build on top of two existing GitHub Actions for Swift. My own contribution of automatically committing/pushing code-changes back into the repo would not have been possible without the prior work of @slashmo and @norio_nomura.

Workflow Description

My workflow leverages two GitHub Actions:

"install-swift" is being used as a replacement for GitHub's default Swift CI action. Unfortunately, the default Swift CI action on GitHub is a bit behind of Swift's release cycle. With "install-swift", it is not only possible to use the latest Swift release, but you can also set-up a testing matrix that covers older Swift releases too. "install-swift" runs only on Ubuntu so far, but this is actually needed for the next action that I use: "action-swiftlint".

"action-swiftlint" is an action that provides SwiftLint, which is a linter that has been inspired by community rules as described in detailed write-ups such as Ray Wenderlich's Swift Style Guide. Most importantly though, SwiftLint features a --fix option for rewriting source code in-place with auto-corrections.

My GitHub Action works as follows:

  1. Build & unit-testing

    • installs Swift (you can use a matrix here)
    • builds your application
    • runs unit-tests
  2. Linting & auto-correct

    • runs an auto-correct on your code
    • checks for linter errors
    • if auto-correct made changes
      • extracts the issue number of the original commit (may be empty)
      • commits the changes and includes the issue number (so changes are tracked by the original GitHub issue-history)

The auto-correct/commit is my own contribution: if team members push ill-formatted code, then this is being corrected by Swift All-Stars directly on GitHub. This takes away the burden of double-checking for formatting specifics by developers, which in turn means that they can spend more time on actual development.

SwiftLint Configuration

Your code is most likely not going to pass SwiftLint's scrutiny. To configure coding-style exceptions, create a file .swiftlint.yml in your repo with settings as described here.

Continued Support & Further Plans

As with all open-source contributions, there is always the question of how long a project will be supported before it is being abandoned. I do need Swift All-Stars for my own work, so there is a strong incentive from my side to keep Swift All-Stars up-to-date.

However, there is a risk that action-swiftlint with it's dependency to SwiftLint will become a problem eventually. The latter has not been updated for a while.

I would have liked to automatically generate DocC documentation and commit/push that too, but it seems that the docc command is inherently interactive on the command-line as of this writing. If I am wrong on this, then I would be eager to hear how docc can be invoked as a standalone command that will just generate the HTML files and then quit.

Final Words

While I needed a better CI solution for Swift for my own projects, this work was primarily motivated by the GitHub Actions Hackathon 2021. My submission for the hackathon mirrors this write-up here.

1 Like
Terms of Service

Privacy Policy

Cookie Policy