uploadrer fix #2
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: Deploy Docs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - docs/** | |
| - .github/workflows/deploy-docs.yml | |
| release: | |
| types: | |
| - published | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: pages | |
| cancel-in-progress: true | |
| jobs: | |
| deploy: | |
| name: Publish GitHub Pages | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Configure Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Build Pages site | |
| shell: bash | |
| env: | |
| GH_REPO: ${{ github.repository }} | |
| run: | | |
| set -euo pipefail | |
| rm -rf _site | |
| mkdir -p _site | |
| cp -R docs/. _site/ | |
| python <<'PY' | |
| import json | |
| import os | |
| import pathlib | |
| import urllib.error | |
| import urllib.request | |
| repo = os.environ["GH_REPO"] | |
| site_dir = pathlib.Path("_site") | |
| downloads_dir = site_dir / "downloads" | |
| metadata_dir = site_dir / "site-data" | |
| downloads_dir.mkdir(parents=True, exist_ok=True) | |
| metadata_dir.mkdir(parents=True, exist_ok=True) | |
| default_manifest = { | |
| "tag_name": None, | |
| "html_url": f"https://github.com/{repo}/releases", | |
| "assets": {}, | |
| } | |
| def request_json(url: str): | |
| request = urllib.request.Request( | |
| url, | |
| headers={ | |
| "Accept": "application/vnd.github+json", | |
| "X-GitHub-Api-Version": "2022-11-28", | |
| "User-Agent": "github-pages-deploy", | |
| }, | |
| ) | |
| with urllib.request.urlopen(request) as response: | |
| return json.load(response) | |
| def download_asset(url: str, output_path: pathlib.Path): | |
| request = urllib.request.Request( | |
| url, | |
| headers={ | |
| "Accept": "application/octet-stream", | |
| "X-GitHub-Api-Version": "2022-11-28", | |
| "User-Agent": "github-pages-deploy", | |
| }, | |
| ) | |
| with urllib.request.urlopen(request) as response: | |
| output_path.write_bytes(response.read()) | |
| try: | |
| release = request_json(f"https://api.github.com/repos/{repo}/releases/latest") | |
| except urllib.error.HTTPError as error: | |
| if error.code == 404: | |
| release = None | |
| else: | |
| raise | |
| manifest = default_manifest | |
| if release: | |
| manifest = { | |
| "tag_name": release.get("tag_name"), | |
| "html_url": release.get("html_url") or default_manifest["html_url"], | |
| "assets": {}, | |
| } | |
| track_names = ("momentum_dev", "unleashed") | |
| release_assets = release.get("assets") or [] | |
| for track_name in track_names: | |
| asset = next( | |
| ( | |
| item | |
| for item in release_assets | |
| if (item.get("name") or "").endswith(f"_{track_name}.fap") | |
| ), | |
| None, | |
| ) | |
| if not asset: | |
| continue | |
| relative_path = f"downloads/latest_{track_name}.fap" | |
| output_path = site_dir / relative_path | |
| download_asset(asset["url"], output_path) | |
| manifest["assets"][track_name] = { | |
| "name": asset.get("name"), | |
| "size": asset.get("size"), | |
| "content_type": asset.get("content_type"), | |
| "url": f"./{relative_path}", | |
| } | |
| (metadata_dir / "latest-release.json").write_text( | |
| json.dumps(manifest, indent=2), | |
| encoding="utf-8", | |
| ) | |
| print(json.dumps(manifest, indent=2)) | |
| PY | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: _site | |
| - name: Deploy Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |