-
Notifications
You must be signed in to change notification settings - Fork 60
220 lines (199 loc) · 7.47 KB
/
upgrade-unity.yml
File metadata and controls
220 lines (199 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# 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
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'
delayTags:
description: 'Delay between tag pushes (in seconds, minimum 1)'
required: false
type: number
default: 1
jobs:
upgrade-unity-version:
name: Upgrade Unity version and packages to ${{ inputs.unityVersion }}
runs-on: ubuntu-latest
steps:
- name: Log input parameter
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
echo "Branch: $BRANCH_NAME"
echo "Unity version: $UNITY_VERSION"
echo "Create tags: $CREATE_TAGS"
echo "Only create tags: $TAGS_ONLY"
echo "Merge master into branch: $MERGE_MASTER"
echo "Custom cli arguments: $CUSTOM_PARAMETERS"
echo "Delay tags: $DELAY_TAGS seconds"
if [[ "$BRANCH_NAME" == *"urp"* ]]
then
echo "urp: true"
else
echo "urp: false"
fi
env:
UNITY_VERSION: ${{ inputs.unityVersion }}
CREATE_TAGS: ${{ inputs.createTags }}
TAGS_ONLY: ${{ inputs.tagsOnly }}
MERGE_MASTER: ${{ inputs.mergeMaster }}
CUSTOM_PARAMETERS: ${{ inputs.customParameters }}
DELAY_TAGS: ${{ inputs.delayTags }}
- uses: actions/checkout@v4
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 "$GIT_USER@users.noreply.github.com"
git config --global user.name "$GIT_USER"
env:
GIT_USER: ${{ github.actor }}
# Avoid running into space issues for github runners - Docker images can take up quite some space
- name: Free Disk Space
run: |
echo "Disk space before cleanup:"
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
echo "Disk space after cleanup:"
df -h
# 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
git log -1
# Unity 2020 cache is not compatible with older versions
- name: Unity Library Cache 2020 or higher
if: ${{ !startsWith(inputs.unityVersion, '201') }}
uses: actions/cache@v4
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@v4
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
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if [[ "$BRANCH_NAME" == *"urp"* ]]
then
echo "NAME=$LAST_UNITY_VERSION-urp" >> $GITHUB_OUTPUT
else
echo "NAME=$LAST_UNITY_VERSION" >> $GITHUB_OUTPUT
fi
- name: Set upgrade name
id: upgrade_name
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
if [[ "$BRANCH_NAME" == *"urp"* ]]
then
echo "NAME=$UNITY_VERSION-urp" >> $GITHUB_OUTPUT
else
echo "NAME=$UNITY_VERSION" >> $GITHUB_OUTPUT
fi
env:
UNITY_VERSION: ${{ inputs.unityVersion }}
- name: Log variables
run: |
echo "last_unity_version -> ${{ steps.last_unity_version.outputs.VERSION }}"
echo "last_unity_name -> ${{ steps.last_unity_version.outputs.NAME }}"
echo "upgrade_name -> ${{ steps.upgrade_name.outputs.NAME }}"
- name: Build project
if: ${{ !inputs.tagsOnly }}
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
buildMethod: UnityBuilderAction.UnityPackageScripts.UpgradeAllPackagesToVerifiedVersion
customParameters: ${{ inputs.customParameters }}
unityVersion: ${{ inputs.unityVersion }}
targetPlatform: WebGL
buildName: ${{ steps.upgrade_name.outputs.NAME }}
allowDirtyBuild: true
manualExit: true
- name: Check Disk Space After Build
if: ${{ !inputs.tagsOnly }}
run: |
echo "Disk space after build:"
df -h
AVAILABLE=$(df / | tail -1 | awk '{print $4}')
AVAILABLE_GB=$(echo $AVAILABLE | sed 's/G//')
echo "Available space: ${AVAILABLE_GB}GB"
if (( $(echo "$AVAILABLE_GB < 1" | bc -l) )); then
echo "::warning::Low disk space! Less than 1GB remaining."
fi
- 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/render-template@v1.9
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.NAME}} to ${{ inputs.unityVersion }}"
branch: "ci/upgrade-unity/from-${{steps.last_unity_version.outputs.NAME}}-to-${{ steps.upgrade_name.outputs.NAME }}"
delete-branch: true
title: "[Automated workflow] upgrade-unity from ${{steps.last_unity_version.outputs.NAME}} to ${{ steps.upgrade_name.outputs.NAME }}"
body: ${{ steps.template.outputs.result }}
- name: Add tags
if: ${{ inputs.createTags || inputs.tagsOnly }}
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
IS_URP=false
if [[ "$BRANCH_NAME" == *"urp"* ]]; then
IS_URP=true
fi
# Run add tags script with delay parameter
./.github/scripts/add-tags.sh "$UNITY_VERSION" "$IS_URP" "$DELAY_TAGS"
env:
UNITY_VERSION: ${{ inputs.unityVersion }}
DELAY_TAGS: ${{ inputs.delayTags }}