GitHub Pages
This guide shows how to build a Flet static web app and deploy it to GitHub Pages with GitHub Actions.
Setup#
- Open your repository root.
- Create this folder if it does not exist:
.github/workflows/ - Create a workflow file in that folder, for example:
.github/workflows/build-deploy.yml- must have the.ymlor.yamlfile extension. - Copy the workflow configuration below into that file and adjust to your needs.
- Commit and push to GitHub.
- Open the Actions tab to monitor build/deploy progress.
Repository settings
In GitHub, open Settings → Pages and make sure deployment source is GitHub Actions.
Workflow#
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://docs.flet.dev/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/upload-pages-artifact@v4.0.0 # (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/deploy-pages@v4.0.5 # (25)!
with:
artifact_name: web-build-artifact # (26)!
- Workflow name shown in the Actions list.
- Trigger block for the workflow.
- Builds on every push.
- Builds on pull request updates.
- Allows manual runs from the Actions tab.
- Concurrency settings for GitHub Pages deployments.
- Places deployments into the same
pagesconcurrency group. - Keeps the currently running deployment instead of canceling it.
- Environment variables available to all jobs.
- Python version used by
uv. - Produces cleaner CI logs by disabling rich output.
- Runs the build job on GitHub-hosted Ubuntu.
- Checks out repository code. View its docs here.
- Installs
uv. View its docs here. - Builds static web output and sets:
- Uploads static files as a Pages artifact. View its docs here.
- Uses
build/webas artifact source. - Artifact name used later by deploy step.
- Keeps the artifact for 20 days.
- Deploys only on pushes to
main. PRs only build but don't deploy. Adjust as needed. - Waits for successful build job before deploy.
- Required permissions for Pages deployment.
- Connects deployment output URL to the GitHub environment.
- Configures Pages runtime. View its docs here.
- Deploys artifact to GitHub Pages. View its docs here.
- Must match the uploaded artifact name.
See it in action here.