├── .github └── FUNDING.yml ├── LICENSE ├── Makefile ├── README.md └── bin ├── auth.sh ├── deauth.sh ├── install.sh └── test.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | ko_fi: scottdoxey 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2022 Scott Doxey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | shellcheck bin/auth.sh bin/deauth.sh bin/install.sh bin/test.sh 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity CI Tools 2 | 3 | > Bash scripts for running Unity tests on continuous integration services 4 | 5 | [![Join the chat at https://discord.gg/nNtFsfd](https://img.shields.io/badge/discord-join%20chat-7289DA.svg)](https://discord.gg/nNtFsfd) 6 | 7 | ## Setup 8 | 9 | ### Create a `bitrise.yml` File 10 | 11 | ```yaml 12 | --- 13 | format_version: "8" 14 | default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git 15 | project_type: other 16 | trigger_map: 17 | - push_branch: main 18 | workflow: primary 19 | - pull_request_source_branch: "*" 20 | workflow: primary 21 | pull_request_target_branch: main 22 | workflows: 23 | primary: 24 | steps: 25 | - git-clone@6: {} 26 | - cache-pull@2: {} 27 | - script@1: 28 | title: Install and Test with Unity 29 | inputs: 30 | - content: |- 31 | #!/usr/bin/env bash 32 | # fail if any commands fails 33 | set -e 34 | # debug log 35 | set -x 36 | 37 | bash <(curl -fsSL https://raw.githubusercontent.com/neogeek/unity-ci-tools/v1.1.0/bin/install.sh) 38 | bash <(curl -fsSL https://raw.githubusercontent.com/neogeek/unity-ci-tools/v1.1.0/bin/auth.sh) 39 | bash <(curl -fsSL https://raw.githubusercontent.com/neogeek/unity-ci-tools/v1.1.0/bin/test.sh) 40 | bash <(curl -fsSL https://raw.githubusercontent.com/neogeek/unity-ci-tools/v1.1.0/bin/deauth.sh) 41 | - cache-push@2: 42 | inputs: 43 | - cache_paths: "$HOME/cache" 44 | is_always_run: true 45 | meta: 46 | bitrise.io: 47 | machine_type: standard 48 | stack: osx-xcode-13.1.x 49 | ``` 50 | 51 | ### Create a `Makefile` File 52 | 53 | ```yaml 54 | test: SHELL:=/bin/bash 55 | test: 56 | bash <(curl -fsSL https://raw.githubusercontent.com/neogeek/unity-ci-tools/v1.1.0/bin/test.sh) 57 | 58 | clean: 59 | git clean -xdf 60 | ``` 61 | 62 | ### Setup Environment Variables on Bitrise 63 | 64 | Add the following variables in the Secrets tab in the Workflow Editor section of your project on : 65 | 66 | | Key | Description | Required | 67 | | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | 68 | | UNITY_SERIAL | The serial key found at . Keys are only avalible with a Plus or Pro Subscription | Yes | 69 | | UNITY_USERNAME | Your email address used to log into . | Yes | 70 | | UNITY_PASSWORD | Your password used to log into . | Yes | 71 | | UNITY_INSTALLER_URL | Full URL of editor installer. See [editor installers](https://github.com/neogeek/get-unity/blob/master/data/editor-installers.json). | No | 72 | | UNITY_INSTALLER_VERSION | Version of editor installer. To be used with hash. See [editor installers](https://github.com/neogeek/get-unity/blob/master/data/editor-installers.json). | No | 73 | | UNITY_INSTALLER_HASH | Hash of editor installer. To be used to version. See [editor installers](https://github.com/neogeek/get-unity/blob/master/data/editor-installers.json). | No | 74 | -------------------------------------------------------------------------------- /bin/auth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # https://github.com/tmux/tmux/issues/475#issuecomment-231527324 4 | export EVENT_NOKQUEUE=1 5 | 6 | findunity() { 7 | 8 | local UNITY_INSTALLS 9 | local PROJECT_VERSION 10 | local UNITY_INSTALL_VERSION_MATCH 11 | local UNITY_INSTALL_LATEST 12 | 13 | UNITY_INSTALLS=$(find /Applications/Unity -name "Unity.app" | sort -r) 14 | 15 | if [ -f "ProjectSettings/ProjectVersion.txt" ]; then 16 | 17 | PROJECT_VERSION=$(grep -o -E "[0-9]+\.[0-9]+\.[0-9]+[a-z][0-9]+" "ProjectSettings/ProjectVersion.txt" | head -1) 18 | 19 | UNITY_INSTALL_VERSION_MATCH=$(grep "${PROJECT_VERSION}" <<< "${UNITY_INSTALLS}") 20 | 21 | fi 22 | 23 | UNITY_INSTALL_LATEST=$(head -1 <<< "${UNITY_INSTALLS}") 24 | 25 | UNITY_APPLICATION=${UNITY_INSTALL_VERSION_MATCH:-$UNITY_INSTALL_LATEST} 26 | 27 | } 28 | 29 | findunity 30 | 31 | "${UNITY_APPLICATION}/Contents/MacOS/Unity" \ 32 | -quit \ 33 | -batchmode \ 34 | -serial "${UNITY_SERIAL}" \ 35 | -username "${UNITY_USERNAME}" \ 36 | -password "${UNITY_PASSWORD}" || true 37 | -------------------------------------------------------------------------------- /bin/deauth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # https://github.com/tmux/tmux/issues/475#issuecomment-231527324 4 | export EVENT_NOKQUEUE=1 5 | 6 | findunity() { 7 | 8 | local UNITY_INSTALLS 9 | local PROJECT_VERSION 10 | local UNITY_INSTALL_VERSION_MATCH 11 | local UNITY_INSTALL_LATEST 12 | 13 | UNITY_INSTALLS=$(find /Applications/Unity -name "Unity.app" | sort -r) 14 | 15 | if [ -f "ProjectSettings/ProjectVersion.txt" ]; then 16 | 17 | PROJECT_VERSION=$(grep -o -E "[0-9]+\.[0-9]+\.[0-9]+[a-z][0-9]+" "ProjectSettings/ProjectVersion.txt" | head -1) 18 | 19 | UNITY_INSTALL_VERSION_MATCH=$(grep "${PROJECT_VERSION}" <<< "${UNITY_INSTALLS}") 20 | 21 | fi 22 | 23 | UNITY_INSTALL_LATEST=$(head -1 <<< "${UNITY_INSTALLS}") 24 | 25 | UNITY_APPLICATION=${UNITY_INSTALL_VERSION_MATCH:-$UNITY_INSTALL_LATEST} 26 | 27 | } 28 | 29 | findunity 30 | 31 | "${UNITY_APPLICATION}/Contents/MacOS/Unity" \ 32 | -quit \ 33 | -batchmode \ 34 | -returnlicense || true 35 | -------------------------------------------------------------------------------- /bin/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -d "${HOME}/cache" ]; then 4 | 5 | mkdir -m 777 "${HOME}/cache" 6 | 7 | fi 8 | 9 | if [ -z "${UNITY_INSTALLER_HASH}" ]; then 10 | 11 | UNITY_INSTALLER_HASH="59ff3e03856d" 12 | 13 | fi 14 | 15 | if [ -z "${UNITY_INSTALLER_VERSION}" ]; then 16 | 17 | UNITY_INSTALLER_VERSION="2019.3.15f1" 18 | 19 | fi 20 | 21 | if [ -z "${UNITY_INSTALLER_URL}" ]; then 22 | 23 | UNITY_INSTALLER_URL="https://download.unity3d.com/download_unity/${UNITY_INSTALLER_HASH}/MacEditorInstaller/Unity-${UNITY_INSTALLER_VERSION}.pkg" 24 | 25 | fi 26 | 27 | FILENAME=$(basename "${UNITY_INSTALLER_URL}") 28 | 29 | if [ ! -f "${HOME}/cache/${FILENAME}" ]; then 30 | 31 | echo "Downloading Unity ${UNITY_INSTALLER_VERSION} from ${UNITY_INSTALLER_URL}" 32 | curl --retry 5 -o "${HOME}/cache/${FILENAME}" "${UNITY_INSTALLER_URL}" 33 | 34 | fi 35 | 36 | echo "Installing Unity ${UNITY_INSTALLER_VERSION}" 37 | sudo installer -dumplog -package "${HOME}/cache/${FILENAME}" -target / 38 | -------------------------------------------------------------------------------- /bin/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # https://github.com/tmux/tmux/issues/475#issuecomment-231527324 4 | export EVENT_NOKQUEUE=1 5 | 6 | findunity() { 7 | 8 | local UNITY_INSTALLS 9 | local PROJECT_VERSION 10 | local UNITY_INSTALL_VERSION_MATCH 11 | local UNITY_INSTALL_LATEST 12 | 13 | UNITY_INSTALLS=$(find /Applications/Unity -name "Unity.app" | sort -r) 14 | 15 | if [ -f "ProjectSettings/ProjectVersion.txt" ]; then 16 | 17 | PROJECT_VERSION=$(grep -o -E "[0-9]+\.[0-9]+\.[0-9]+[a-z][0-9]+" "ProjectSettings/ProjectVersion.txt" | head -1) 18 | 19 | UNITY_INSTALL_VERSION_MATCH=$(grep "${PROJECT_VERSION}" <<< "${UNITY_INSTALLS}") 20 | 21 | fi 22 | 23 | UNITY_INSTALL_LATEST=$(head -1 <<< "${UNITY_INSTALLS}") 24 | 25 | UNITY_APPLICATION=${UNITY_INSTALL_VERSION_MATCH:-$UNITY_INSTALL_LATEST} 26 | 27 | } 28 | 29 | findunity 30 | 31 | UNITY_VERSION=$(defaults read "${UNITY_APPLICATION}/Contents/Info.plist" CFBundleVersion) 32 | 33 | echo "Testing with Unity ${UNITY_VERSION}" 34 | 35 | if echo "${UNITY_VERSION}" | grep "2019" &> /dev/null; then 36 | 37 | "${UNITY_APPLICATION}/Contents/MacOS/Unity" \ 38 | -batchmode \ 39 | -nographics \ 40 | -silent-crashes \ 41 | -stackTraceLogType Full \ 42 | -logFile - \ 43 | -projectPath "$(pwd)/" \ 44 | -runEditorTests \ 45 | -editorTestsResultFile "$(pwd)/test.xml" 46 | 47 | else 48 | 49 | "${UNITY_APPLICATION}/Contents/MacOS/Unity" \ 50 | -batchmode \ 51 | -nographics \ 52 | -noUpm \ 53 | -silent-crashes \ 54 | -logFile "$(pwd)/unity.log" \ 55 | -projectPath "$(pwd)/" \ 56 | -runEditorTests \ 57 | -editorTestsResultFile "$(pwd)/test.xml" 58 | 59 | cat "$(pwd)/unity.log" 60 | 61 | fi 62 | 63 | LOG_FILE="$(pwd)/test.xml" 64 | 65 | checktests() { 66 | 67 | local TOTAL 68 | local PASSED 69 | local FAILED 70 | 71 | if [ ! -f "${LOG_FILE}" ]; then 72 | 73 | printf "Test results missing.\n" 74 | 75 | return 1 76 | 77 | fi 78 | 79 | TOTAL=$(grep -Eo 'total="([0-9]*)"' "${LOG_FILE}" | head -1 | grep -Eo '[0-9]+') 80 | PASSED=$(grep -Eo 'passed="([0-9]*)"' "${LOG_FILE}" | head -1 | grep -Eo '[0-9]+') 81 | FAILED=$(grep -Eo 'failed="([0-9]*)"' "${LOG_FILE}" | head -1 | grep -Eo '[0-9]+') 82 | 83 | printf '\n%s\n\n' "$(<"${LOG_FILE}")" 84 | 85 | printf "Test Results:\n - Total %s\n ✔ Passed %s\n 𐄂 Failed %s\n" "${TOTAL}" "${PASSED}" "${FAILED}" 86 | 87 | if [ "${TOTAL}" -ne "${PASSED}" ]; then 88 | 89 | return 1 90 | 91 | fi 92 | 93 | return 0 94 | 95 | } 96 | 97 | checktests 98 | 99 | CODE=$? 100 | 101 | exit $CODE 102 | --------------------------------------------------------------------------------