├── .travis.yml ├── LICENSE ├── README.md └── ci ├── move_to_packagebranch.sh └── show_tree.sh /.travis.yml: -------------------------------------------------------------------------------- 1 | language: generic 2 | 3 | #define GITHUB_TOKEN variable at Environment Variables for your progect in Travis 4 | 5 | env: 6 | - | 7 | MASTER_TARGET_BRANCH=upm #for master 8 | DEVELOP_TARGET_BRANCH=upm-dev #for develop 9 | TEST_BRANCH=upm-test #for other branches 10 | TARGET_BRANCH=not_defined #upm-branch to clone, will be chosen later 11 | TEST_RUN=false #will be true if branch is not master or develop 12 | FOLDER_TO_EXPORT=Assets/ParentFolder #parent folder for your root directory 13 | 14 | sudo: required 15 | 16 | before_install: 17 | - | 18 | if [ "$TRAVIS_BRANCH" = "develop" ]; then 19 | TARGET_BRANCH=$DEVELOP_TARGET_BRANCH 20 | elif [ "$TRAVIS_BRANCH" = "master" ]; then 21 | TARGET_BRANCH=$MASTER_TARGET_BRANCH 22 | else 23 | TARGET_BRANCH=$DEVELOP_TARGET_BRANCH #include your test branch in branches section to 24 | TEST_RUN=true 25 | fi 26 | 27 | after_success: 28 | - chmod 777 -R ci 29 | - ci/move_to_packagebranch.sh 30 | 31 | branches: 32 | only: 33 | - master 34 | - develop 35 | - /^(?i:test).*$/ 36 | except: 37 | - /^(?i:upm).*$/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Alex 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # unity-package-manager-ci 2 | [![](https://img.shields.io/badge/Unity-Package%20Manager-blue.svg?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAQAAADZc7J%2FAAADzElEQVRIx5WVW2jWZRzHP%2B%2F736mdmG6Sp5sUt5ygYpJriad5oGXmhVkXWZCGFWSgtjnacp0QTGKGw3QXoUQw7CIstAhiCrpceGGC5lzpPM2F5DZ1B9veTxf%2BffduKtbvd%2FMc%2BH%2Be5%2F87fB%2F47xYhhRxmUUUDbbwfXzfBY0PGsYRVciKmmOMsq2ywzXzJF0h6yKEBaTzFbBblFM9iHvOZQAaPEKGI5iKaH3IDMgIzXOhmj3jNHvsdtHqp92G%2FQM1GL5loA%2FFRm1GJPgBAGpmk8fYU%2B%2BIfdHne7%2FwtPu92qky9L4C5aWaa5mhPqR222Ohu1zjaHA%2BrGlP7LTeQIAImBE2iG%2BZuW0YmtykgiyaO8yunf%2BEkTcl1tbwO%2FMAAi0mmgVJ60ofdgPXzbQkvucc82c4rTBZh%2BTK7VJ3mYrvUaxZK4RAAG0o8GwarUvZQFN%2FJzfVHVfeZ5eN2qjctk7IEAGULw9P7fM9Acgezwqa1ql50hixIs0Ud8KAcjAOoXOq5MEQVRmVkQlYmTrRV1UoDCairc0C9IBdCAB8872VVb7vRVMmJDWYlPd1tqjY6XsYLpaXeVm%2FIjSSAyIfLquoYBVxkE19%2FzjGeid5NzAAZBbwBxPiSS2u9BBw6xE1GEECQxGORN1e8u5M8AE5whRXrUhJSO0A6b5EB7GMv7AXwVuTbQ8tL2QW7YOtWO%2BL11ecNu%2B1J8G57VG2xWOYO5muDDY6Q%2FCSWLCE7fl4SKQ%2Foy3aa4c%2F4tLOTy%2FTCxSR2Fu%2Bs4TWigJzkOGOH1GaMVJ4km2LWU3khEhgDYOZMlvIs37wDMIO6HWGrHjVfDnIgwb%2FnpzWq%2FuHTskBiEI16Rm2VVkCYwo7PjKl6yplSNqS8R47053gVkhWD6dP9R%2B2W7rt1MInaT0PEOWfLuiGIF%2BbZrfb7orwcg82bHVDbpX2wEidQ%2B3GIOO0cWZ8AyMz0C1WPmCd5HDumapM0JfbCOGqrQ8056xwpT0BMm%2BTvqlYYOM5OtdcaqRnajY8GVoaI874kW1hEVrhXXq7qVcdaZJfaYYmUDNeD3BTLbPWq121zi4vMkv1UU8KoUR5VtcqP7FFPmi3ZwwBCVrIFFjrZIv%2B2zRPut9oSs6X%2BCU%2BrnXYYs9%2FtJknSPQAhmQIKmcwnq8Og9vmXzdb7aigqqr0uvqvLPsAJAg8MEfWb9oRI7TBd0u9R5WGI5zJc5W7PeCtB4O%2FYYTl8n4flHkQGq9gdMd%2FVfuVZr9sbAiqk4j8AQkyE%2FMBUx7jSWhu9YrvFUiz%2FxwJSGcNKamnkCu1U31n%2BF80M7hBuo8ZPAAAAAElFTkSuQmCC&style=popout)](https://docs.unity3d.com/Manual/upm-dependencies.html) 3 | [![](https://img.shields.io/badge/CI-Travis-blue.svg?logo=travis&style=popout)](https://travis-ci.org/) 4 | 5 | Travis Ci scripts to push changes to specific branch for using with Unity Package Manager (UPM) system 6 | 7 | ## How Unity Package Manager works with git 8 | 9 | 10 | There's `Packages/manifest.json` in your Unity project folder. You can [manually add](https://docs.unity3d.com/Manual/upm-dependencies.html#Git) `git` dependencies in it like this 11 | ```json 12 | "com.company.repo.name": "https://YourGitHost.com/UserName/RepoName.git#BranchName" 13 | ``` 14 | To update asset through UPM you must delete reference in `lock` section in manifest. 15 | 16 | Currently you must follow strict rules if you want to use your asset like this. Most importantly, aux files (manifest, asmdef) _must be in repo root and have `*.meta` files._ 17 | 18 | This repo will help you set up CI for separate UPM branch 19 | 20 | ## Examples 21 | 22 | * [Hermesiss/unity-splines](https://github.com/Hermesiss/unity-splines) 23 | * [vladfaust/unity-wakatime](https://github.com/vladfaust/unity-wakatime) 24 | 25 | ## Configure Travis 26 | 1. Register at https://travis-ci.org/ for public or at https://travis-ci.com/ for private repos 27 | 2. Open repo settings, go to `Environment Variables` 28 | 3. Add variable with exact name `GITHUB_TOKEN` and value from [created token](https://github.com/settings/tokens) with selected scope `repo` 29 | 30 | ## Add files to repo 31 | 1. Open your project in Unity 32 | 1. Create `package.json` near your main folder (but inside `Assets`!) with keywords and category of your choice: 33 | ```json 34 | { 35 | "name": "com.company.repo.name", 36 | "displayName": "Display Name of Your Asset", 37 | "version": "0.1.1", 38 | "unity": "2018.3", 39 | "description": "Short description of your asset", 40 | "keywords": [ 41 | "unity", "editor" 42 | ], 43 | "category": "Instrument" 44 | } 45 | ``` 46 | 1. Create [Assembly definition](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html) file `com.company.repo.name.asmdef` in the same folder: 47 | ```json 48 | { 49 | "name": "Display Name of Your Asset" 50 | } 51 | ``` 52 | If you have Editor folders, repeat for each: 53 | 1. Create Assembly definition files with only `editor` platform included 54 | 1. Add references to other necessary asmdefs 55 | 1. Make sure that `*.meta` files appeared. You now must have 6 items in your dir: 1 folder, 1 .json, 1 .asmdef and 3 .meta 56 | 1. Copy `.travis.yml` file and `ci` folder to project's root 57 | 1. Edit `.travis.yml`, change env variables - target branches and folder to export. If you want to test this config, add custom test branch to `branches: only:` section 58 | 1. Commit and push changes 59 | 60 | ## Different info 61 | * If your commit doesn't require CI (like readme editing) you can add `[skip ci]` into your commit message and Travis won't build it 62 | * Unity is not consistent while handling Editor folders in packages during build, so it's mandatory to wrap all editor scripts in `#IF UNITY_EDITOR ... #ENDIF` or make [new asmdef file](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html) in every Editor folder with only `Editor` checked in platforms 63 | -------------------------------------------------------------------------------- /ci/move_to_packagebranch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #set -e 4 | set -x 5 | 6 | #echo "git push" 7 | REMOTE=$(git config --get remote.origin.url) 8 | echo $REMOTE 9 | COMMIT=$(git log -1 --pretty=%B) 10 | echo $COMMIT 11 | 12 | echo "TARGET_BRANCH is $TARGET_BRANCH" 13 | 14 | git archive -o archive.tar HEAD:$FOLDER_TO_EXPORT 15 | ARCHIVE_PATH=$(pwd) 16 | 17 | mkdir ../$TARGET_BRANCH 18 | cd ../$TARGET_BRANCH 19 | 20 | if [ "$(git ls-remote $REMOTE $TARGET_BRANCH | wc -l)" != 1 ]; then 21 | git clone --depth=1 $REMOTE 22 | cd * 23 | git checkout -b $TARGET_BRANCH 24 | else 25 | git clone --branch=$TARGET_BRANCH $REMOTE 26 | cd * 27 | fi 28 | 29 | shopt -s extglob 30 | rm ./ -dr -- !(.git) 31 | 32 | mv $ARCHIVE_PATH/archive.tar archive.tar 33 | 34 | echo "Archive content:" 35 | 36 | tar -tf archive.tar 37 | tar -xf archive.tar --overwrite 38 | rm archive.tar 39 | 40 | git add -A 41 | 42 | echo "Diffs:" 43 | git diff --cached 44 | 45 | git config --global user.email "travis@travis-ci.org" 46 | git config --global user.name "Travis CI" 47 | 48 | git commit -m "$COMMIT" 49 | 50 | git push https://$GITHUB_TOKEN@${REMOTE#*//} $TARGET_BRANCH -------------------------------------------------------------------------------- /ci/show_tree.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | shopt -s globstar 5 | for rdir in $1 6 | do 7 | for file in $rdir/** 8 | do 9 | echo "$file" 10 | done 11 | done 12 | --------------------------------------------------------------------------------