@@ -3,6 +3,12 @@ name: Build Wolfenstein 3D
33on :
44 - push
55 - pull_request
6+
7+ permissions :
8+ contents : write
9+ pages : write
10+ id-token : write
11+
612jobs :
713 build :
814 runs-on : ubuntu-latest
@@ -82,3 +88,160 @@ jobs:
8288 with :
8389 name : wolf3d-html
8490 path : wolf3d.html
91+
92+ deploy-demo :
93+ runs-on : ubuntu-latest
94+ needs : build
95+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
96+ steps :
97+ - name : Download build artifact
98+ uses : actions/download-artifact@v4.1.3
99+ with :
100+ name : build-dos
101+ path : WOLF3D
102+
103+ - name : Assert wolf3d.exe is present
104+ run : |
105+ echo "Files in WOLF3D/:"
106+ ls -la WOLF3D/
107+ if [ ! -f WOLF3D/wolf3d.exe ]; then
108+ echo "ERROR: wolf3d.exe not found in build artifact" >&2
109+ exit 1
110+ fi
111+
112+ - name : Create dosbox.conf for jsdos
113+ run : |
114+ cat > WOLF3D/dosbox.conf << 'EOF'
115+ [cpu]
116+ cycles=max
117+
118+ [autoexec]
119+ mount c .
120+ c:
121+ wolf3d.exe
122+ EOF
123+
124+ - name : Package hra.jsdos
125+ run : |
126+ cd WOLF3D
127+ zip -r ../hra.jsdos .
128+ cd ..
129+ echo "Created hra.jsdos ($(du -sh hra.jsdos | cut -f1))"
130+
131+ - name : Compute short SHA
132+ id : sha
133+ run : echo "short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
134+
135+ - name : Generate index.html
136+ run : |
137+ SHORT_SHA="${{ steps.sha.outputs.short }}"
138+ cat > index.html << EOF
139+ <!DOCTYPE html>
140+ <html lang="en">
141+ <head>
142+ <meta charset="UTF-8">
143+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
144+ <title>Wolfenstein 3D — build ${SHORT_SHA}</title>
145+ <link rel="stylesheet" href="https://js-dos.com/v8/js-dos.css">
146+ <script src="https://js-dos.com/v8/js-dos.js"></script>
147+ <style>
148+ * { box-sizing: border-box; margin: 0; padding: 0; }
149+ body { background: #111; color: #eee; font-family: Arial, sans-serif; display: flex; flex-direction: column; align-items: center; min-height: 100vh; padding: 20px; }
150+ h1 { margin-bottom: 12px; font-size: 1.4rem; }
151+ #dos { width: 800px; height: 600px; max-width: 100%; }
152+ .meta { margin-top: 10px; font-size: 0.8rem; color: #888; }
153+ button { margin-top: 10px; padding: 6px 16px; background: #333; color: #eee; border: 1px solid #555; cursor: pointer; border-radius: 4px; }
154+ button:hover { background: #444; }
155+ </style>
156+ </head>
157+ <body>
158+ <h1>Wolfenstein 3D</h1>
159+ <div id="dos"></div>
160+ <button onclick="document.getElementById('dos').requestFullscreen && document.getElementById('dos').requestFullscreen()">Full screen</button>
161+ <p class="meta">build ${SHORT_SHA} — <a href="https://github.com/luke-b/DosTest/commit/${GITHUB_SHA}" style="color:#888">view commit</a></p>
162+ <script>
163+ Dos(document.getElementById("dos"), {
164+ url: "./hra.jsdos",
165+ onprogress: (stage, total, loaded) => {
166+ if (stage === "Resolving DosBox") return;
167+ console.log(stage, loaded, "/", total);
168+ }
169+ });
170+ </script>
171+ </body>
172+ </html>
173+ EOF
174+
175+ - name : Generate latest redirect
176+ run : |
177+ SHORT_SHA="${{ steps.sha.outputs.short }}"
178+ mkdir -p latest-redirect
179+ cat > latest-redirect/index.html << EOF
180+ <!DOCTYPE html>
181+ <html>
182+ <head>
183+ <meta charset="UTF-8">
184+ <meta http-equiv="refresh" content="0; url=../${SHORT_SHA}/">
185+ <title>Redirecting…</title>
186+ </head>
187+ <body>
188+ <p>Redirecting to <a href="../${SHORT_SHA}/">latest build (${SHORT_SHA})</a>…</p>
189+ </body>
190+ </html>
191+ EOF
192+
193+ - name : Deploy build to gh-pages
194+ uses : peaceiris/actions-gh-pages@v4
195+ with :
196+ github_token : ${{ secrets.GITHUB_TOKEN }}
197+ publish_dir : ./
198+ destination_dir : demo/build/${{ steps.sha.outputs.short }}
199+ exclude_assets : " WOLF3D,latest-redirect"
200+ keep_files : true
201+
202+ - name : Deploy latest redirect to gh-pages
203+ uses : peaceiris/actions-gh-pages@v4
204+ with :
205+ github_token : ${{ secrets.GITHUB_TOKEN }}
206+ publish_dir : ./latest-redirect
207+ destination_dir : demo/build/latest
208+ keep_files : true
209+
210+ update-readme :
211+ runs-on : ubuntu-latest
212+ needs : deploy-demo
213+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
214+ steps :
215+ - name : Checkout main
216+ uses : actions/checkout@v4
217+ with :
218+ ref : main
219+ token : ${{ secrets.GITHUB_TOKEN }}
220+
221+ - name : Compute short SHA
222+ id : sha
223+ run : echo "short=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
224+
225+ - name : Update demo link in README.md
226+ run : |
227+ SHORT_SHA="${{ steps.sha.outputs.short }}"
228+ DEMO_URL="https://luke-b.github.io/DosTest/demo/build/${SHORT_SHA}/"
229+ BADGE_LINE="[](${DEMO_URL})"
230+ BLOCK="<!-- DEMO_LINK -->\n${BADGE_LINE}\n<!-- /DEMO_LINK -->"
231+
232+ if grep -q '<!-- DEMO_LINK -->' README.md; then
233+ # Replace existing block (handles multi-line with perl)
234+ perl -i -0pe "s|<!-- DEMO_LINK -->.*?<!-- /DEMO_LINK -->|${BLOCK}|s" README.md
235+ else
236+ # Sentinel missing: insert complete block after the first heading line
237+ perl -i -0pe "s|(# [^\n]+\n)|\$1\n${BLOCK}\n|" README.md
238+ fi
239+
240+ - name : Commit and push README update
241+ run : |
242+ SHORT_SHA="${{ steps.sha.outputs.short }}"
243+ git config user.name "github-actions[bot]"
244+ git config user.email "github-actions[bot]@users.noreply.github.com"
245+ git add README.md
246+ git diff --cached --quiet || git commit -m "chore: update demo link to build ${SHORT_SHA} [skip ci]"
247+ git push
0 commit comments