Update Build Index #553
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Build Index | |
| on: | |
| workflow_run: | |
| workflows: | |
| - "Android 13 Framework Patcher" | |
| - "Android 14 Framework Patcher" | |
| - "Android 15 Framework Patcher" | |
| - "Android 16 Framework Patcher" | |
| types: | |
| - completed | |
| # Prevent concurrent index updates (race condition protection) | |
| concurrency: | |
| group: build-index-update | |
| cancel-in-progress: false | |
| jobs: | |
| update-index: | |
| name: Update build index | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Render GitHub Pages index | |
| run: | | |
| python3 scripts/core/render_pages_index.py --output /tmp/index.html | |
| - name: Setup gh-pages branch | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if git fetch origin gh-pages; then | |
| git checkout -B gh-pages origin/gh-pages | |
| else | |
| echo "gh-pages branch not found, creating orphan branch..." | |
| git checkout --orphan gh-pages | |
| git rm -rf . | |
| mkdir -p builds | |
| touch builds/.gitkeep | |
| git add builds/.gitkeep | |
| git commit -m "Initialize gh-pages" | |
| fi | |
| - name: Download build manifest artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build-manifest-${{ github.event.workflow_run.id }} | |
| path: /tmp/manifest | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| continue-on-error: true | |
| - name: Update index | |
| run: | | |
| MANIFEST_FILE="/tmp/manifest/build-manifest.json" | |
| if [ ! -f "$MANIFEST_FILE" ]; then | |
| echo "No build manifest found for run ${{ github.event.workflow_run.id }}, skipping." | |
| exit 0 | |
| fi | |
| mkdir -p builds | |
| # Backup current index | |
| if [ -f builds/index.json ]; then | |
| cp builds/index.json builds/index.json.bak | |
| fi | |
| # Read manifest fields | |
| DEVICE=$(python3 -c "import json; print(json.load(open('$MANIFEST_FILE'))['device'])") | |
| BASE_ROM=$(python3 -c "import json; print(json.load(open('$MANIFEST_FILE'))['base_rom'])") | |
| # Update per-device index file | |
| DEVICE_FILE="builds/${DEVICE}.json" | |
| export MANIFEST_FILE | |
| export DEVICE | |
| export BASE_ROM | |
| export DEVICE_FILE | |
| python3 <<'PYEOF' | |
| import json, os, sys | |
| from datetime import datetime, timezone | |
| manifest_path = os.environ.get("MANIFEST_FILE", "/tmp/manifest/build-manifest.json") | |
| device = os.environ.get("DEVICE", "unknown") | |
| base_rom = os.environ.get("BASE_ROM", "unknown") | |
| device_file = os.environ.get("DEVICE_FILE", f"builds/{device}.json") | |
| run_id = "${{ github.event.workflow_run.id }}" | |
| with open(manifest_path) as f: | |
| manifest = json.load(f) | |
| manifest_release_url = manifest.get("release_url") or manifest.get("workflow_url") | |
| manifest_workflow_url = manifest.get("workflow_url", "") | |
| # Load or create device index | |
| if os.path.exists(device_file): | |
| with open(device_file) as f: | |
| device_data = json.load(f) | |
| else: | |
| device_data = {"device": device, "builds": {}} | |
| # Upsert build entry | |
| device_data["builds"][base_rom] = { | |
| "android_version": manifest.get("android_version", "unknown"), | |
| "patch_version": manifest.get("patch_engine_version", "unknown"), | |
| "features": manifest.get("features", []), | |
| "build_time": manifest.get("build_time", ""), | |
| "git_commit": manifest.get("git_commit", ""), | |
| "checksums": manifest.get("checksums", {}), | |
| "workflow_run_id": run_id, | |
| "workflow_url": manifest_workflow_url, | |
| "release_url": manifest_release_url, | |
| } | |
| device_data["last_updated"] = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") | |
| with open(device_file, "w") as f: | |
| json.dump(device_data, f, indent=2) | |
| # Update summary index | |
| index_path = "builds/index.json" | |
| if os.path.exists(index_path): | |
| with open(index_path) as f: | |
| index = json.load(f) | |
| else: | |
| index = {"schema_version": "1.0", "devices": {}} | |
| index["last_updated"] = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") | |
| index["engine_version"] = manifest.get("patch_engine_version", "unknown") | |
| if device not in index["devices"]: | |
| index["devices"][device] = {} | |
| index["devices"][device][base_rom] = { | |
| "android_version": manifest.get("android_version", "unknown"), | |
| "build_time": manifest.get("build_time", ""), | |
| "patch_version": manifest.get("patch_engine_version", "unknown"), | |
| "release_url": manifest_release_url, | |
| "workflow_url": manifest_workflow_url, | |
| "features": manifest.get("features", []), | |
| } | |
| with open(index_path, "w") as f: | |
| json.dump(index, f, indent=2) | |
| print(f"✅ Updated index for {device}/{base_rom}") | |
| PYEOF | |
| - name: Validate JSON | |
| run: | | |
| # Validate all JSON files before committing | |
| for f in builds/*.json; do | |
| if [ -f "$f" ]; then | |
| python3 -c "import json; json.load(open('$f'))" || { | |
| echo "❌ Invalid JSON in $f — restoring backup" | |
| if [ -f builds/index.json.bak ]; then | |
| mv builds/index.json.bak builds/index.json | |
| fi | |
| exit 1 | |
| } | |
| fi | |
| done | |
| rm -f builds/index.json.bak | |
| echo "✅ All JSON files validated" | |
| - name: Commit and push | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| cp /tmp/index.html index.html | |
| git add index.html builds/ | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Update build index for run ${{ github.event.workflow_run.id }}" | |
| git push origin gh-pages | |
| fi |