forked from Rezmason/matrix
-
Notifications
You must be signed in to change notification settings - Fork 0
234 lines (194 loc) · 8.55 KB
/
Copy pathgh-pages-deploy.yml
File metadata and controls
234 lines (194 loc) · 8.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
name: Deploy to GitHub Pages
# Deploy the main site to the root of gh-pages branch
# This keeps the live site updated with the latest master branch
on:
# Trigger on pushes to master
push:
branches:
- master
# Allow manual trigger
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
jobs:
deploy-main-site:
name: Deploy Main Site to gh-pages
runs-on: ubuntu-latest
steps:
- name: Checkout master branch
uses: actions/checkout@v6
with:
ref: master
fetch-depth: 1
submodules: false
- name: Checkout gh-pages branch
uses: actions/checkout@v6
with:
ref: gh-pages
path: gh-pages
# Need full history for reliable sync; shallow tip alone races with PR preview deploys.
fetch-depth: 0
continue-on-error: true
- name: Initialize gh-pages if needed
run: |
if [ ! -d "gh-pages/.git" ]; then
echo "Creating new gh-pages branch"
rm -rf gh-pages
mkdir -p gh-pages
cd gh-pages
git init
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b gh-pages
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
else
echo "gh-pages branch exists"
cd gh-pages
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
fi
# PR previews land on gh-pages in parallel. Without resetting to the remote tip here, this job
# can build from a stale checkout and `git push --force` would delete pr-* directories (404 on /matrix/pr-N/).
- name: Sync gh-pages to origin tip
run: |
if [ ! -d "gh-pages/.git" ]; then
echo "No gh-pages repo; skip sync"
exit 0
fi
cd gh-pages
git remote set-url origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" 2>/dev/null || \
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
if git fetch origin gh-pages 2>/dev/null; then
git reset --hard origin/gh-pages
echo "✅ gh-pages working tree = origin/gh-pages (includes pr-* / previews / v*)"
else
echo "⚠️ Could not fetch origin/gh-pages (first deploy?); continuing with checkout state"
fi
- name: Clean root directory (preserve PR previews and version directories)
run: |
cd gh-pages
# Remove all files in root (but not directories)
find . -maxdepth 1 -type f ! -name '.gitignore' ! -name 'CNAME' -delete 2>/dev/null || true
# Remove application directories at root level
rm -rf assets js lib shaders gallery 2>/dev/null || true
# Preserve pr-* and v* directories (PR previews and version releases)
# Everything else at root gets replaced with fresh master content
echo "✅ Cleaned root directory (preserved pr-* and v* directories)"
ls -la
- name: Copy main site files to gh-pages root
run: |
# Copy essential web application files to gh-pages root
cp index.html gh-pages/
cp service-worker.js gh-pages/
cp manifest.webmanifest gh-pages/
cp icon-192.png gh-pages/
cp icon-512.png gh-pages/
cp VERSION gh-pages/
# Copy application directories
cp -r js gh-pages/
cp -r lib gh-pages/
cp -r assets gh-pages/
cp -r shaders gh-pages/
# Copy gallery directory if it exists
if [ -d "gallery" ]; then
cp -r gallery gh-pages/
else
mkdir -p gh-pages/gallery
fi
# Optional files (don't fail if missing)
cp README.md gh-pages/ 2>/dev/null || true
cp screenshot.png gh-pages/ 2>/dev/null || true
echo "✅ Main site files copied to gh-pages root"
ls -la gh-pages/
# Browsers only install a new SW when service-worker.js bytes change; VERSION alone is not enough.
- name: Stamp PWA deploy build (new cache + SW update each deploy)
run: |
VER="matrix-pwa-${GITHUB_RUN_NUMBER}-$(echo "$GITHUB_SHA" | cut -c1-7)"
sed -i "s|const VER = \"local\"|const VER = \"${VER}\"|" gh-pages/service-worker.js
echo "VER=${VER}"
- name: Update or create index page listing
run: |
cd gh-pages
# Create a versions list if we have version directories
VERSION_LINKS=""
for dir in v*/ ; do
if [ -d "$dir" ]; then
VERSION="${dir%/}"
VERSION_LINKS="${VERSION_LINKS}\n <li><a href=\"/${VERSION}/\">${VERSION}</a></li>"
fi
done
# Create a PR previews list
PR_LINKS=""
for dir in pr-*/ ; do
if [ -d "$dir" ]; then
PR="${dir%/}"
PR_LINKS="${PR_LINKS}\n <li><a href=\"/${PR}/\">${PR}</a></li>"
fi
done
# Create README for gh-pages branch
cat > README.md << 'MDEOF'
# Matrix Digital Rain - GitHub Pages
This branch hosts the GitHub Pages deployment for the Matrix Digital Rain project.
## Structure
- Root (/) - Latest code from master branch
- Version directories (/vX.Y.Z/) - Specific release versions
- PR previews (/pr-XX/) - Preview deployments for pull requests
## Links
- Main site - https://ap0ught.github.io/matrix/
- Repository - https://github.com/ap0ught/matrix
- Latest release - https://github.com/ap0ught/matrix/releases/latest
## Deployments
This branch is automatically updated by GitHub Actions workflows.
- Master branch pushes update the root
- Tagged releases create version directories
- Pull requests create preview directories
MDEOF
echo "✅ Created README.md for gh-pages"
- name: Commit and push to gh-pages
run: |
cd gh-pages
# Ensure git config is set
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Set up authentication
git remote set-url origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git" || \
git remote add origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
# Ensure we're on gh-pages branch
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")
if [ "$CURRENT_BRANCH" != "gh-pages" ]; then
git branch -M gh-pages
fi
# Stage all changes
git add .
# Check if there are changes
if git diff --staged --quiet; then
echo "No changes to deploy"
else
COMMIT_SHA="${GITHUB_SHA:0:7}"
git commit -m "Deploy main site from master@${COMMIT_SHA}"
if git push origin gh-pages; then
echo "✅ Successfully pushed main site to gh-pages"
else
echo "⚠️ Push rejected (concurrent gh-pages update); rebasing and retrying..."
git fetch origin gh-pages
git rebase origin/gh-pages
git push origin gh-pages
echo "✅ Successfully deployed main site to gh-pages after rebase"
fi
fi
- name: Summary
run: |
echo "## 🎉 Main Site Deployed to GitHub Pages!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Live URL:** https://ap0ught.github.io/matrix/" >> $GITHUB_STEP_SUMMARY
echo "**Source:** master@${GITHUB_SHA:0:7}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔗 Quick Links" >> $GITHUB_STEP_SUMMARY
echo "- [Main Site](https://ap0ught.github.io/matrix/)" >> $GITHUB_STEP_SUMMARY
echo "- [Classic Matrix](https://ap0ught.github.io/matrix/?suppressWarnings=true)" >> $GITHUB_STEP_SUMMARY
echo "- [3D Mode](https://ap0ught.github.io/matrix/?version=3d&suppressWarnings=true)" >> $GITHUB_STEP_SUMMARY
echo "- [Mirror Effect](https://ap0ught.github.io/matrix/?effect=mirror&suppressWarnings=true)" >> $GITHUB_STEP_SUMMARY