iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🛠️

Building an Xcode Project with GitHub Actions

に公開

What is this?

This is a note on how to build an Xcode project with GitHub Actions. If you are wondering "What is GitHub Actions in the first place?", please refer to the following site.

About GitHub Actions - GitHub Help

Application for Use

GitHub Actions is still in beta, and you need to apply via the URL below to use it.
It is now out of beta. You can use it immediately from the URL below.

https://github.com/features/actions

After waiting for a few days, you will receive an email from GitHub saying "It's ready to use."

Let's try building for now

The "Actions" tab has been added to the top page of the repository, so click "Set up Actions".

Screen Shot 2019-08-29 21.56.10.png

The start page will be displayed. You can run a sample workflow here, but this time click "Set up workflow yourself" in the top right.

Screen Shot 2019-08-29 21.56.54.png

The workflow editing screen will be displayed, so enter the following yml.

name: CI

on: [push] # Triggered on git push

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v1 # Checkout the source code
    - name: Select Xcode version # Use Xcode 12.4
      run: sudo xcode-select -s '/Applications/Xcode_12.4.app/Contents/Developer'
    - name: Show Xcode version
      run: xcodebuild -version
    - name: Build # Build for the simulator
      run: xcodebuild -sdk iphonesimulator -configuration Debug build 

Note: The list of available Xcode versions can be found here

Since we're at it, let's push the above content to an appropriate branch and create a pull request. You can confirm that the workflow is running in the "Checks" tab.

Screen Shot 2019-08-29 23.24.51.png

Now we have built the Xcode project!

In this way, you can also run tests or export IPAs.

The xcodebuild command is explained in detail on the following site.

Using CocoaPods or Carthage

Since CocoaPods and Carthage are already installed in the GitHub Actions virtual environment,

- name: CocoaPods
  run: pod install
- name: Carthage
  run: carthage bootstrap --platform iOS --cache-builds

you can use them like this.

Update Nov 20, 2019: Caching is now available

    - name: Cache CocoaPods files
      uses: actions/cache@preview
      with:
        path: Pods
        key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-pods-
    - name: Cache Carthage files
      uses: actions/cache@v1
      with:
        path: Carthage
        key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
        restore-keys: |
          ${{ runner.os }}-carthage-

Links

Discussion