Setup GitHub Actions Runner on M1 Mac

Intro

I assume you have a project setup and GitHub actions working. However, you can’t seem to figure out why the self-hosted runner issn’t using the full potentional of the M1. This is where this article comes in.

Background

Over my years as a developer my interest in continous integration and continuous deployment has increased from year to year, up to a point where I would like to argue that I am rather good at setting up and maintaining a few of the well known CI services on the market. However, GitHub Actions has not been in my aresenal of tools… that is, until now.

Runners

As of the writing of this article, GitHub runners run your code on x86_64 architecture. Meaning if you setup a runner on an M1 on MacOS, it’ll use said architecutre. In order to get the runner to run on arm64, you will have to tell phases in our workflow file to do so.

This is an example of a workflow file which runs using the M1 CPU:

name: iOS test branch

on:
  push:
    branches:
      - '*'
jobs:
  setup:
    name: Setting up the project with cache and pod- & bundle install
    runs-on: m1max
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2
        with:
          clean: false
      - name: Install GEM dependencies
        run: arch -arm64 gem install bundler
      - name: Bundle install
        run: |
          cd MyProject
          arch -arm64 bundle install
      - name: Pod install
        run: |
          cd MyProject
          arch -arm64 pod install
      - name: Test project
        run: |
          cd MyProject
          arch -arm64 bundle exec fastlane ios buildAndTest

What this does is that is tells the workflow script at each step to perform an action using the arm64 architecture. The clue is using arch -arm64 when calling commands from your workflow.

If you have build using the runner already, make sure you clean your derived folder so it can make a clean build. It might sometimes also be good to clean the Pods folder (if you are using Cocoapods).