iOS CI/CD workflow with GitHub Actions, tests, deployment to Appstore, Codeclimate integration

Real workflow with GitHub Actions, test coverage base from Codeclimate, Appstore deployment

This post covers:

  • Add GitHub Actions workflows to your application
  • Build and test iOS applications, showing the results of tests in a convenient way on the GitHub Actions report page
  • Sending code coverage of tests to Codeclimate, Cobertura, Slather, and Codeclimate status badges
  • Deploy to Appstore, work with the sign-in certificate, and provision file
  • Workflow example on a real project

Motivation

The free setup which Github Actions for tests, build, deployment to Appstore, and Codeclimate

GitHub Actions is a freemium service which build-in and available for any GitHub repository. It will be free for 2,000 minutes per month. Detailed billing details you can find here.

Codeclimate free tool for open-source projects and this is a great tool for finding some duplications, code smells, and other mess places in your project. Of course, Codeclimate like any static analyzer can’t understand specific composition problems or polymorphic similarities of code, but it can help you to find these places, and you can decide if this place has real problems and refactor if needed. Very useful for massive code bases. Also, Codeclimate works with code coverage info, generates code coverage status badges, and analyzes trends of your code coverage compared to production code. Codecliamte is a tool for almost all platforms, not only iOS, that’s why we need to convert (with Slather) our Xcode test report to a general code coverage report format (Cobertura) and send it to the codeclimate project. More about configuring test coverage for codeclimate. Detailed billing info you can find here.

Codeclimate, encryption, secrets

Encryption of provision and certificate files

Before workflow setup, we need to generate provision and distribution certificate for deploy workflows. This post doesn’t cover this, because it is a lot of examples over the internet. After creating and downloading Some.mobileprovision and SomeDistribution.cer files we need to encrypt them into .gpg files, and the .cer file should be converted to .p12 file before encryption. You can find examples of encrypting files in the gist file below. The encrypting process will ask you for a secret for future decryption. You need to save it in the repository secret section here as SECRET_KEY. It will be visible only to you:

Encrypted files SomeDistribution.p12.gpg and Some.mobileprovision.gpg you need to save in .github/secrets. Make sure to save encryption .gpg files, not the real certificate and provision.

Codeclimate

Sign up into the Codeclimate service and link your repository here. Copy test reporter id. Save it in GitHub secrets as CC_TEST_REPORTER_ID. It will be used for sending Cobertura test reports in the Codeclimate service.

Badges you can find here and add this markdown code to README.md in the root of the project.

Apple IDs

You need to create an app-specific password to deploy your application in Testflight from GitHub Actions. It is easy with these steps. Save your apple id and newly created specific password to Github secrets as APPLEID_PASSWORD and APPLEID_USERNAME.

Workflow files

In the code examples below, you need to change workspaces, schemes, and project names as it uses in your project. Code examples have comments in urgent places.

For adding workflow you need to create in the root of the project next folders .github/workflows/AnyName.yml. I will use the CI_iOS.yml name for my workflow. So, we need to create 3 files for 3 different workflows in .github/workflows/

Here you can control the process of your actions and see the result:

Pitfalls

  • Make sure to copy exportOptions.plist in the .github/secrets folder and change values from your project.
  • Slather needs a custom directory for derived data, make sure to use the same derivedDataPath for xcodebuild and slather commands
  • Slather crashed if you have modules without tests and put the item into the list of “Test coverage for specific targets” in scheme settings.n
  • In-App specific password creation flow make sure to copy the password, not the aliases name of the password.
  • Bundle increment does not work if your project has enabled setting with auto-generated Info.plist file. It should be turned off
  • Make sure that you have turned off the Automatic sign-in for the Release configuration which will be used for archiving in deploy workflow.
  • If your tests fail, then you can find a readable format for logs, instead of just reading logs from the script results. You can find it here and they are generated only for “CI iOS” with 3rd party script kishikawakatsumi/xcresulttool@v1. Check “CI iOS” file.

Real project with these workflows

  • I used this workflow for my personal public repo, you can find how it works together for a real project here.
  • The “CI iOS” workflow runs on each pull request to the main branch. If all tests are passed — this pull request can be merged
  • The “Main” workflow runs on any push to the main branch and runs tests, gather and send coverage of the all system to the codeclimate
  • The “Deploy” workflow runs on push to the deploy/deploy_podcast_iphone_ios branch. It will archive, export, and send the new build to the Testflight

You can ask any questions and help me to improve this guide and pitfalls section!

LinkedIn Twitter Original Blog Github HackerRank

Photo by EJ Strat on Unsplash

--

--