website/docs/publish/web/static-website/hosting/github-pages.md
This guide shows how to build a Flet static web app and deploy it to GitHub Pages with GitHub Actions.
.github/workflows/.github/workflows/build-deploy.yml - must have the .yml or .yaml file extension.:::danger[Repository settings] In GitHub, open Settings → Pages and make sure deployment source is GitHub Actions. :::
name: Web Build + Deploy to GitHub Pages # (1)!
on: # (2)!
push: # (3)!
pull_request: # (4)!
workflow_dispatch: # (5)!
concurrency: # (6)!
group: "pages" # (7)!
cancel-in-progress: false # (8)!
env: # (9)!
UV_PYTHON: 3.12 # (10)!
# https://flet.dev/docs/reference/environment-variables
FLET_CLI_NO_RICH_OUTPUT: 1 # (11)!
jobs:
build:
name: Build web app
runs-on: ubuntu-latest # (12)!
steps:
- name: Checkout repository
uses: actions/checkout@v4 # (13)!
- name: Setup uv
uses: astral-sh/setup-uv@v6 # (14)!
- name: Build app
shell: bash
run: | # (15)!
uv run flet build web --yes --verbose --base-url ${GITHUB_REPOSITORY#*/} --route-url-strategy hash
- name: Upload Pages Artifact
uses: actions/[email protected] # (16)!
with:
path: build/web # (17)!
name: web-build-artifact # (18)!
retention-days: 20 # (19)!
deploy:
name: Deploy to GitHub Pages
if: github.event_name == 'push' && github.ref == 'refs/heads/main' # (20)!
needs: build # (21)!
runs-on: ubuntu-latest
permissions: # (22)!
pages: write
id-token: write
environment: # (23)!
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Setup Pages
uses: actions/configure-pages@v5 # (24)!
- name: Deploy to GitHub Pages
id: deployment
uses: actions/[email protected] # (25)!
with:
artifact_name: web-build-artifact # (26)!
pages concurrency group.uv.uv. View its docs here.build/web as artifact source.main. PRs only build but don't deploy. Adjust as needed.See it in action here.