Skip to content

WIP: Circleci support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9c37533
first commit for CircleCI
GabLeRoux Sep 15, 2018
eb7ce5a
Update shameless plug
GabLeRoux Sep 15, 2018
f212e70
Add CircleCI Badge to readme
GabLeRoux Sep 15, 2018
8c52ea5
Setup circleci (first draft) and move licenses to ci folder
GabLeRoux Sep 15, 2018
a7afec4
Move ignored gh-pages branch for circleci
GabLeRoux Sep 15, 2018
5b0b803
Fix license path for travis
GabLeRoux Sep 15, 2018
afe4761
Add setup_unity_license_env_var step to circleci
GabLeRoux Sep 15, 2018
985f5b0
Skipping gh-pages for now for circleci
GabLeRoux Sep 15, 2018
4fc5b42
Commenting artifacts for circleci
GabLeRoux Sep 15, 2018
8691a3e
Commenting setup_unity_license_env_var for circleci
GabLeRoux Sep 15, 2018
68e34c7
Trying something simplified for CircleCI
GabLeRoux Sep 15, 2018
d6df274
Remove BUILD_NAME from top jobs definition
GabLeRoux Sep 15, 2018
5a2f7c4
Still trying things with circleci, it's getting late
GabLeRoux Sep 15, 2018
c739cf9
Still trying things with circleci, it's getting late
GabLeRoux Sep 15, 2018
7cd6dd9
Fix indentation for build step circleci
GabLeRoux Sep 15, 2018
79532b3
Fix no command given circleci
GabLeRoux Sep 15, 2018
bb8a1da
Add activation part to circleci
GabLeRoux Sep 15, 2018
09667c9
Testing and building for CircleCI
GabLeRoux Sep 15, 2018
d04a883
Use workflows and display openssl version + -md md5
GabLeRoux Sep 15, 2018
cf7336f
Install git in image before running checkout step (with todo)
GabLeRoux Sep 15, 2018
ed96ef7
Fix circleci (wasn't using right unity license, my bad)
GabLeRoux Sep 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
version: 2
references:
docker_image: &docker_image
docker:
- image: gableroux/unity3d:2018.2.6f1
setup_unity_license_env_var: &setup_unity_license_env_var
command: |
openssl version
openssl aes-256-cbc -md md5 -d -in ./ci/Unity_v2018.x.ulf-cipher -out Unity_v2018.x.ulf -k $KEY
export UNITY_LICENSE_CONTENT=`cat Unity_v2018.x.ulf`
rm Unity_v2018.x.ulf
jobs:
test_editmode:
<<: *docker_image
steps:
# TODO: Add git to unity image so this is not required anymore
# this will prevent following error on 'checkout' step:
# Either git or ssh (required by git to clone through SSH) is not installed in the image. Falling back to CircleCI's native git client but the behavior may be different from official git. If this is an issue, please use an image that has official git and ssh installed.
- run:
command: apt-get update && apt-get install -y git && git --version
- checkout
- run:
<<: *setup_unity_license_env_var
- run:
environment:
TEST_PLATFORM: editmode
command: "./ci/test.sh"
- store_artifacts:
path: "$(pwd)/$TEST_PLATFORM-results.xml"
destination: "$TEST_PLATFORM-results.xml"
test_playmode:
<<: *docker_image
steps:
- run:
command: apt-get update && apt-get install -y git && git --version
- checkout
- run:
<<: *setup_unity_license_env_var
- run:
environment:
TEST_PLATFORM: playmode
command: "./ci/test.sh"
- store_artifacts:
path: "$(pwd)/$TEST_PLATFORM-results.xml"
destination: "$TEST_PLATFORM-results.xml"
build_StandaloneLinux64:
<<: *docker_image
steps:
- run:
command: apt-get update && apt-get install -y git && git --version
- checkout
- run:
<<: *setup_unity_license_env_var
- run:
environment:
BUILD_TARGET: StandaloneLinux64
command: "./ci/build.sh"
- store_artifacts:
path: "./Builds/"
workflows:
version: 2
test_and_build:
jobs:
- test_editmode
- test_playmode
- build_StandaloneLinux64

# - run:
# environment:
# TEST_PLATFORM: editmode
# command: "./ci/test.sh"
## - store_artifacts:
## path: "$(pwd)/$TEST_PLATFORM-results.xml"
## destination: "$TEST_PLATFORM-results.xml"
# - run:
# environment:
# TEST_PLATFORM: playmode
# command: "./ci/test.sh"
## - store_artifacts:
## path: "$(pwd)/$TEST_PLATFORM-results.xml"
## destination: "$TEST_PLATFORM-results.xml"
# build:
# <<: *docker_image
# steps:
## - run:
## <<: *setup_unity_license_env_var
# - run:
# BUILD_TARGET: StandaloneLinux64
# command: "./ci/build.sh"
## - store_artifacts:
## path: "./Builds/"
# - run:
# environment:
# BUILD_TARGET: StandaloneOSX
# command: "./ci/build.sh"
## - store_artifacts:
## path: "./Builds/"
# - run:
# environment:
# BUILD_TARGET: StandaloneWindows64
# command: "./ci/build.sh"
## - store_artifacts:
## path: "./Builds/"
# - run:
# environment:
# BUILD_TARGET: WebGL
# command: "./ci/build.sh"
## - store_artifacts:
## path: "./Builds/"
## following is untested, but deploying to github-pages from CircleCI should look like this:
# deploy_pages:
# machine:
# enabled: true
# steps:
# - run:
# name: Deploy github-pages
# environment:
# - SOURCE_BRANCH: master
# - TARGET_BRANCH: gh-pages
# command: |
# if [ $CIRCLE_BRANCH == $SOURCE_BRANCH ]; then
# git config --global user.email $GH_EMAIL
# git config --global user.name $GH_NAME
#
# git clone $CIRCLE_REPOSITORY_URL out
#
# cd out
# git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
# git rm -rf .
# cd ..
#
# cp -a ./Builds/ out/.
#
# #mkdir -p out/.circleci && cp -a .circleci/. out/.circleci/.
# cd out
#
# git add -A
# git commit -m "Automated deployment to GitHub Pages: ${CIRCLE_SHA1}" --allow-empty
#
# git push origin $TARGET_BRANCH
# fi
#workflows:
# version: 2
# test_and_build:
# jobs:
# - test
# - build
##TODO: prevent build on gh-pages branch in workflows
#filter:
# branches:
# ignore:
# - gh-pages

## example if you'd like to create builds only on master
# - build:
# filters:
# branches:
# only:
# - master
## example for deploying github pages
# - deploy_pages:
# requires:
# - test
# - build
# filters:
# branches:
# only:
# - master
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- docker
before_install:
- openssl aes-256-cbc -K $encrypted_82766e747237_key -iv $encrypted_82766e747237_iv
-in Unity_v2018.x.ulf.enc -out ./Unity_v2018.x.ulf -d
-in ./ci/Unity_v2018.x.ulf.enc -out Unity_v2018.x.ulf -d
- export UNITY_LICENSE_CONTENT=`cat Unity_v2018.x.ulf`
- rm Unity_v2018.x.ulf
- docker pull $IMAGE_NAME
Expand Down
50 changes: 38 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![pipeline status](https://gitlab.com/gableroux/unity3d-gitlab-ci-example/badges/master/pipeline.svg)](https://gitlab.com/gableroux/unity3d-gitlab-ci-example/commits/master)
[![Build Status](https://travis-ci.com/GabLeRoux/unity3d-ci-example.svg?branch=master)](https://travis-ci.com/GabLeRoux/unity3d-ci-example)
[![CircleCI](https://circleci.com/gh/GabLeRoux/unity3d-ci-example.svg?style=svg)](https://circleci.com/gh/GabLeRoux/unity3d-ci-example)

This project is a PoC to **run unity3d tests and builds inside a CI** using [gableroux/unity3d docker image](https://hub.docker.com/r/gableroux/unity3d/). It currently creates builds for Windows, Linux, MacOS and webgl. The webgl build is published by the CI to [gitlab-pages](https://about.gitlab.com/features/pages/) and [github-pages]()! This repository is hosted on multiple remotes to provide examples for [Gitlab-CI](), [Travis]() and [CircleCI]():

Expand All @@ -17,11 +18,13 @@ This project is a PoC to **run unity3d tests and builds inside a CI** using [gab
- [Build script](#build-script)
- [CI Configuration](#ci-configuration)
- [gitlab-ci](#gitlab-ci)
- [WIP: CircleCI](#wip-circleci)
- [CircleCI](#circleci)
- [Travis](#travis)
- [Test files](#test-files)
- [How to activate](#how-to-activate)
- [Gitlab-CI](#gitlab-ci)
- [Travis](#travis-1)
- [CircleCI](#circleci-1)
- [How to add build targets](#how-to-add-build-targets)
- [gitlab-ci](#gitlab-ci-1)
- [iOS support](#ios-support)
Expand All @@ -43,7 +46,7 @@ If you don't have a Unity project yet:

If you already have your own project:

1. Copy desired CI file
1. Copy desired CI file and scripts in `ci` folder
2. Update the Unity version according to your project version in the CI file. All versions are available at [gableroux/unity3d docker image](https://hub.docker.com/r/gableroux/unity3d/)
3. Copy build script (make sure you use the same path as original project, it must be in an `Editor` folder)
4. Follow How to activate instructions
Expand All @@ -67,9 +70,7 @@ Pick one, if you're on gitlab, use gitlab-ci as Travis and CircleCI don't suppor

* [`.gitlab-ci.yml`](.gitlab-ci.yml)

#### WIP: CircleCI

**TODO**
#### CircleCI

* [`.circleci/config.yml`](.circleci/config.yml)

Expand Down Expand Up @@ -127,24 +128,49 @@ You'll first need to run this locally. All you need is [docker](https://www.dock
6. Open https://license.unity3d.com/manual and answer questions
7. Upload `unity3d.alf` for manual activation
8. Download `Unity_v2018.x.ulf`
9. Copy the content of `Unity_v2018.x.ulf` license file to your CI's environment variable `UNITY_LICENSE_CONTENT`.
_Note: if you are doing this on windows, chances are the [line endings will be wrong as explained here](https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_95831816). Luckily for you, [`.gitlab-ci.yml`](.gitlab-ci.yml) solves this by removing `\r` character from the env variable so you'll be alright_
[`.gitlab-ci.yml`](.gitlab-ci.yml) will then place the `UNITY_LICENSE_CONTENT` to the right place before running tests or creating the builds.
9. Pass the license as a secret to your CI Configuration (see following sections)

### Gitlab-CI

Gitlab-CI Supports using mutli-line environment variables out of the box. :tada:

Copy the content of `Unity_v2018.x.ulf` license file to your CI's environment variable `UNITY_LICENSE_CONTENT`.

_Note: if you are doing this on windows, chances are the [line endings will be wrong as explained here](https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_95831816). Luckily for you, [`.gitlab-ci.yml`](.gitlab-ci.yml) solves this by removing `\r` character from the env variable so you'll be alright_. [`.gitlab-ci.yml`](.gitlab-ci.yml) will then place the `UNITY_LICENSE_CONTENT` to the right place before running tests or creating the builds.

### Travis

Travis doesn't support multiple-lines env variable out of the box and I had troubles with escaping so I recommend encrypting the license file. `.travis.yml` will decrypt the file and add its content to `UNITY_LICENSE_CONTENT` env var itself afterward.
Travis doesn't support multiple-lines environment variables. I had troubles with escaping so I recommend encrypting the license file. `.travis.yml` will decrypt the file and add its content to `UNITY_LICENSE_CONTENT` env var itself afterward.

Move your `Unity_v2018.x.ulf` to `ci` folder (so you don't clutter your project's root). Just make sure you don't track it inside git.

```bash
travis encrypt-file --pro -r YOUR_TRAVIS_USERNAME/YOUR_TRAVIS_REPO_NAME ./Unity_v2018.x.ulf
travis encrypt-file --pro -r YOUR_TRAVIS_USERNAME/YOUR_TRAVIS_REPO_NAME ./ci/Unity_v2018.x.ulf
```

For the record, the message I was getting:
For the record, the message I was getting when trying to paste license content directly into the env var in travis settings:

> The previous command failed, possibly due to a malformed secure environment variable.
> Please be sure to escape special characters such as ' ' and '$'.
> For more information, see https://docs.travis-ci.com/user/encryption-keys.

### CircleCI

CircleCI doesn't support multi-lines environment variables. We can use a solution similar to Travis by encrypting the license and decrypting it from the CI using `openssl` [as explained here](https://github.com/circleci/encrypted-files):

Move your `Unity_v2018.x.ulf` to `ci` folder (so you don't clutter your project's root). Just make sure you don't track it inside git.

1. Generate a strong password
2. Store that password in a new `KEY` env var in CircleCI
3. Encrypt the license using the same `KEY`

```bash
export KEY=insert-your-strong-generated-key-here
openssl aes-256-cbc -e -in ci/Unity_v2018.x.ulf -out ci/Unity_v2018.x.ulf-cipher -k $KEY
git add ci/Unity_v2018.x.ulf-cipher
git commit -m "Add encrypted Unity_v2018.x.ulf using openssl aes-256-cbc KEY"
```

## How to add build targets

Supported build targets can be found [here](https://docs.unity3d.com/ScriptReference/BuildTarget.html)
Expand Down Expand Up @@ -179,7 +205,7 @@ path/to/unity -runTests -projectPath $(pwd) -testResults $(pwd)/playmode-results

## Shameless plug

I made this for free as a gift to the video game community so if this tool helped you, I would be very happy if you'd like to support me, support [Totema Studio](https://totemastudio.com) on Patreon: :beers:
I made this for free as a gift to the video game community. If this tool helped you, feel free to become a patron for [Totema Studio](https://totemastudio.com) on Patreon: :beers:

[![Totema Studio Logo](./doc/totema-studio-logo-217.png)](https://patreon.com/totemastudio)

Expand Down
Binary file added ci/Unity_v2018.x.ulf-cipher
Binary file not shown.
File renamed without changes.