Commit 53cdf885 authored by Gabriel Le Breton's avatar Gabriel Le Breton

Merge branch 'feature/ios-with-fastlane' into 'master'

Feature/ios with fastlane

See merge request !32
parents a93011c0 6fbf582a
Pipeline #119980322 passed with stages
in 45 minutes and 3 seconds
......@@ -100,6 +100,23 @@ build-android:
variables:
BUILD_TARGET: Android
build-ios-xcode:
<<: *build
image: gableroux/unity3d:2019.2.11f1-ios
variables:
BUILD_TARGET: iOS
#build-and-deploy-ios:
# stage: deploy
# script:
# - cd ./Builds/iOS/$BUILD_NAME
# - pod install
# - fastlane ios beta
# tags:
# - ios
# - mac
# needs: ["build-ios-xcode"]
pages:
image: alpine:latest
stage: deploy
......
using UnityEditor.Callbacks;
using UnityEditor;
using System.IO;
using UnityEngine;
using System;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
using System;
public static class BuildPostProcess
{
private const string PLIST_FILE = "Info.plist";
private const string EXIST_ON_SUSPEND_KEY = "UIApplicationExitsOnSuspend";
private const string VERSIONING_SYSTEM_KEY = "VERSIONING_SYSTEM";
private const string CURRENT_PROJECT_VERSION_KEY = "CURRENT_PROJECT_VERSION";
private const string APPLE_GENERIC_VALUE = "apple-generic";
private const string ENABLE_BITCODE_KEY = "ENABLE_BITCODE";
private const string CODE_SIGN_STYLE_KEY = "CODE_SIGN_STYLE";
private const string PROVISIONING_PROFILE_SPECIFIER_KEY = "PROVISIONING_PROFILE_SPECIFIER";
private const string PROVISIONING_PROFILE_KEY = "PROVISIONING_PROFILE";
[PostProcessBuild(1)]
public static void IOSBuildPostProcess(BuildTarget target, string pathToBuiltProject)
{
RemoveDeprecatedInfoPListKeys(pathToBuiltProject);
string projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
var pbxProject = new PBXProject();
pbxProject.ReadFromFile(projectPath);
string guidProject = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
Debug.Log("Setting Versioning system to Apple Generic...");
pbxProject.SetBuildProperty(guidProject, VERSIONING_SYSTEM_KEY, APPLE_GENERIC_VALUE);
pbxProject.SetBuildProperty(guidProject, CURRENT_PROJECT_VERSION_KEY, "1");
Debug.Log("Disabling bitcode...");
pbxProject.SetBuildProperty(guidProject, ENABLE_BITCODE_KEY, "NO");
Debug.Log("Setting Code sign style to manual and setup provisioning profile specifier...");
pbxProject.SetBuildProperty(guidProject, CODE_SIGN_STYLE_KEY, "Manual");
pbxProject.SetBuildProperty(guidProject, PROVISIONING_PROFILE_SPECIFIER_KEY, pbxProject.GetBuildPropertyForAnyConfig(guidProject, PROVISIONING_PROFILE_KEY));
pbxProject.WriteToFile(projectPath);
}
private static void RemoveDeprecatedInfoPListKeys(string pathToBuiltProject)
{
string plistPath = Path.Combine(pathToBuiltProject, PLIST_FILE);
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
PlistElementDict rootDict = plist.root;
if (rootDict.values.ContainsKey(EXIST_ON_SUSPEND_KEY))
{
Debug.LogFormat("Removing deprecated key \"{0}\" on \"{1}\" file", EXIST_ON_SUSPEND_KEY, PLIST_FILE);
rootDict.values.Remove(EXIST_ON_SUSPEND_KEY);
}
File.WriteAllText(plistPath, plist.WriteToString());
}
}
#endif
fileFormatVersion: 2
guid: 8d3ff88a611f9254f99748f710a6a2ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -37,6 +37,15 @@ This repository is hosted on multiple remotes to provide examples for [Gitlab-CI
- [How to add build targets](#how-to-add-build-targets)
- [gitlab-ci](#gitlab-ci-1)
- [iOS support](#ios-support)
- [Setup (only one time per mac)](#setup-only-one-time-per-mac)
- [Unity Settings](#unity-settings)
- [XCode project](#xcode-project)
- [App on portail](#app-on-portail)
- [Fastlane initialization](#fastlane-initialization)
- [Provisioning profile](#provisioning-profile)
- [Make lane](#make-lane)
- [Run tests locally](#run-tests-locally)
- [Gitlab-runner - register your mac](#gitlab-runner-register-your-mac)
- [Android support](#android-support)
- [How to run scripts manually](#how-to-run-scripts-manually)
- [Test](#test)
......@@ -90,7 +99,7 @@ You need to have one of these files in your project in order to build your proje
Note: you can add BuildOptions per target by adding environment variable `BuildOptions`.
```
```yaml
build-ios:
<<: *build
image: gableroux/unity3d:2019.2.11f1-android
......@@ -100,7 +109,8 @@ build-ios:
```
If you would like to use several BuildOptions, you have to separate all values by `,` :
```
``` yaml
BuildOptions: AcceptExternalModificationsToPlayer,CompressTextures,ConnectToHost
```
......@@ -159,11 +169,12 @@ All you need is [docker](https://www.docker.com/) installed on your machine.
If your password contains a `!`, you can escape it like this (`example_pass!word`):
```bash
...
-e "UNITY_PASSWORD=example_pass"'!'"word" \
...
```
```bash
...
-e "UNITY_PASSWORD=example_pass"'!'"word" \
...
```
3. In Unity docker container's bash, run once like this, it will try to activate
```bash
......@@ -266,7 +277,140 @@ build-StandaloneWindows64:
### iOS support
**Help wanted!** See [#16](https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/16)
#### Setup (only one time per mac)
Install the latest Xcode command line tools :
```bash
xcode-select --install
```
Install fastlane using:
```bash
# Using RubyGems
sudo gem install fastlane -NV
# Alternatively using Homebrew
brew install fastlane
```
#### Unity Settings
1. Switch target to iOS
1. In `PlayerSettings -> Other Settings`
1. Fill the field `Signing Team ID`
1. Ensure `Automatically Sign` is unchecked
1. iOS Provisioning Profile
1. `ProfileID`: `match AppStore your_bundle_identifier` _Replace `your_bundle_identifier` by yours_
1. `ProfileType`: `Distribution`
#### XCode project
Make a first iOS build using your mac from Unity, that will create an xcode project.
Ensure your target the same path than the ci.
Ex: if you let `BUILD_NAME: ExampleProjectName` in `.gitlab-ci.yml`, your xcode project must be at the root of the following path: `.\Builds\iOS\ExampleProjectName\`
#### App on portail
Make sure that you have setup your app on the Apple Developer Portal and the App Store Connect or use [fastlane produce](https://docs.fastlane.tools/actions/produce/) to create it.
#### Fastlane initialization
Open the terminal at the same path then run `fastlane init`, follow instructions to generate Appfile and default Fastfile.
#### Provisioning profile
Run `fastlane match init`, follow instructions, select `appstore` provisioning profile type. ([Documentation](https://docs.fastlane.tools/actions/match/))
#### Make lane
Copy the following instructions on your `fastlane/Fastfile`:
```ruby
default_platform(:ios)
platform :ios do
desc "Push a new beta build to TestFlight"
lane :beta do
sync_code_signing(type:"appstore", readonly: is_ci)
increment_build_number({
build_number: latest_testflight_build_number + 1
})
build_app(scheme:"Unity-iPhone")
upload_to_testflight(groups:["Team"])
end
end
```
Note about `upload_to_testflight`: Change "Team" to your internal tester or remove `(groups:["Team"])` if you want set manually who can test the build
##### Related documentation
* [sync_code_signing (alias for match)](https://docs.fastlane.tools/actions/sync_code_signing/)
* [increment_build_number](https://docs.fastlane.tools/actions/increment_build_number/)
* [build_app (alias for gym)](https://docs.fastlane.tools/actions/build_app/)
* [upload_to_testflight (alias for pilot)](https://docs.fastlane.tools/actions/testflight/)
#### Run tests locally
Run the following command to test the build and the deployement localy:
```bash
fastlane ios beta
```
If the build and upload are ok, you have to force add some file to your git using command below
```bash
git add -f pathToTheFileToAdd
```
you have to add the following files:
* `Gemfile`
* `Gemfile.lock` (if here)
* `fastlane/Appfile`
* `fastlane/Fastfile`
* `fastlane/Matchfile`
#### Gitlab-runner - register your mac
To automate your build with gitlab, you need to setup your mac as a gitlab runner.
Installation:
```bash
sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64
```
Give permission to execute :
```bash
sudo chmod +x /usr/local/bin/gitlab-runner
```
* [Source (if you would like to check)](https://docs.gitlab.com/runner/install/osx.html)
Go to your project gitlab page, then go to `settings` -> `CI/CD` -> `Runners` -> `Specitic Runners` -> `Set up a specific Runner manually` -> take note of the token
[Follow these instructions](https://docs.gitlab.com/runner/register/index.html) to register your mac as a gitlab-runner for your specific project.
Follow **macOS** instructions **without** sudo command for registration.
* Tags: set `mac,ios`
* Executor: set `shell`
Then, to install/launch the runner:
```bash
cd ~
gitlab-runner install
gitlab-runner start
```
Runner is installed and will be run after a system reboot.
Now, you can uncomment the job `build-and-deploy-ios` in `.gitlab-ci.yml` to make the app build and deployement work.
### Android support
......@@ -280,12 +424,13 @@ Encode your keystore file as base64 using openssl:
Copy the result to your CI's environment variable `ANDROID_KEYSTORE_BASE64`
Add following environment variables:
- `KEYSTORE_PASS` : Keystore pass
- `KEY_ALIAS_NAME` : Keystore alias name to use (if not set, the program will use the alias name set in Project's PlayerSettings)
- `KEY_ALIAS_PASS` : Keystore alias pass to use
Add following environment variables:
* `KEYSTORE_PASS`: Keystore pass
* `KEY_ALIAS_NAME`: Keystore alias name to use (if not set, the program will use the alias name set in Project's PlayerSettings)
* `KEY_ALIAS_PASS`: Keystore alias pass to use
Note about keystore security, if you would like to use another solution, see [HERE](https://android.jlelse.eu/where-to-store-android-keystore-file-in-ci-cd-cycle-2365f4e02e57)
Note about _keystore security_, if you would like to use another solution for storage, see [HERE](https://android.jlelse.eu/where-to-store-android-keystore-file-in-ci-cd-cycle-2365f4e02e57).
## How to run scripts manually
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment