Upgrade Unity version #142
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Manually upgrade unity and update packages | |
# Check if the Unity version already exists as a docker image: https://game.ci/docs/docker/versions | |
name: Upgrade Unity version | |
on: | |
workflow_dispatch: | |
inputs: | |
unityVersion: | |
description: 'Unity version' | |
required: true | |
type: string | |
createTags: | |
description: 'Create Tags' | |
required: false | |
type: boolean | |
default: true | |
urp: | |
description: 'URP branch' | |
required: true | |
type: boolean | |
default: false | |
tagsOnly: | |
description: 'Only create tags' | |
required: true | |
type: boolean | |
default: false | |
mergeMaster: | |
description: 'Merge master into branch' | |
required: true | |
type: boolean | |
default: true | |
customParameters: | |
description: 'Custom cli arguments' | |
required: false | |
type: string | |
default: '-accept-apiupdate' | |
jobs: | |
upgrade-unity-version: | |
name: Upgrade Unity version and packages | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
steps: | |
- name: Log input parameter | |
run: | | |
echo "Unity version: $UNITY_VERSION" | |
echo "Create tags: $CREATE_TAGS" | |
echo "URP branch: $URP_BRANCH" | |
echo "Only create tags: $TAGS_ONLY" | |
echo "Merge master into branch: $MERGE_MASTER" | |
echo "Custom cli arguments: $CUSTOM_PARAMETERS" | |
env: | |
UNITY_VERSION: ${{ inputs.unityVersion }} | |
CREATE_TAGS: ${{ inputs.createTags }} | |
URP_BRANCH: ${{ inputs.urp }} | |
TAGS_ONLY: ${{ inputs.tagsOnly }} | |
MERGE_MASTER: ${{ inputs.mergeMaster }} | |
CUSTOM_PARAMETERS: ${{ inputs.customParameters }} | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
lfs: true | |
# Makes sure, that pushing new tags will trigger workflows | |
token: ${{ secrets.PR_GITHUB_TOKEN }} | |
- name: Set git user | |
run: | | |
git status | |
git config --global user.email "[email protected]" | |
git config --global user.name "$GIT_USER" | |
env: | |
GIT_USER: ${{ github.actor }} | |
# Make sure the branch has the latest master changes in | |
- name: Merge master into current branch | |
if: ${{ inputs.mergeMaster }} | |
run: | | |
git fetch origin master | |
git merge FETCH_HEAD | |
git push | |
# Unity 2020 cache is not compatible with older versions | |
- name: Unity Library Cache 2020 or higher | |
if: ${{ !startsWith(inputs.unityVersion, '201') }} | |
uses: actions/cache@v3 | |
with: | |
path: Library | |
key: Library-202x-WebGL | |
restore-keys: Library-202x- | |
- name: Unity Library Cache 2019 or lower | |
if: ${{ startsWith(inputs.unityVersion, '201') }} | |
uses: actions/cache@v3 | |
with: | |
path: Library | |
key: Library-201x-WebGL | |
restore-keys: Library-201x- | |
- name: Set last unity version | |
id: last_unity_version | |
run: | | |
LAST_UNITY_VERSION=$(sed -n 's/^\m_EditorVersion: //p'< ./ProjectSettings/ProjectVersion.txt) | |
echo "VERSION=$LAST_UNITY_VERSION" >> $GITHUB_OUTPUT | |
- name: Set upgrade name | |
id: upgrade_name | |
run: | | |
if [[ "$URP_BRANCH" == "true" ]] | |
then | |
echo "NAME=$UNITY_VERSION-urp" >> $GITHUB_OUTPUT | |
else | |
echo "NAME=$UNITY_VERSION" >> $GITHUB_OUTPUT | |
fi | |
env: | |
UNITY_VERSION: ${{ inputs.unityVersion }} | |
URP_BRANCH: ${{ inputs.urp }} | |
- name: Log variables | |
run: | | |
echo "last_unity_version -> ${{ steps.last_unity_version.outputs.VERSION }}" | |
echo "upgrade_name -> ${{ steps.upgrade_name.outputs.NAME }}" | |
- name: Build project | |
if: ${{ !inputs.tagsOnly }} | |
uses: JohannesDeml/unity-builder@no-quit-parameter | |
env: | |
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
with: | |
buildMethod: UnityBuilderAction.UnityPackageScripts.UpgradeAllPackagesToVerifiedVersion | |
customParameters: ${{ inputs.customParameters }} | |
unityVersion: ${{ inputs.unityVersion }} | |
targetPlatform: WebGL | |
buildName: ${{ needs.variables.outputs.BUILD_NAME }} | |
allowDirtyBuild: true | |
- name: Delete build folder with elevated rights | |
if: ${{ !inputs.tagsOnly }} | |
run: sudo rm -rf ./build | |
- name: Render template | |
if: ${{ !inputs.tagsOnly }} | |
id: template | |
uses: chuhlomin/[email protected] | |
with: | |
template: .github/templates/upgrade-unity-pr-body.md | |
vars: | | |
unityversion: ${{ steps.upgrade_name.outputs.NAME }} | |
- name: Create Pull Request | |
if: ${{ !inputs.tagsOnly }} | |
uses: peter-evans/create-pull-request@v4 | |
with: | |
token: ${{ secrets.PR_GITHUB_TOKEN }} | |
commit-message: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.VERSION}} to ${{ inputs.unityVersion }}" | |
branch: "ci/upgrade-unity/from-${{steps.last_unity_version.outputs.VERSION}}-to-${{ steps.upgrade_name.outputs.NAME }}" | |
delete-branch: true | |
title: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.VERSION}} to ${{ steps.upgrade_name.outputs.NAME }}" | |
body: ${{ steps.template.outputs.result }} | |
- name: Add tags | |
if: ${{ inputs.createTags || inputs.tagsOnly }} | |
run: | | |
if [[ "$URP_BRANCH" == "true" ]] | |
then | |
git tag -a -f $UNITY_VERSION-urp-webgl1 -m "[Automated workflow] Created by upgrade-unity" | |
git tag -a -f $UNITY_VERSION-urp-webgl2 -m "[Automated workflow] Created by upgrade-unity" | |
git tag -a -f $UNITY_VERSION-urp-webgl2-debug -m "[Automated workflow] Created by upgrade-unity" | |
else | |
git tag -a -f $UNITY_VERSION-minsize-webgl1 -m "[Automated workflow] Created by upgrade-unity" | |
git tag -a -f $UNITY_VERSION-webgl1 -m "[Automated workflow] Created by upgrade-unity" | |
git tag -a -f $UNITY_VERSION-webgl2 -m "[Automated workflow] Created by upgrade-unity" | |
# Push tags in between - pushing more than 3 tags won't trigger tag workflows | |
git push origin -f --tags | |
git tag -a -f $UNITY_VERSION-webgl2-debug -m "[Automated workflow] Created by upgrade-unity" | |
fi | |
git push origin -f --tags | |
env: | |
UNITY_VERSION: ${{ inputs.unityVersion }} | |
URP_BRANCH: ${{ inputs.urp }} | |