@@ -3,15 +3,14 @@ name: Unity WebGL Automatic Build 👽✨🚀
3
3
on :
4
4
push :
5
5
branches :
6
- # - 'main'
7
6
- ' 1-configure-as-a-unity-package'
8
7
pull_request :
9
8
branches :
10
9
- ' main'
11
10
workflow_dispatch :
12
11
13
12
permissions :
14
- contents : read
13
+ contents : write
15
14
pages : write
16
15
id-token : write
17
16
@@ -24,116 +23,49 @@ jobs:
24
23
name : Unity Build 👽
25
24
runs-on : ubuntu-latest
26
25
steps :
27
- # Checkout repository
26
+ # 1. Checkout repository
28
27
- name : Checkout repository
29
- uses : actions/checkout@v2
30
- with :
31
- token : ${{ secrets.PAT }}
32
-
33
- # Git LFS: Create file list and restore cache
34
- - name : Create LFS file list
35
- run : git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
36
-
37
- - name : Restore LFS cache
38
- uses : actions/cache@v2
39
- id : lfs-cache
40
- with :
41
- path : .git/lfs
42
- key : ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
43
- restore-keys : |
44
- ${{ runner.os }}-lfs-
28
+ uses : actions/checkout@v3
45
29
46
- - name : Git LFS Pull
30
+ # 2. Set up Git LFS
31
+ - name : Set up Git LFS
47
32
run : |
33
+ git lfs install
48
34
git lfs pull
49
- git add .
50
- git reset --hard
51
35
52
- # Cache Unity Library
53
- - uses : actions/cache@v2
36
+ # 3. Cache Unity Library
37
+ - uses : actions/cache@v3
54
38
with :
55
39
path : Library
56
40
key : Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
57
41
restore-keys : |
58
42
Library-
59
43
60
- # Build project
61
- - name : Build project
44
+ # 4. Build project using Unity Docker
45
+ - name : Build WebGL with Unity
62
46
run : |
63
- docker rmi $(docker images -q)
64
47
docker pull unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0
65
48
66
- # Verify that entrypoint.sh exists in the container
67
- docker run --rm unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0 /bin/bash -c "ls -l /workspace"
68
-
69
- # Run Unity build process
70
49
docker run --rm \
71
- -v $GITHUB_WORKSPACE :/workspace \
50
+ -v ${{ github.workspace }} :/workspace \
72
51
-e UNITY_LICENSE=$UNITY_LICENSE \
73
- -e UNITY_EMAIL=$UNITY_EMAIL \
74
- -e UNITY_PASSWORD=$UNITY_PASSWORD \
75
- -e UNITY_SERIAL=$UNITY_SERIAL \
76
- -e UNITY_VERSION=2022.3.10f1 \
77
- -e BUILD_PATH=$BUILD_PATH \
78
- -e BUILD_NAME=WebGL \
79
- -e BUILD_TARGET=WebGL \
80
- unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0 /bin/bash -c "/workspace/entrypoint.sh"
52
+ unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0 \
53
+ /bin/bash -c "/opt/unity/Editor/Unity -batchmode -nographics -quit -buildTarget WebGL -projectPath /workspace -executeMethod BuildPipeline.BuildPlayer"
54
+
81
55
env :
82
56
UNITY_LICENSE : ${{ secrets.UNITY_LICENSE }}
83
- UNITY_EMAIL : ${{ secrets.UNITY_EMAIL }}
84
- UNITY_PASSWORD : ${{ secrets.UNITY_PASSWORD }}
85
- UNITY_SERIAL : ${{ secrets.UNITY_SERIAL }}
86
- BUILD_PATH : ${{ secrets.BUILD_PATH }}
87
- GITHUB_WORKSPACE : ${{ github.workspace }}
88
57
89
- # Upload build artifact
90
- - name : Upload Build Artifact
58
+ # 5. Upload build artifact
59
+ - name : Upload WebGL Build
91
60
uses : actions/upload-artifact@v3
92
61
with :
93
- name : WebGL-Build-Artifact
94
- path : ${{ secrets.BUILD_PATH }}
95
-
96
- # Stash build result and reset local changes
97
- - name : Stash build result and reset local changes
98
- run : |
99
- echo "Applying initial configs"
100
- sudo chown -R $USER:$USER ${{ secrets.BUILD_PATH }}
101
- git config --global user.email "${{ secrets.GH_EMAIL }}"
102
- git config --global user.name "${{ secrets.GH_USERNAME }}"
103
- echo "Stash and reset"
104
- git add ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}
105
- git stash push ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}
106
- git stash list
107
- git reset --hard
108
- sudo git clean -d -x -f
62
+ name : WebGL-Build
63
+ path : Build/WebGL/
109
64
110
- # Apply stashed files to gh-pages branch
111
- - name : Switch to gh-pages branch and apply build artifact
112
- run : |
113
- echo "Switch to gh-pages branch"
114
- git switch -f ${{ secrets.DEPLOYMENT_BRANCH }}
115
- git reset --hard
116
- sudo git clean -d -x -f
117
- git add *
118
- git commit -m "Cleaning gh-pages branch"
119
- git push
120
-
121
- - name : Apply stashed files to gh-pages branch
122
- run : |
123
- echo "Applying stash"
124
- git stash apply stash@{0}
125
-
126
- # Copy build result to root directory
127
- - name : Copying files to root directory
128
- run : |
129
- cd ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}/${{ secrets.TARGET_PLATFORM }}
130
- cp -r * ../../../
131
- cd ../../../
132
- rm -r ${{ secrets.BUILD_PATH }}
133
-
134
- # Push deployment to gh-pages branch
135
- - name : Push deployment to gh-pages branch
136
- run : |
137
- git add *
138
- git commit -m "Deployment to gh-pages"
139
- git push
65
+ # 6. Deploy to GitHub Pages
66
+ - name : Deploy to GitHub Pages
67
+ uses : peaceiris/actions-gh-pages@v3
68
+ with :
69
+ github_token : ${{ secrets.GITHUB_TOKEN }}
70
+ publish_dir : Build/WebGL/
71
+ publish_branch : gh-pages
0 commit comments