diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd16f177f0..0914dcfaf3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,8 @@ name: GenCI permissions: contents: read pull-requests: write + pages: write + id-token: write on: push: @@ -135,3 +137,141 @@ jobs: tools: ${{ matrix.tools }} extras: ${{ matrix.extras }} secrets: inherit + + # New job to prepare content for GitHub Pages + prepare-gh-pages: + name: Prepare GitHub Pages + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: [build-generals, build-generalsmd] + runs-on: ubuntu-latest + steps: + - name: Checkout Code (main branch) + uses: actions/checkout@v4 + with: + path: main-repo + + - name: Download all workflow artifacts + uses: actions/download-artifact@v4 + with: + path: ./current-build-artifacts/ + + - name: Checkout gh-pages branch + uses: actions/checkout@v4 + with: + ref: gh-pages + path: gh-pages-root + + - name: Prepare historical artifacts and update index.html + shell: bash + run: | + GH_PAGES_ROOT="./gh-pages-root" + BUILD_ARTIFACTS_DIR="$GH_PAGES_ROOT/builds" + CURRENT_BUILD_ID="${{ github.run_id }}" + CURRENT_BUILD_SHA="${{ github.sha }}" + CURRENT_BUILD_TIMESTAMP="$(TZ=UTC date -u +"%Y-%m-%d_%H-%M-%S")" + CURRENT_BUILD_NAME="${CURRENT_BUILD_TIMESTAMP}_${CURRENT_BUILD_ID}_${CURRENT_BUILD_SHA:0:7}" + + mkdir -p "$BUILD_ARTIFACTS_DIR/$CURRENT_BUILD_NAME" + + shopt -s nullglob + for artifact_bundle_src_dir in ./current-build-artifacts/*; do + if [ -d "$artifact_bundle_src_dir" ]; then + artifact_bundle_name=$(basename "$artifact_bundle_src_dir") + mkdir -p "$BUILD_ARTIFACTS_DIR/$CURRENT_BUILD_NAME/$artifact_bundle_name" + cp -R "$artifact_bundle_src_dir"/* "$BUILD_ARTIFACTS_DIR/$CURRENT_BUILD_NAME/$artifact_bundle_name/" + fi + done + shopt -u nullglob + + # Clean up old builds, keeping only the last 5 + MAX_BUILDS_TO_KEEP=5 + BUILD_DIRS=($(ls -r "$BUILD_ARTIFACTS_DIR")) # List in reverse chronological order + NUM_BUILDS=${#BUILD_DIRS[@]} + + if [ "$NUM_BUILDS" -gt "$MAX_BUILDS_TO_KEEP" ]; then + echo "Cleaning up old builds. Keeping $MAX_BUILDS_TO_KEEP most recent." + for (( i=MAX_BUILDS_TO_KEEP; i" > "$INDEX_HTML" + echo "" >> "$INDEX_HTML" + echo "Build Artifacts History" >> "$INDEX_HTML" + echo "" >> "$INDEX_HTML" + echo "

Build Artifacts History

" >> "$INDEX_HTML" + echo "

This page lists historical build artifacts.

" >> "$INDEX_HTML" + echo "" >> "$INDEX_HTML" + echo "" >> "$INDEX_HTML" + + echo "Generated main index.html content:" + cat "$INDEX_HTML" + echo "Site structure in $GH_PAGES_ROOT:" + ls -R "$GH_PAGES_ROOT" + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./gh-pages-root + + deploy-gh-pages: + name: Deploy to GitHub Pages + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: prepare-gh-pages + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + permissions: + pages: write + id-token: write + concurrency: + group: ${{ github.repository }}-pages + cancel-in-progress: false + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4