Repository navigation
215 lines (190 loc) · 8.41 KB
/
Copy pathrelease.yml
File metadata and controls
215 lines (190 loc) · 8.41 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
# Build and upload the project by pushing tags
name: Build project & release
on:
push:
tags:
- '*'
branches:
- master
jobs:
variables:
name: Define variables 🔗
runs-on: ubuntu-latest
outputs:
UNITY_VERSION: ${{ steps.set_unity_version.outputs.VERSION }}
TAG: ${{ steps.set_tag.outputs.VERSION }}
BUILD_NAME: ${{ steps.set_build_name.outputs.VERSION }}
steps:
- uses: actions/checkout@v7
with:
sparse-checkout: |
ProjectSettings/ProjectVersion.txt
- name: Set unity version
id: set_unity_version
run: |
UNITY_VERSION=$(sed -n 's/^\m_EditorVersion: //p'< ./ProjectSettings/ProjectVersion.txt)
echo "VERSION=$UNITY_VERSION" >> $GITHUB_OUTPUT
- name: Set tag
id: set_tag
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
else
echo "VERSION=${{ steps.set_unity_version.outputs.VERSION }}-webgl2-master" >> $GITHUB_OUTPUT
fi
- name: Set target name
id: set_build_name
run: echo "VERSION=WebGL-${{ steps.set_tag.outputs.VERSION }}" >> $GITHUB_OUTPUT
- name: Log variables
run: |
echo "UNITY_VERSION -> ${{ steps.set_unity_version.outputs.VERSION }}"
echo "TAG -> ${{ steps.set_tag.outputs.VERSION }}"
echo "BUILD_NAME -> ${{ steps.set_build_name.outputs.VERSION }}"
tagVersionMatchTest:
needs: [ variables ]
name: Check tag version match ☑
runs-on: ubuntu-latest
steps:
- name: Log tag and version
run: echo "Github tag '${{ needs.variables.outputs.TAG }}' has to start with unity version '${{ needs.variables.outputs.UNITY_VERSION }}'"
- name: Version match ✔
if: ${{ startsWith(needs.variables.outputs.TAG, needs.variables.outputs.UNITY_VERSION) }}
run: echo "Versions are matching 🥳"
- name: Version missmatch ❌
if: ${{ !startsWith(needs.variables.outputs.TAG, needs.variables.outputs.UNITY_VERSION) }}
uses: actions/github-script@v4
with:
script: |
core.setFailed('Unity version does not match tag version')
buildProject:
name: Create Unity WebGL Build 🏗
# Build if it's a master push or if the tag is not just the unity version
if: ${{ github.ref == 'refs/heads/master' || needs.variables.outputs.TAG != needs.variables.outputs.UNITY_VERSION }}
needs: [ variables ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
lfs: true
# 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
# Unity 2020 cache is not compatible with older versions
- name: Unity Library Cache 2020 or higher
if: ${{ !startsWith(needs.variables.outputs.UNITY_VERSION, '201') }}
uses: actions/cache@v6
with:
path: Library
key: Library-202x-WebGL
restore-keys: Library-202x-
- name: Unity Library Cache 2019 or lower
if: ${{ startsWith(needs.variables.outputs.UNITY_VERSION, '201') }}
uses: actions/cache@v6
with:
path: Library
key: Library-201x-WebGL
restore-keys: Library-201x-
- name: Build project
id: buildStep
# Exit code 101 is recoverable and handled by the retry step below, so don't fail the job yet
continue-on-error: true
uses: game-ci/unity-builder@v5
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
buildMethod: UnityBuilderAction.BuildScript.BuildWithCommandlineArgs
customParameters: -tag ${{ needs.variables.outputs.TAG }}
targetPlatform: WebGL
versioning: None
buildName: ${{ needs.variables.outputs.BUILD_NAME }}
# Unity's Bee backend caps buildprogram planning runs at 6, but a cold WebGL minsize build
# needs 7, so the first attempt dies one node short of finishing (BuildScript exits with 101).
# Library/Bee is warm afterwards, which collapses the run chain, so a second build succeeds.
- name: Retry build after Bee buildprogram run limit
if: steps.buildStep.outputs.engineExitCode == '101'
uses: game-ci/unity-builder@v5
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
buildMethod: UnityBuilderAction.BuildScript.BuildWithCommandlineArgs
customParameters: -tag ${{ needs.variables.outputs.TAG }}
targetPlatform: WebGL
versioning: None
buildName: ${{ needs.variables.outputs.BUILD_NAME }}
# Any other failure is not worth a second 15 minute build, so fail the job here
- name: Fail on unrecoverable build error
if: steps.buildStep.outcome == 'failure' && steps.buildStep.outputs.engineExitCode != '101'
run: |
echo "::error::Build failed with engineExitCode '${{ steps.buildStep.outputs.engineExitCode }}' - not retrying"
exit 1
- name: Check Disk Space After Build
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
- uses: actions/upload-artifact@v7
with:
name: ${{ needs.variables.outputs.BUILD_NAME }}
path: build/WebGL
createRelease:
name: Create Github release 🐙
# only run for the pure tag without build parameters
if: ${{ github.ref_type == 'tag' && needs.variables.outputs.TAG == needs.variables.outputs.UNITY_VERSION }}
needs: [ variables ]
runs-on: ubuntu-latest
steps:
- name: Create Release
uses: softprops/action-gh-release@v3
with:
body: |
## Changes
*
[${{ needs.variables.outputs.UNITY_VERSION }}-webgl2](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-webgl2/)
[${{ needs.variables.outputs.UNITY_VERSION }}-webgl1](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-webgl1/)
[${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl2 Demo](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl2/)
[${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl1 Demo](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl1/)
[${{ needs.variables.outputs.UNITY_VERSION }}-minsize-webgl1 Demo](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-minsize-webgl1/)
draft: true
deployOnServer:
name: Deploy on server 🚀
needs: [ variables, buildProject ]
# Guarded by username, you will need to remove or replace the line for your fork
if: ${{ github.repository_owner == 'JohannesDeml' }}
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v8
with:
name: ${{ needs.variables.outputs.BUILD_NAME }}
path: build
- name: Display structure of root files
run: ls -R
working-directory: build/${{ needs.variables.outputs.BUILD_NAME }}
- name: Deploy ⤴
uses: SamKirkland/FTP-Deploy-Action@v4.4.0
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USER }}
password: ${{ secrets.FTP_PASSWORD }}
port: 21
protocol: ftps
local-dir: ./build/${{ needs.variables.outputs.BUILD_NAME }}/
server-dir: ./${{ needs.variables.outputs.TAG }}/
# Make sure old files are deleted (e.g. created with name files as hashes)
dangerous-clean-slate: true