@@ -28,62 +28,43 @@ jobs:
2828 uses : actions/checkout@v3
2929 with :
3030 token : ${{ secrets.PAT }}
31-
31+
3232 - name : Echo Checkout Completed
3333 run : echo "Repository has been successfully checked out."
3434
35- # Git LFS Cache and Pull Job
36- lfs :
37- name : Git LFS Setup and Pull
35+ # Create Temporary Branch and Sync with Main Job
36+ sync-main :
37+ name : Sync Temp Branch with Main
3838 runs-on : ubuntu-22.04
3939 needs : checkout # This job depends on the "checkout" job
4040 steps :
41- - name : Create LFS file list
42- run : git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
41+ - name : Checkout deployment branch
42+ run : |
43+ echo "Checking out deployment branch: ${{ secrets.DEPLOYMENT_BRANCH }}"
44+ git checkout ${{ secrets.DEPLOYMENT_BRANCH }}
4345
44- - name : Restore LFS cache
45- uses : actions/cache@v3
46- id : lfs-cache
47- with :
48- path : .git/lfs
49- key : ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
50- restore-keys : |
51- ${{ runner.os }}-lfs-
52-
53- - name : Git LFS Pull
46+ - name : Create temporary branch
5447 run : |
55- git lfs pull
56- git add .
57- git reset --hard
58-
59- - name : Echo LFS Pull Completed
60- run : echo "Git LFS has been pulled and reset successfully."
61-
62- # Cache Unity Library Job
63- cache-library :
64- name : Unity Library Cache
65- runs-on : ubuntu-22.04
66- needs : lfs # This job depends on the "lfs" job
67- steps :
68- - uses : actions/cache@v3
69- with :
70- path : Library
71- key : Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
72- restore-keys : |
73- Library-
48+ echo "Creating temporary branch from ${{ secrets.DEPLOYMENT_BRANCH }}"
49+ git checkout -b temp
50+
51+ - name : Pull latest changes from main
52+ run : |
53+ echo "Pulling latest changes from main"
54+ git pull origin main
7455
75- - name : Echo Unity Library Cache Completed
76- run : echo "Unity Library has been successfully cached ."
56+ - name : Echo Sync Main Completed
57+ run : echo "Temporary branch has been successfully synced with main ."
7758
78- # Build Project Job
59+ # Build Unity Project Job
7960 build :
8061 name : Build Unity Project
8162 runs-on : ubuntu-22.04
82- needs : cache-library # This job depends on the "cache-library " job
63+ needs : sync-main # This job depends on the "sync-main " job
8364 steps :
8465 - name : Pull Unity Image and Build Project
8566 run : |
86- echo "Starting to pull Unity image and build project "
67+ echo "Starting Unity build"
8768 docker pull unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0
8869 docker run --rm \
8970 -v $GITHUB_WORKSPACE:/workspace \
@@ -100,83 +81,56 @@ jobs:
10081 - name : Echo Build Completed
10182 run : echo "Unity build has completed successfully."
10283
103- # Upload Build Artifact Job
104- upload :
105- name : Upload Build Artifact
84+ # Deploy to GitHub Pages Job
85+ deploy :
86+ name : Deploy to GitHub Pages and Upload Artifact
10687 runs-on : ubuntu-22.04
10788 needs : build # This job depends on the "build" job
10889 steps :
90+ - name : Checkout Deployment Branch
91+ run : |
92+ echo "Checking out deployment branch: ${{ secrets.DEPLOYMENT_BRANCH }}"
93+ git checkout ${{ secrets.DEPLOYMENT_BRANCH }}
94+
95+ - name : Merge Temp Branch to Deployment Branch
96+ run : |
97+ echo "Merging changes from temp to deployment branch"
98+ git merge temp --no-ff --commit -m "Merge build changes into deployment branch"
99+
100+ - name : Push Changes to Deployment Branch
101+ run : |
102+ echo "Pushing changes to deployment branch"
103+ git push origin ${{ secrets.DEPLOYMENT_BRANCH }}
104+
109105 - name : Upload Build Artifact
110106 uses : actions/upload-artifact@v3
111107 with :
112108 name : build-artifact
113109 path : ${{ secrets.BUILD_PATH }}
114-
115- - name : Echo Upload Completed
116- run : echo "Build artifact has been uploaded successfully."
117-
118- # Stash and Reset Job
119- stash-reset :
120- name : Stash Build Result and Reset Local Changes
121- runs-on : ubuntu-22.04
122- needs : upload # This job depends on the "upload" job
123- steps :
124- - name : Stash build result and reset local changes
110+
111+ - name : Deploy to GitHub Pages
125112 run : |
126- echo "Applying initial configs"
127- sudo chown -R $USER:$USER ${{ secrets.BUILD_PATH }}
128- git config --global user.email "${{ secrets.GH_EMAIL }}"
129- git config --global user.name "${{ secrets.GH_USERNAME }}"
130- git add ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}
131- git stash push ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}
132- git reset --hard
133- sudo git clean -d -x -f
134-
135- - name : Echo Stash and Reset Completed
136- run : echo "Build result has been stashed and local changes have been reset."
113+ echo "Deploying to GitHub Pages"
114+ # Any deployment script or commands you need for GitHub Pages here.
115+
116+ - name : Echo Deployment Completed
117+ run : echo "Deployment to GitHub Pages has been successfully completed."
137118
138- # Clean and Deploy Job
139- deploy :
140- name : Clean and Deploy to gh-pages
119+ # Clean Temporary Branch Job
120+ cleanup :
121+ name : Clean Up Temporary Branch
141122 runs-on : ubuntu-22.04
142- needs : stash-reset # This job depends on the "stash-reset " job
123+ needs : deploy # This job depends on the "deploy " job
143124 steps :
144- - name : Cleaning gh-pages branch
145- run : |
146- echo "Switching to the deployment branch: ${{ secrets.DEPLOYMENT_BRANCH }}"
147- git switch -f ${{ secrets.DEPLOYMENT_BRANCH }}
148- git reset --hard
149- sudo git clean -d -x -f
150- rm -r *
151- git add *
152- git commit -m "cleaning branch"
153- git push
154-
155- - name : Applying stashed files to gh-pages
156- run : |
157- echo "Applying stashed files to gh-pages"
158- git stash apply stash@{0}
159-
160- - name : Copying files to root directory
125+ - name : Delete Temporary Branch
161126 run : |
162- cd ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}/${{ secrets.TARGET_PLATFORM }}
163- ls
164- cp -r * ../../../
165- cd ../../../
166- rm -r ${{ secrets.BUILD_PATH }}
167- ls
168- pwd
169-
170- - name : Pushing deployment to gh-pages branch
127+ echo "Deleting temporary branch"
128+ git branch -D temp
129+
130+ - name : Push Cleanup
171131 run : |
172- echo "Pushing deployment to gh-pages branch"
173- pwd
174- git status
175- git add *
176- git commit -m "Deployment"
177- git push
178- env :
179- GH_TOKEN : ${{ secrets.PAT }} # Use the authentication token for git push
132+ echo "Cleaning up remote branches"
133+ git push origin --delete temp
180134
181- - name : Echo Deployment Completed
182- run : echo "Deployment to gh-pages branch has been successfully completed ."
135+ - name : Echo Cleanup Completed
136+ run : echo "Temporary branch has been deleted ."
0 commit comments