Carregando...

GitHubActions for Swift projects

13 de September de 2019

 

The long awaited action-based GitHub CI and CD arrived, today I received my invite and went running to test.
To join the waiting list, sign up for this GitHub Actions link. When you receive your invite your account and all your repositories receive the Actions button as below:
 

 
Well, let's go! My example follows a very simple structure: To run a Swift project build, I will base the script on one of my open projects, MLTontiatorView.
 
Accessing this tab you will see a GetStarted with workflow suggestions to have a base from where to start. Unfortunately there is no popular for workflow Swift yet, so you will see a button with blue text Set up a workflow yourself. Click on it and you will enter a standard GitHub edit screen as below:
 

 
You can clear the content and based on this code that I will add here:
 

on:
  push:
    branches:    
      - develop
name: Build
jobs:
  test:
    name: Build
    runs-on: macOS-latest
    strategy:
        matrix:
          destination: ['platform=iOS Simulator,OS=12.2,name=iPhone X']
    steps:
      - name: Checkout
        uses: actions/checkout@master
      - name: Build
        run: |
          xcodebuild clean build -project MLTontiatorView.xcodeproj -scheme MLTontiatorView-iOS -destination "${destination}" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ONLY_ACTIVE_ARCH=NO
        env: 
         destination: ${{ matrix.destination }}
 
You must replace the parts:
  • branches> develop for the branch you want to workflow on
  • - project to your project's xcodeproj file
  • -scheme for Target in this case ios's gave project
The strategy matrix is very simple, it is an array of platforms that your project will execute. Soon I will make a new post with other examples of modules that run on other platforms, such as tvOS. The goal here is to make you run a build on your project via Actions.
Once the edit is done, the Start commit button can be clicked, add the comment regarding this change and wait for the action to start the process.
 
NOTE: I am changing the filename from main.yml to Build.yml to separate workflows. In this case, you can create a new file such as Tests.yml and configure the workflow to run your tests.
When you get back to the Actions tab you will see a screen like this:

 

In the Edit workflow button you edit your Build.yml file.
By clicking on develop, you get to the screen with the jobs running in your workflow with time and information whether they succeeded or not.
 

 
That's it people, good Actions!
Ah a detail: In your local repository check out the branch where you created the yml. You can edit it locally as workflow files are stored in the
.github / workflows / folder
I recommend running the xcodebuild command in your project folder to verify that the build is running and testing the command before running in Action, as some configuration may be different in your project.
In my opinion, the process of setting up and running the workflow is very fast. The free versions have an attractive runtime for small projects, but as they are still in beta, some issues may occur. Until the publication of this post I could not run a simple Command Line project and its tests. I will work a little on it and I will post news again.
Thanks for reading guys!
 
Some useful links:
 

 

Desenvolvido por Michel Lütz