Categories
Swift Xcode

Swift Package Manager.3

Now that we know how to create a package hosted in a git repo and use in a client project, we would like to try to set up some automated build + running our unit tests. This would prevent any wrong commits, and we could be notified automatically by the system.

For the example, I will use the Github Actions available for free

Get started with Github Actions

  • Open your github project in your browser, and select the tab Actions
  • GitHub automatically detected that we are having Swift code in our repo, so he presents us with a recommendation, which we can accept
  • Select : Setup this workflow
  • I am not going to make a tutorial about the workflow (into yml files) on git hub, but basically, we can create several workflows to automate things in gihub based on triggers. We can react to commits, pull requests, merge, on special branches ….
  • Here the workflow will work by default on the main branch. It will checkout the repo, build it and run the auto tests. Perfect for now 👌
  • You can rename the file to CI.yml and commit the file
  • Go back to the Actions tab.
  • You can see our workflow being executed (or in a queue)
  • In theory the workflow should succeed, as we don’t have much there. but when it fails, you can go inside the console of each run to check what’s wrong.
  • When something goes wrong, you will be receiving an email.
  • The good thing with this very basic action, is that you can get very quick feedback if something goes wrong. If you forgot to run the tests locally when pushing some code, github is going to do it for you.

Add a badge to your README.md

Something cool we can add in our README.me, is a little badge for each of the workflows we set up.

The syntax is very each and well documented, but it should be like this:

# FluentCoding.MediaControl

![{placeholder}](https://github.com/{username}/{projectname}/actions/workflows/{workflow.yml}/badge.svg)
  • Replace {username}, {projectname}, {workflow.yml} with your values and you are good to go.

Thank you for reading until here…  👊 Have a good week end…  🍺