1
1
name : Unity WebGL Automatic Build 👽✨🚀
2
-
3
2
on :
4
- push :
5
- branches :
6
- - ' 1-configure-as-a-unity-package '
3
+ # push:
4
+ # branches:
5
+ # - 'main '
7
6
pull_request :
8
- branches :
7
+ branches :
9
8
- ' main'
10
9
workflow_dispatch :
11
-
12
10
permissions :
13
- contents : write
11
+ contents : read
14
12
pages : write
15
13
id-token : write
16
-
17
14
concurrency :
18
15
group : " pages"
19
16
cancel-in-progress : false
20
-
21
17
jobs :
22
18
build :
23
19
name : Unity Build 👽
24
20
runs-on : ubuntu-latest
25
21
steps :
26
- # 1. Checkout repository
22
+ # Checkout (without LFS)
27
23
- name : Checkout repository
28
- uses : actions/checkout@v3
24
+ uses : actions/checkout@v2
25
+ with :
26
+ token : ${{secrets.PAT}}
27
+ # Git LFS
28
+ - name : Create LFS file list
29
+ run : git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
29
30
30
- # 2. Set up Git LFS
31
- - name : Set up Git LFS
31
+ - name : Restore LFS cache
32
+ uses : actions/cache@v2
33
+ id : lfs-cache
34
+ with :
35
+ path : .git/lfs
36
+ key : ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
37
+
38
+ - name : Git LFS Pull
32
39
run : |
33
- git lfs install
34
40
git lfs pull
41
+ git add .
42
+ git reset --hard
35
43
36
- # 3. Cache Unity Library
37
- - uses : actions/cache@v3
44
+ # # Cache
45
+ - uses : actions/cache@v2
38
46
with :
39
47
path : Library
40
48
key : Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
41
49
restore-keys : |
42
50
Library-
43
51
44
- # 4. Build project using Unity Docker
45
- - name : Build WebGL with Unity
46
- run : |
47
- docker pull unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0
48
-
49
- docker run --rm \
50
- -v ${{ github.workspace }}:/workspace \
51
- -e UNITY_LICENSE=$UNITY_LICENSE \
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
-
52
+ # # Build
53
+ - name : Build project
54
+ uses : game-ci/unity-builder@v2
55
55
env :
56
56
UNITY_LICENSE : ${{ secrets.UNITY_LICENSE }}
57
-
58
- # 5. Upload build artifact
59
- - name : Upload WebGL Build
60
- uses : actions/upload-artifact@v3
57
+ UNITY_EMAIL : ${{ secrets.UNITY_EMAIL }}
58
+ UNITY_PASSWORD : ${{ secrets.UNITY_PASSWORD }}
61
59
with :
62
- name : WebGL-Build
63
- path : Build/WebGL/
64
-
65
- # 6. Deploy to GitHub Pages
66
- - name : Deploy to GitHub Pages
67
- uses : peaceiris/ actions-gh-pages @v3
60
+ targetPlatform : ${{ vars.TARGET_PLATFORM }}
61
+ buildsPath : ${{ vars.BUILD_PATH }}
62
+ allowDirtyBuild : true
63
+ # Output: Artifact
64
+ - name : Upload Build Artifact
65
+ uses : actions/upload-artifact @v3
68
66
with :
69
- github_token : ${{ secrets.GITHUB_TOKEN }}
70
- publish_dir : Build/WebGL/
71
- publish_branch : gh-pages
67
+ name : ${{ vars.ARTIFACT_NAME }}
68
+ path : ${{ vars.BUILD_PATH }}
69
+ # Deployment
70
+ - name : Stash build result and reset local changes
71
+ run : |
72
+ echo "Applying initial configs"
73
+ sudo chown -R $USER:$USER ${{ vars.BUILD_PATH }}
74
+ git config --global user.email "${{ secrets.GH_EMAIL }}"
75
+ git config --global user.name "${{ secrets.GH_USERNAME }}"
76
+ echo "Stash and reset"
77
+ git add ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }}
78
+ git stash push ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }}
79
+ git stash list
80
+ git reset --hard
81
+ sudo git clean -d -x -f
82
+ # Deployment
83
+ - name : Cleaning gh-pages branch
84
+ run : |
85
+ echo "Switch to ${{ vars.DEPLOYMENT_BRANCH }}"
86
+ git switch -f ${{ vars.DEPLOYMENT_BRANCH }}
87
+ git reset --hard
88
+ sudo git clean -d -x -f
89
+ rm -r *
90
+ git add *
91
+ git commit -m "cleaning branch"
92
+ git push
93
+ - name : Applying stashed files to ${{ vars.DEPLOYMENT_BRANCH }}
94
+ run : |
95
+ echo "Applying stash"
96
+ git stash apply stash@{0}
97
+ - name : Copying files to root directory
98
+ run : |
99
+ cd ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }}/${{ vars.TARGET_PLATFORM }}
100
+ ls
101
+ cp -r * ../../../
102
+ cd ../../../
103
+ rm -r ${{ vars.BUILD_PATH }}
104
+ ls
105
+ pwd
106
+ - name : Pushing deployment to gh-pages branch
107
+ run : |
108
+ pwd
109
+ git status
110
+ git add *
111
+ git commit -m "Deployment"
112
+ git push
113
+ git reset --hard
114
+ sudo git clean -d -x -f
0 commit comments