@@ -3,6 +3,8 @@ name: GenCI
3
3
permissions :
4
4
contents : read
5
5
pull-requests : write
6
+ pages : write
7
+ id-token : write
6
8
7
9
on :
8
10
push :
@@ -135,3 +137,141 @@ jobs:
135
137
tools : ${{ matrix.tools }}
136
138
extras : ${{ matrix.extras }}
137
139
secrets : inherit
140
+
141
+ # New job to prepare content for GitHub Pages
142
+ prepare-gh-pages :
143
+ name : Prepare GitHub Pages
144
+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
145
+ needs : [build-generals, build-generalsmd]
146
+ runs-on : ubuntu-latest
147
+ steps :
148
+ - name : Checkout Code (main branch)
149
+ uses : actions/checkout@v4
150
+ with :
151
+ path : main-repo
152
+
153
+ - name : Download all workflow artifacts
154
+ uses : actions/download-artifact@v4
155
+ with :
156
+ path : ./current-build-artifacts/
157
+
158
+ - name : Checkout gh-pages branch
159
+ uses : actions/checkout@v4
160
+ with :
161
+ ref : gh-pages
162
+ path : gh-pages-root
163
+
164
+ - name : Prepare historical artifacts and update index.html
165
+ shell : bash
166
+ run : |
167
+ GH_PAGES_ROOT="./gh-pages-root"
168
+ BUILD_ARTIFACTS_DIR="$GH_PAGES_ROOT/builds"
169
+ CURRENT_BUILD_ID="${{ github.run_id }}"
170
+ CURRENT_BUILD_SHA="${{ github.sha }}"
171
+ CURRENT_BUILD_TIMESTAMP="$(TZ=UTC date -u +"%Y-%m-%d_%H-%M-%S")"
172
+ CURRENT_BUILD_NAME="${CURRENT_BUILD_TIMESTAMP}_${CURRENT_BUILD_ID}_${CURRENT_BUILD_SHA:0:7}"
173
+
174
+ mkdir -p "$BUILD_ARTIFACTS_DIR/$CURRENT_BUILD_NAME"
175
+
176
+ shopt -s nullglob
177
+ for artifact_bundle_src_dir in ./current-build-artifacts/*; do
178
+ if [ -d "$artifact_bundle_src_dir" ]; then
179
+ artifact_bundle_name=$(basename "$artifact_bundle_src_dir")
180
+ mkdir -p "$BUILD_ARTIFACTS_DIR/$CURRENT_BUILD_NAME/$artifact_bundle_name"
181
+ cp -R "$artifact_bundle_src_dir"/* "$BUILD_ARTIFACTS_DIR/$CURRENT_BUILD_NAME/$artifact_bundle_name/"
182
+ fi
183
+ done
184
+ shopt -u nullglob
185
+
186
+ # Clean up old builds, keeping only the last 5
187
+ MAX_BUILDS_TO_KEEP=5
188
+ BUILD_DIRS=($(ls -r "$BUILD_ARTIFACTS_DIR")) # List in reverse chronological order
189
+ NUM_BUILDS=${#BUILD_DIRS[@]}
190
+
191
+ if [ "$NUM_BUILDS" -gt "$MAX_BUILDS_TO_KEEP" ]; then
192
+ echo "Cleaning up old builds. Keeping $MAX_BUILDS_TO_KEEP most recent."
193
+ for (( i=MAX_BUILDS_TO_KEEP; i<NUM_BUILDS; i++ )); do
194
+ OLD_BUILD_DIR="${BUILD_ARTIFACTS_DIR}/${BUILD_DIRS[$i]}"
195
+ echo "Deleting old build: $OLD_BUILD_DIR"
196
+ rm -rf "$OLD_BUILD_DIR"
197
+ done
198
+ else
199
+ echo "Number of builds ($NUM_BUILDS) is within the limit ($MAX_BUILDS_TO_KEEP). No cleanup needed."
200
+ fi
201
+
202
+ INDEX_HTML="$GH_PAGES_ROOT/index.html"
203
+ echo "<!DOCTYPE html>" > "$INDEX_HTML"
204
+ echo "<html lang='en'>" >> "$INDEX_HTML"
205
+ echo "<head><meta charset='UTF-8'><title>Build Artifacts History</title></head>" >> "$INDEX_HTML"
206
+ echo "<body>" >> "$INDEX_HTML"
207
+ echo "<h1>Build Artifacts History</h1>" >> "$INDEX_HTML"
208
+ echo "<p>This page lists historical build artifacts.</p>" >> "$INDEX_HTML"
209
+ echo "<ul>" >> "$INDEX_HTML"
210
+
211
+ for build_dir in $(ls -r "$BUILD_ARTIFACTS_DIR"); do
212
+ if [ -d "$BUILD_ARTIFACTS_DIR/$build_dir" ]; then
213
+ echo " <li><a href=\"builds/$build_dir/index.html\">Build: $build_dir</a></li>" >> "$INDEX_HTML"
214
+ BUILD_INDEX_HTML="$BUILD_ARTIFACTS_DIR/$build_dir/index.html"
215
+ echo "<!DOCTYPE html>" > "$BUILD_INDEX_HTML"
216
+ echo "<html lang='en'>" >> "$BUILD_INDEX_HTML"
217
+ echo "<head><meta charset='UTF-8'><title>Artifacts for $build_dir</title></head>" >> "$BUILD_INDEX_HTML"
218
+ echo "<body>" >> "$BUILD_INDEX_HTML"
219
+ echo "<h1>Artifacts for Build: $build_dir</h1>" >> "$BUILD_INDEX_HTML"
220
+ echo "<p>Commit: <a href='${{ github.server_url }}/${{ github.repository }}/commit/${CURRENT_BUILD_SHA}'>${CURRENT_BUILD_SHA}</a></p>" >> "$BUILD_INDEX_HTML"
221
+ echo "<p>Workflow Run: <a href='${{ github.server_url }}/${{ github.repository }}/actions/runs/${CURRENT_BUILD_ID}'>#${CURRENT_BUILD_ID}</a></p>" >> "$BUILD_INDEX_HTML"
222
+ echo "<p>Generated: $(TZ=UTC date -u +"%Y-%m-%d %H:%M:%S %Z")</p>" >> "$BUILD_INDEX_HTML"
223
+ echo "<ul>" >> "$BUILD_INDEX_HTML"
224
+
225
+ for artifact_bundle_sub_dir in "$BUILD_ARTIFACTS_DIR/$build_dir"/*; do
226
+ if [ -d "$artifact_bundle_sub_dir" ]; then
227
+ artifact_bundle_name=$(basename "$artifact_bundle_sub_dir")
228
+ echo " <li><strong>$artifact_bundle_name</strong>" >> "$BUILD_INDEX_HTML"
229
+ echo " <ul>" >> "$BUILD_INDEX_HTML"
230
+ for file_path in "$artifact_bundle_sub_dir"/*; do
231
+ if [ -f "$file_path" ]; then
232
+ file_name=$(basename "$file_path")
233
+ link_path="./$artifact_bundle_name/$file_name"
234
+ echo " <li><a href=\"$link_path\">$file_name</a></li>" >> "$BUILD_INDEX_HTML"
235
+ fi
236
+ done
237
+ echo " </ul>" >> "$BUILD_INDEX_HTML"
238
+ echo " </li>" >> "$BUILD_INDEX_HTML"
239
+ fi
240
+ done
241
+ echo "</ul>" >> "$BUILD_INDEX_HTML"
242
+ echo "<p><a href=\"../index.html\">Back to History</a></p>" >> "$BUILD_INDEX_HTML"
243
+ echo "</body></html>" >> "$BUILD_INDEX_HTML"
244
+ fi
245
+ done
246
+
247
+ echo "</ul>" >> "$INDEX_HTML"
248
+ echo "</body></html>" >> "$INDEX_HTML"
249
+
250
+ echo "Generated main index.html content:"
251
+ cat "$INDEX_HTML"
252
+ echo "Site structure in $GH_PAGES_ROOT:"
253
+ ls -R "$GH_PAGES_ROOT"
254
+
255
+ - name : Upload Pages artifact
256
+ uses : actions/upload-pages-artifact@v3
257
+ with :
258
+ path : ./gh-pages-root
259
+
260
+ deploy-gh-pages :
261
+ name : Deploy to GitHub Pages
262
+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
263
+ needs : prepare-gh-pages
264
+ runs-on : ubuntu-latest
265
+ environment :
266
+ name : github-pages
267
+ url : ${{ steps.deployment.outputs.page_url }}
268
+ permissions :
269
+ pages : write
270
+ id-token : write
271
+ concurrency :
272
+ group : ${{ github.repository }}-pages
273
+ cancel-in-progress : false
274
+ steps :
275
+ - name : Deploy to GitHub Pages
276
+ id : deployment
277
+ uses : actions/deploy-pages@v4
0 commit comments