To start with Github Action we need to have a repo and few test written to verify our build and test command. First let’s create a YML file in the directory .github/workflows
at the root of your repository.
There is a very good post on the YML file here
Let’s look into the a sample github action workflow. Below workflow will build and test a Swift Package Manager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| name: Build My Framework #1
on: #2
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs: #3
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
|
- The name of the work flow
- Define when the workflow should get triggered. here it will start either on any commit to
main
branch or on a pull request. - The actions which we want to perform in the work flow.
- First we choose the operating system which is
macos-latest
here. Other virtual environments - We define the steps or actions in form of
name and then run in next line
actions/checkout@v2
is a predefined action from github action marketplace. we can use any action from here based on our requirement.- Later in the post we have used a 3rd party action from marketplace
maxim-lobanov/setup-xcode@v1
from maxim-lobanov
.
To trigger this work flow we either push a commit to main branch or create a pull request.
Select Xcode
Select a specific version of Xcode
1
2
3
4
5
| - name: Show the currently detailed version of Xcode for CLI
run: xcode-select -p
- name: Select Xcode 12.4
run: sudo xcode-select -s /Applications/Xcode_12.4.app && xcodebuild -version
|
Select the latest Xcode available
1
2
3
| - uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
|
Select the latest beta Xcode
1
2
3
| - uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest
|
Install a specific simulator version
This process takes some time (around 15 mins) for installing the pkg
1
2
| - name: install simulator
run: xcversion simulators --install='iOS 14.3'
|
Prepare the existing simulator for use
Since github action do not load the simulator on its own we need to pre install the main iOS simulators from Xcode runtime to use for xcode build and test. Here is the discussion thread on the same. It is a workaround with symlink simulators to CoreSimulator directory.
1
2
3
4
5
6
7
| - name: Prepare iOS 14.4 simulator
run: |
sudo mkdir -p /Library/Developer/CoreSimulator/Profiles/Runtimes
sudo ln -s /Applications/Xcode_12.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 14.4.simruntime
xcrun simctl list runtimes
xcrun simctl create iPhone_8 "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-14-4"
xcrun simctl list devices 14.4
|
Install dependency (if any)
Here, we will be installing cocoapods.
1
2
3
4
5
| - name: Install Cocoapods
run: gem install cocoapods
- name: Install pods to prepare workspace
run: pod install
|
Print current Build settings
1
2
| - name: Show Build Settings
run: xcodebuild -workspace Grocery.xcworkspace -scheme Grocery -showBuildSettings
|
Print Build SDK
1
2
| - name: Show Build SDK
run: xcodebuild -workspace Grocery.xcworkspace -scheme Grocery -showsdks
|
Print available destinations for workspace/schema
1
2
| - name: Show Available Destinations
run: xcodebuild -workspace Grocery.xcworkspace -scheme Grocery -showdestinations
|
1
2
| - name: clean and build
run: xcodebuild clean build -workspace Grocery.xcworkspace -scheme Grocery -destination 'platform=iOS Simulator,OS=14.4,name=iPhone 12 mini' -showBuildTimingSummary
|
1
2
| - name: build and test
run: xcodebuild clean test -workspace Grocery.xcworkspace -scheme Grocery -destination 'platform=iOS Simulator,OS=14.4,name=iPhone 8' -showBuildTimingSummary
|
References: