Half-2: Use M1 Mac to energy your personal iOS CI/CD pipelines
In part-1 of this sequence, we noticed creating self-hosted Microsoft Azure’s DevOps brokers utilizing apple silicon machines.
For many who are utilizing GitHub actions, on this put up, we are going to stroll by means of the method of utilizing an M1-based machine for GitHub actions self-hosted runners.
First, you’ll want to mirror the configuration of GitHub-hosted runners to keep away from any future errors. For this, create a person account named runner and this account to the admin group:
After a reboot, your new person account shall be prepared. Any longer, use this account to configure and run our self-hosted runner.
NOTE: you’ll want to set up pre-requisite instruments like git if not achieved already and in addition install Rosetta 2 on your Apple M1 machine.
You’ll be able to create a self-hosted runner at both repository degree or group degree or enterprise degree. To take action, navigate to the Settings tab at your required degree. Choose Actions from the sidebar navigation, subsequent choose the Runners choice and click on New self-hosted runner.
Whenever you do, you’ll see a view with setup instructions and instance utilization as proven above. From right here, merely open a terminal, and run the instructions so as. On operating config.sh, you may be offered following dialogue within the terminal:
Right here, select your runner group and identify or settle for the default values. You’ll be able to optionally present extra labels in your runner, the utilization of labels shall be defined later. Then, you possibly can customise the work folder or settle for the default worth
Lastly, you’ll want to configure extra surroundings variables to make sure actions work correctly in your self-hosted runner. A very powerful being
ImageOS you’ll want to present the OS identify (macos right here) and model within the format macos*model*, i.e.
maos12. And for
XCODE_*_DEVELOPER_DIR, present the trail to the Xcode developer listing for the relevant model
/Functions/Xcode_12.5.1.app/Contents/Developer. You’ll be able to add these variables within the .env file within the runner folder. In case your actions require extra surroundings variables you possibly can add them right here as properly.
With that, you possibly can lastly execute the run.sh script that shall be out there in your new runner listing.
When you’ve accomplished the setup, it’s best to see the output within the terminal that the runner is up and Listening for Jobs. You’ll be able to then navigate in your browser to your GitHub repository, click on the Settings tab, after which choose Actions after which Runners once more within the sidebar, the place it’s best to see your newly related runner with a inexperienced dot and a standing of Idle, as proven under.
Now to run actions in your self-hosted runner, you’ll want to modify your workflow file
jobs.<job_id>.runs-on property like this:
Within the array for the self-hosted runner, you possibly can present extra labels that you’ve offered throughout configuration. After committing modifications, you possibly can get pleasure from improved efficiency with self-hosting.
Many setup actions obtain instruments and retailer them within the device cache folder at /Customers/runner/hostedtoolcache. You’ll be able to handle required instruments with homebrew and use the next python script to hyperlink put in instruments to your device cache folder:
With GitHub actions, you possibly can run this script earlier than each job by offering the above script path to
ACTIONS_RUNNER_HOOK_JOB_STARTED surroundings variable within the
.env file. By doing so, you possibly can guarantee your put in instruments will at all times be out there within the device cache earlier than any job.
In case your actions require root privileges, you possibly can configure your
sudoers file by typing
sudo visudo. In case your runner is simply used for the non-public repositories (that is the default suggestion offered by GitHub because of the security of runners) you possibly can add the next line in
runner ALL=(ALL) NOPASSWD: ALL
Alternatively, you possibly can add restriction software degree, in order that these purposes received’t require a password immediate. For instance, setup-unity motion requires root privileges for
hdiutil, in that case, you possibly can add
hdiutil to no password immediate like this:
runner ALL= NOPASSWD: /bin/hdiutil
# Or your extra purposes with arguments:
runner ALL= NOPASSWD: /bin/hdiutil,/your_dir/your_bin your_args
Sadly no, though that is the fundamental setup required by most actions, some actions might require extra extra instruments to be pre-installed. Fortunately, these actions specify these necessities of their documentation.
Be at liberty to level out if I missed something and keep tuned for part-3 of this sequence, the place I’ll speak about totally different steps you possibly can take to optimize your pipeline for extra efficiency.