@@ -3,15 +3,14 @@ name: Unity WebGL Automatic Build 👽✨🚀
33on :
44 push :
55 branches :
6- # - 'main'
76 - ' 1-configure-as-a-unity-package'
87 pull_request :
98 branches :
109 - ' main'
1110 workflow_dispatch :
1211
1312permissions :
14- contents : read
13+ contents : write
1514 pages : write
1615 id-token : write
1716
@@ -24,116 +23,49 @@ jobs:
2423 name : Unity Build 👽
2524 runs-on : ubuntu-latest
2625 steps :
27- # Checkout repository
26+ # 1. Checkout repository
2827 - 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
4529
46- - name : Git LFS Pull
30+ # 2. Set up Git LFS
31+ - name : Set up Git LFS
4732 run : |
33+ git lfs install
4834 git lfs pull
49- git add .
50- git reset --hard
5135
52- # Cache Unity Library
53- - uses : actions/cache@v2
36+ # 3. Cache Unity Library
37+ - uses : actions/cache@v3
5438 with :
5539 path : Library
5640 key : Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
5741 restore-keys : |
5842 Library-
5943
60- # Build project
61- - name : Build project
44+ # 4. Build project using Unity Docker
45+ - name : Build WebGL with Unity
6246 run : |
63- docker rmi $(docker images -q)
6447 docker pull unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0
6548
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
7049 docker run --rm \
71- -v $GITHUB_WORKSPACE :/workspace \
50+ -v ${{ github.workspace }} :/workspace \
7251 -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+
8155 env :
8256 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 }}
8857
89- # Upload build artifact
90- - name : Upload Build Artifact
58+ # 5. Upload build artifact
59+ - name : Upload WebGL Build
9160 uses : actions/upload-artifact@v3
9261 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/
10964
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