GitHub Actions for your Swift Package
With the release Xcode 11 is now easier than ever before to work with the Swift Package manager. If I enjoyed making CLI tools with Swift before, now it’s a pleasure! Lately I’ve been working on a small plugin for the recently released static site generator Publish. And the plugin is itself a Swift Package so I had to opportunity to enjoy SPM and Swift tooling development.
But one of the things I rarely enjoy when publishing any open source repo is the setup of the CI. Yes, nowadays is not that hard with many companies offering free resources for open source repos, but still, having to create an account, linking it with GitHub, manually creating configuration files… sometimes is too much effort for a simple and small repo.
Thankfully GitHub has been improving its platform quite a lot this past year, and one of the new features are GitHub actions. These actions allow us to create automated workflows on our repo using GH servers and fully integrated with our commits and pull requests.
The amazing thing is that adding this to your Swift package repo takes less than one minute!
Try it by yourself:
- Go to your repo’s Actions tab.
- GitHub will detect that your repo is a Swift package and it will already suggest the proper action. Just click on Set up this workflow.
The basics of this workflow should work for most projects. It builds and tests your Swift package in a macOS machine on every push to the repo.
- Commit or create a branch with the changes.
AND THAT’S IT!
From now on every push on the repo will trigger this action and report the results back to the commit.
And if the commit is part of a PR you will also see the action run as part of the PR checks.
From here you can expand your integration as you want, but it is quite amazing that in less than a minute and with 2 clicks we can have a CI integration directly into our repo.
Now you just need to write unit tests for it 😉