1
1
name : Unity WebGL Automatic Build 👽✨🚀
2
2
3
3
on :
4
- push :
5
- branches :
6
- - ' 1-configure-as-a-unity-package'
7
4
pull_request :
8
5
branches :
9
6
- ' main'
@@ -23,77 +20,92 @@ jobs:
23
20
name : Unity Build 👽
24
21
runs-on : ubuntu-latest
25
22
steps :
26
-
27
- # Step 1: Checkout the repository
23
+ # Step 1: Checkout repository without LFS
28
24
- name : Checkout repository
29
- uses : actions/checkout@v3
25
+ uses : actions/checkout@v2
30
26
with :
31
27
token : ${{ secrets.PAT }}
32
28
33
- # Step 2: Stash any local changes (if needed) and apply them later if necessary
34
- - name : Stash any local changes (if needed)
35
- run : |
36
- echo "Stashing local changes"
37
- git stash push --include-untracked
29
+ # Step 2: Git LFS: Restore LFS files
30
+ - name : Create LFS file list
31
+ run : git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
38
32
39
- # Step 3: Pull the latest changes from main
40
- - name : Pull latest changes from main
33
+ - name : Restore LFS cache
34
+ uses : actions/cache@v2
35
+ id : lfs-cache
36
+ with :
37
+ path : .git/lfs
38
+ key : ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
39
+
40
+ - name : Git LFS Pull
41
41
run : |
42
- echo "Pulling latest changes from main"
43
- git pull origin main --no-rebase
42
+ git lfs pull
43
+ git add .
44
+ git reset --hard
45
+
46
+ # Step 3: Cache Unity Library
47
+ - uses : actions/cache@v2
48
+ with :
49
+ path : Library
50
+ key : Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
51
+ restore-keys : |
52
+ Library-
44
53
45
- # Step 4: Pull Unity image and build the project using Unity Builder
54
+ # Step 4: Build Unity Project
46
55
- name : Build project
47
- run : |
48
- docker pull unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0
49
- docker run --rm \
50
- -v $GITHUB_WORKSPACE:/workspace \
51
- -e UNITY_LICENSE=$UNITY_LICENSE \
52
- -e UNITY_EMAIL=$UNITY_EMAIL \
53
- -e UNITY_PASSWORD=$UNITY_PASSWORD \
54
- -e UNITY_SERIAL=$UNITY_SERIAL \
55
- -e UNITY_VERSION=2022.3.10f1 \
56
- -e BUILD_PATH=$BUILD_PATH \
57
- -e BUILD_NAME=WebGL \
58
- -e BUILD_TARGET=WebGL \
59
- unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0 /bin/bash -c "/workspace/entrypoint.sh"
56
+ uses : game-ci/unity-builder@v2
60
57
env :
61
58
UNITY_LICENSE : ${{ secrets.UNITY_LICENSE }}
62
59
UNITY_EMAIL : ${{ secrets.UNITY_EMAIL }}
63
60
UNITY_PASSWORD : ${{ secrets.UNITY_PASSWORD }}
64
- UNITY_SERIAL : ${{ secrets.UNITY_SERIAL }}
65
- BUILD_PATH : ${{ secrets.BUILD_PATH }}
66
- GITHUB_WORKSPACE : ${{ github.workspace }}
61
+ with :
62
+ targetPlatform : ${{ vars.TARGET_PLATFORM }}
63
+ buildsPath : ${{ vars.BUILD_PATH }}
64
+ allowDirtyBuild : true
67
65
68
- # Step 5: Upload build artifact
66
+ # Step 5: Upload Build Artifact
69
67
- name : Upload Build Artifact
70
- uses : actions/upload-artifact@v3
68
+ uses : actions/upload-artifact@v2
71
69
with :
72
- name : build-artifact
73
- path : ${{ secrets.BUILD_PATH }}
70
+ name : ${{ vars.ARTIFACT_NAME }}
71
+ path : ${{ vars.BUILD_PATH }}
72
+
73
+ # Step 6: Stash the build result and reset local changes
74
+ - name : Stash build result and reset local changes
75
+ run : |
76
+ echo "Stashing build result and resetting local changes"
77
+ sudo chown -R $USER:$USER ${{ vars.BUILD_PATH }}
78
+ git config --global user.email "${{ secrets.GH_EMAIL }}"
79
+ git config --global user.name "${{ secrets.GH_USERNAME }}"
80
+ git add ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }}
81
+ git stash push ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }}
82
+ git reset --hard
83
+ sudo git clean -d -x -f
74
84
75
- # Step 6 : Checkout the gh-pages branch
85
+ # Step 7 : Checkout gh-pages branch
76
86
- name : Checkout gh-pages branch
77
87
run : |
78
88
echo "Switching to gh-pages branch"
79
- git checkout ${ secrets.DEPLOYMENT_BRANCH }
89
+ git switch -f ${{ secrets.DEPLOYMENT_BRANCH }}
90
+ git reset --hard
91
+ sudo git clean -d -x -f
80
92
81
- # Step 7 : Apply the stashed changes to the gh-pages branch
93
+ # Step 8 : Apply stashed changes to gh-pages branch
82
94
- name : Apply stashed changes to gh-pages
83
95
run : |
84
96
echo "Applying stashed changes to gh-pages"
85
- git stash apply
86
- git add -A
97
+ git stash apply stash@{0}
98
+ git add *
87
99
git commit -m "Deploying latest build to gh-pages"
88
100
89
- # Step 8 : Push the changes to gh-pages
101
+ # Step 9 : Push changes to gh-pages branch
90
102
- name : Push changes to gh-pages branch
91
103
run : |
92
104
echo "Pushing changes to gh-pages branch"
93
- git push origin ${ secrets.DEPLOYMENT_BRANCH }
105
+ git push origin ${{ secrets.DEPLOYMENT_BRANCH } }
94
106
95
- # Step 9 : Clean up: Delete stashed changes (if any)
107
+ # Step 10 : Clean up: Delete stashed changes (if any)
96
108
- name : Clean up stashed changes
97
109
run : |
98
- echo "Cleaning up stashed changes (if any) "
110
+ echo "Cleaning up stashed changes"
99
111
git stash clear
0 commit comments