Skip to content

Commit 73f803f

Browse files
committed
[GitHub] Uploads the Build Artifacts To Simple Website Using GitHub Pages
1 parent c9d1fd5 commit 73f803f

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

.github/workflows/ci.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: GenCI
33
permissions:
44
contents: read
55
pull-requests: write
6+
pages: write
7+
id-token: write
68

79
on:
810
push:
@@ -135,3 +137,127 @@ jobs:
135137
tools: ${{ matrix.tools }}
136138
extras: ${{ matrix.extras }}
137139
secrets: inherit
140+
141+
# New job to prepare content for GitHub Pages
142+
prepare-gh-pages:
143+
name: Prepare GitHub Pages
144+
# Only run for pushes to the main branch,
145+
# and only if the build jobs it needs were scheduled to run and succeeded.
146+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
147+
needs:
148+
[build-generals, build-generalsmd] # Runs if both build jobs (if triggered) succeed.
149+
# If a build job is skipped due to path filtering, this job will also be skipped.
150+
runs-on: ubuntu-latest
151+
steps:
152+
- name: Download all workflow artifacts
153+
uses: actions/download-artifact@v4
154+
with:
155+
path: ./all-build-artifacts/ # Download all artifacts into this directory
156+
# Artifacts will be in subdirectories named after the artifact name by default
157+
158+
- name: List downloaded artifacts (for debugging)
159+
run: |
160+
echo "Downloaded artifacts structure:"
161+
ls -R ./all-build-artifacts/
162+
163+
- name: Create Pages content directory
164+
run: mkdir ./_site
165+
166+
- name: Generate index.html and organize artifacts
167+
shell: bash
168+
run: |
169+
SITE_DIR="./_site"
170+
INDEX_HTML="$SITE_DIR/index.html"
171+
DOWNLOADS_DEST_DIR="$SITE_DIR/downloads" # Store actual files here
172+
173+
mkdir -p "$DOWNLOADS_DEST_DIR"
174+
175+
echo "<!DOCTYPE html>" > "$INDEX_HTML"
176+
echo "<html lang='en'>" >> "$INDEX_HTML"
177+
echo "<head><meta charset='UTF-8'><title>Build Artifacts</title></head>" >> "$INDEX_HTML"
178+
echo "<body>" >> "$INDEX_HTML"
179+
echo "<h1>Build Artifacts</h1>" >> "$INDEX_HTML"
180+
echo "<p>Commit: <a href='${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}'>${{ github.sha }}</a></p>" >> "$INDEX_HTML"
181+
echo "<p>Workflow Run: <a href='${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'>#${{ github.run_number }}</a></p>" >> "$INDEX_HTML"
182+
echo "<p>Last updated: $(TZ=UTC date -u +"%Y-%m-%d %H:%M:%S %Z")</p>" >> "$INDEX_HTML"
183+
echo "<ul>" >> "$INDEX_HTML"
184+
185+
# Artifacts were downloaded into subdirectories under ./all-build-artifacts/
186+
# e.g., ./all-build-artifacts/Generals-vc6+t+e/Game.exe
187+
shopt -s nullglob # Ensures loop doesn't run if no matches
188+
artifact_count=0
189+
for artifact_bundle_src_dir in ./all-build-artifacts/*; do
190+
if [ -d "$artifact_bundle_src_dir" ]; then
191+
artifact_bundle_name=$(basename "$artifact_bundle_src_dir")
192+
echo "Processing artifact bundle: $artifact_bundle_name"
193+
194+
echo " <li>" >> "$INDEX_HTML"
195+
echo " <strong>$artifact_bundle_name</strong>" >> "$INDEX_HTML"
196+
echo " <ul>" >> "$INDEX_HTML"
197+
198+
# Create a target directory for this specific bundle's files within 'downloads'
199+
# This keeps the URL structure cleaner: /downloads/BUNDLE_NAME/file.exe
200+
current_bundle_target_dir="$DOWNLOADS_DEST_DIR/$artifact_bundle_name"
201+
mkdir -p "$current_bundle_target_dir"
202+
203+
file_in_bundle_count=0
204+
for file_path in "$artifact_bundle_src_dir"/*; do
205+
if [ -f "$file_path" ]; then
206+
file_name=$(basename "$file_path")
207+
# Relative path for the link from site root (index.html)
208+
link_path="downloads/$artifact_bundle_name/$file_name"
209+
210+
cp "$file_path" "$current_bundle_target_dir/$file_name"
211+
echo " <li><a href=\"$link_path\">$file_name</a></li>" >> "$INDEX_HTML"
212+
file_in_bundle_count=$((file_in_bundle_count + 1))
213+
fi
214+
done
215+
216+
if [ "$file_in_bundle_count" -eq 0 ]; then
217+
echo " <li>No files found in this artifact bundle.</li>" >> "$INDEX_HTML"
218+
fi
219+
echo " </ul>" >> "$INDEX_HTML"
220+
echo " </li>" >> "$INDEX_HTML"
221+
artifact_count=$((artifact_count + 1))
222+
fi
223+
done
224+
shopt -u nullglob
225+
226+
if [ "$artifact_count" -eq 0 ]; then
227+
echo " <li>No build artifacts were found or processed for this run.</li>" >> "$INDEX_HTML"
228+
fi
229+
230+
echo "</ul>" >> "$INDEX_HTML"
231+
echo "</body></html>" >> "$INDEX_HTML"
232+
233+
echo "Generated index.html content:"
234+
cat "$INDEX_HTML"
235+
echo "Site structure in $SITE_DIR:"
236+
ls -R "$SITE_DIR"
237+
238+
- name: Upload Pages artifact
239+
uses: actions/upload-pages-artifact@v3
240+
with:
241+
path: ./_site # Upload the directory we just prepared
242+
243+
# New job to deploy to GitHub Pages
244+
deploy-gh-pages:
245+
name: Deploy to GitHub Pages
246+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
247+
needs: prepare-gh-pages # Runs only if prepare-gh-pages completes successfully
248+
runs-on: ubuntu-latest
249+
environment:
250+
name: github-pages
251+
url: ${{ steps.deployment.outputs.page_url }}
252+
# Permissions are inherited from the workflow level but specified here for clarity
253+
permissions:
254+
pages: write
255+
id-token: write
256+
concurrency: # Optional: ensures only one deployment to Pages at a time for this repo
257+
group: ${{ github.repository }}-pages
258+
cancel-in-progress: false
259+
steps:
260+
- name: Deploy to GitHub Pages
261+
id: deployment
262+
uses: actions/deploy-pages@v4
263+
# This action automatically picks up the artifact uploaded by actions/upload-pages-artifact

0 commit comments

Comments
 (0)