|
| 1 | +name: Deploy demo (GitHub Pages) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + paths: |
| 7 | + - "BlazorCanvas2d/**" |
| 8 | + - "BlazorCanvas2d.Samples/**" |
| 9 | + - ".github/workflows/deploy-demo.yml" |
| 10 | + - ".github/workflows/ci.yml" |
| 11 | + - "BlazorCanvas2d.sln" |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + pages: write |
| 16 | + id-token: write |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: "pages" |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Setup .NET |
| 29 | + uses: actions/setup-dotnet@v4 |
| 30 | + with: |
| 31 | + dotnet-version: 10.0.x |
| 32 | + |
| 33 | + - name: Publish SimpleCanvas (Release) |
| 34 | + run: dotnet publish "BlazorCanvas2d.Samples/BlazorCanvas2d.Samples.SimpleCanvas/BlazorCanvas2d.Samples.SimpleCanvas.csproj" -c Release -o "artifacts/publish" |
| 35 | + |
| 36 | + - name: Prepare GitHub Pages assets |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + set -euo pipefail |
| 40 | + WWWROOT="artifacts/publish/wwwroot" |
| 41 | + REPO_NAME="${GITHUB_REPOSITORY#*/}" |
| 42 | + BASE_HREF="/${REPO_NAME}/" |
| 43 | +
|
| 44 | + # Blazor WASM needs correct base href when hosted from /<repo>/ |
| 45 | + python3 - <<'PY' |
| 46 | + import os |
| 47 | + import pathlib |
| 48 | + import re |
| 49 | +
|
| 50 | + wwwroot = pathlib.Path(os.environ["WWWROOT"]) |
| 51 | + base_href = os.environ["BASE_HREF"] |
| 52 | + index = wwwroot / "index.html" |
| 53 | + html = index.read_text(encoding="utf-8") |
| 54 | + html2, n = re.subn(r'<base href="[^"]*"\s*/>', f'<base href="{base_href}" />', html, count=1) |
| 55 | + if n != 1: |
| 56 | + raise SystemExit("Expected exactly one <base href=\"...\" /> in index.html") |
| 57 | + index.write_text(html2, encoding="utf-8") |
| 58 | + (wwwroot / "404.html").write_text(html2, encoding="utf-8") |
| 59 | + (wwwroot / ".nojekyll").write_text("", encoding="utf-8") |
| 60 | + PY |
| 61 | +
|
| 62 | + - name: Upload Pages artifact |
| 63 | + uses: actions/upload-pages-artifact@v3 |
| 64 | + with: |
| 65 | + path: artifacts/publish/wwwroot |
| 66 | + |
| 67 | + deploy: |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: build |
| 70 | + environment: |
| 71 | + name: github-pages |
| 72 | + url: ${{ steps.deployment.outputs.page_url }} |
| 73 | + steps: |
| 74 | + - id: deployment |
| 75 | + uses: actions/deploy-pages@v4 |
| 76 | + |
0 commit comments