Skip to content

Commit fccfba8

Browse files
hackall360claude
andcommitted
Fix: Prevent develop deployments from overwriting main site
The previous deployment strategy was overwriting the main site when deploying from develop branch. This fix implements a targeted approach: - Develop branch: Only updates /development/ folder, preserves everything else - Main branch: Updates root files, preserves CNAME and /development/ folder - Checks out gh-pages branch first for surgical updates - No more using peaceiris action that was causing overwrites This ensures: ✅ www.unityailab.com stays intact when deploying develop ✅ www.unityailab.com/development/ updates independently ✅ CNAME file is always preserved ✅ Each branch only touches its designated area 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6f34389 commit fccfba8

File tree

1 file changed

+59
-17
lines changed

1 file changed

+59
-17
lines changed

.github/workflows/deploy.yml

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ jobs:
154154
if: needs.build.outputs.build_status == 'success'
155155

156156
steps:
157-
- name: Checkout code
157+
- name: Checkout gh-pages branch
158158
uses: actions/checkout@v4
159+
with:
160+
ref: gh-pages
161+
path: gh-pages-repo
159162

160163
- name: Download build artifact
161164
uses: actions/download-artifact@v4
@@ -167,32 +170,71 @@ jobs:
167170
run: |
168171
cd artifact
169172
tar -xf artifact.tar
173+
mkdir -p ../dist
170174
mv -f * ../dist/ 2>/dev/null || true
171175
cd ..
172176
rm -rf artifact
173177
174-
- name: Determine deployment path
178+
- name: Determine deployment path and update files
175179
id: deploy-path
176180
run: |
177181
if [ "${{ github.ref_name }}" == "develop" ]; then
178-
echo "path=development" >> $GITHUB_OUTPUT
179-
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/development/" >> $GITHUB_OUTPUT
180-
echo "📍 Deploying to /development/ subdirectory"
182+
echo "📍 Deploying develop branch to /development/ subdirectory"
183+
echo "url=https://www.unityailab.com/development/" >> $GITHUB_OUTPUT
184+
185+
# Remove old development folder and copy new build
186+
rm -rf gh-pages-repo/development
187+
mkdir -p gh-pages-repo/development
188+
cp -r dist/* gh-pages-repo/development/
189+
190+
echo "✅ Updated /development/ folder only"
181191
else
182-
echo "path=." >> $GITHUB_OUTPUT
183-
echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" >> $GITHUB_OUTPUT
184-
echo "📍 Deploying to root directory"
192+
echo "📍 Deploying main branch to root directory"
193+
echo "url=https://www.unityailab.com/" >> $GITHUB_OUTPUT
194+
195+
# Preserve CNAME and development folder
196+
if [ -f "gh-pages-repo/CNAME" ]; then
197+
cp gh-pages-repo/CNAME /tmp/CNAME
198+
echo "💾 Preserved CNAME file"
199+
fi
200+
201+
if [ -d "gh-pages-repo/development" ]; then
202+
mv gh-pages-repo/development /tmp/development
203+
echo "💾 Preserved /development/ folder"
204+
fi
205+
206+
# Clear root and copy new build
207+
rm -rf gh-pages-repo/*
208+
cp -r dist/* gh-pages-repo/
209+
210+
# Restore preserved files
211+
if [ -f "/tmp/CNAME" ]; then
212+
mv /tmp/CNAME gh-pages-repo/CNAME
213+
echo "♻️ Restored CNAME file"
214+
fi
215+
216+
if [ -d "/tmp/development" ]; then
217+
mv /tmp/development gh-pages-repo/development
218+
echo "♻️ Restored /development/ folder"
219+
fi
220+
221+
echo "✅ Updated root files while preserving /development/"
185222
fi
186223
187-
- name: Deploy to GitHub Pages
188-
uses: peaceiris/actions-gh-pages@v4
189-
with:
190-
github_token: ${{ secrets.GITHUB_TOKEN }}
191-
publish_dir: ./dist
192-
destination_dir: ${{ steps.deploy-path.outputs.path }}
193-
keep_files: true
194-
user_name: 'github-actions[bot]'
195-
user_email: 'github-actions[bot]@users.noreply.github.com'
224+
- name: Commit and push to gh-pages
225+
run: |
226+
cd gh-pages-repo
227+
git config user.name 'github-actions[bot]'
228+
git config user.email 'github-actions[bot]@users.noreply.github.com'
229+
git add -A
230+
231+
if git diff --staged --quiet; then
232+
echo "No changes to deploy"
233+
else
234+
git commit -m "Deploy from ${{ github.ref_name }} branch - $(date +'%Y-%m-%d %H:%M:%S')"
235+
git push origin gh-pages
236+
echo "✅ Deployed successfully"
237+
fi
196238
197239
- name: Report deployment success
198240
run: |

0 commit comments

Comments
 (0)