The easiest way to run MagicPod tests from GitHub Actions is to use magicpod-api-client and follow these steps to run tests using a cloud device or external cloud service device.
This page describes the steps to run tests on MagicPod for an application built with Fastlane using GitHub Actions.
Table of contents
- Create an execution configuration file for Fastlane
- Create a shell script
- Create an execution configuration file for GitHub Actions
1. Create an execution configuration file for Fastlane
This time, we will use Fastlane to build an application. To use Fastlane, we will create a text file named Fastfile that contains the execution settings.
Execute the following command under the top-level folder of the repository where the source code is located.
mkdir fastlane
touch fastlane/Fastfile
Write the following in the created Fastfile. (In this case, we will build an iOS application.)
See this document for details.
default_platform(:ios)
platform :ios do
desc "Create app file". # Any lane description
lane :magicpod_create_app do # Any lane name
app_dir_path = "magicpod_created_app" # Arbitrary directory to store the created application files
build_ios_app(
scheme: "magic_pod_demo_app", # Scheme name specified in Xcode, which can be checked from "Product" > "Scheme" in Xcode
project: "magic_pod_demo_app.xcodeproj", # Project name specified in Xcode (or workspace)
configuration: "Debug",
export_method: "ad-hoc",
derived_data_path: app_dir_path,
skip_package_ipa: true,
skip_archive: true,
destination: "generic/platform=iOS Simulator"
)
# add actions here: https://docs.fastlane.tools/actions
end
end
2. Create a shell script
Create a shell script to run tests on MagicPod. Execute the following command under the top-level folder of the repository where the source code is located.
touch <Any file name(e.g. run_magicpod_test)>.sh
Write the following in the created shell script.
#!/bin/bash -e
# (Using -e, terminate processing at the line where there is a command error)
# Download and unzip the latest version of magicpod-api-client to the current directory
# For security, MAGICPOD_API_TOKEN is set using the GitHub Actions environment variables
OS=mac # Specify windows for builds on Windows machines and linux for Linux
FILENAME=magicpod-api-client # Any file name
curl -L "https://app.magicpod.com/api/v1.0/magicpod-clients/api/${OS}/latest/" -H "Authorization: Token ${MAGICPOD_API_TOKEN}" --output ${FILENAME}.zip
unzip -fq ${FILENAME}.zip
# Set the various environment variables used by MagicPod.
export MAGICPOD_ORGANIZATION=MagicPod organization name
export MAGICPOD_PROJECT=MagicPod project name
# Upload the app/ipa/apk file to MagicPod, and acquire the FILE_NO.
Path to the FILE_NO=$(./magicpod-api-client upload-app -a app)
# Run batch tests using the app just uploaded and the setting number settings
./magicpod-api-client batch-run -S setting number -s "{\"app_file_number\":\"${FILE_NO}\"}"
# If the test is successful, delete the uploaded app (optional)
if [ $? = 0 ]; then
./magicpod-api-client delete-app -a ${FILE_NO}
fi
For security, MAGICPOD_API_TOKEN is set in a GitHub environment variable.
Go to https://github.com/<repository>/settings/secrets/actions.
Click New repository secret, input a variable name like MAGICPOD_API_TOKEN in Name and copy and paste MagicPod API token in Secret.
3. Create an execution configuration file for GitHub Actions
If the .github/workflows directory does not yet exist under the top-level folder of the repository containing the source code, create it by executing the following command.
mkdir -p .github/workflows
Create a file named <any file name>.yml under that the .github/workflows directory.
touch .github/workflows/<Any file name(e.g. magicpod_test)>.yml
Write the following in the created yml file.
# Execute this workflow when you push
on: [push]
jobs:
# job name(Any job name)
magic_pod_job:
# Specify virtual machine format
runs-on: macos-latest # Specify mac this time
# Steps in the job
steps:
# Step1(Checkout)
- name: Checkout
uses: actions/checkout@v3 # Specify the latest version of actions
# Step2(Install Ruby)
- name: Set up ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1.2
# Step3(Install Fastlane)
- name: Install Fastlane
run: gem install fastlane
# Step4(Install brew)
- name: Setup brew
run: echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
# Step5(Select Xcode 13.2.1)
- name: Select Xcode version
run: sudo xcode-select -s '/Applications/Xcode_13.2.1.app/Contents/Developer'
# Step6(Output the Xcode version)
- name: Show Xcode version
run: xcodebuild -version
# Step7(Create app)
- name: Create app
run: fastlane magicpod_create_app # Lane name specified in Fastfile
# Step8(Upload the created app to MagicPod for batch run)
- name: Batch run test
env:
MAGICPOD_API_TOKEN: ${{ secrets.MAGICPOD_API_TOKEN }} # Variable name set in GitHub
run: bash run_magicpod_test.sh # Shell script created earlier
In this case, the version of Fastlane to be installed is not fixed, so if you want to fix it, use Bundler.
If you want to use Bundler, please refer to this page.
4. Confirmation of operation
Push all of the following files to the repository where the source code is located, and you will see that the app built with Fastlane is being tested and run tests with MagicPod in the Actions tab in GitHub.
- Text file named Fastfile created in 1
- Shell script to run tests with MagicPod created in 2
- YML file created in 3