This workflow (deploy-preview.yml) automatically builds and deploys preview versions of the examples application to GitHub Pages for every branch push and pull request.
- Pull Requests: Triggers on
opened,synchronize, andreopenedevents - Branch Pushes: Triggers on pushes to any branch except
main(which has its own deployment workflow)
The workflow deploys to the gh-pages branch using the following path structure:
-
Pull Requests:
pr/<pr-number>-<short-sha>/- Example:
pr/42-abc1234/
- Example:
-
Branches:
branch/<safe-branch-name>-<short-sha>/- Example:
branch/feature_new-ui-a7b8c9d/
- Example:
The workflow automatically:
- Fetches the GitHub Pages URL using the
ghCLI - Falls back to
https://<owner>.github.io/<repo>if Pages isn't configured - Builds the examples app with the correct base href using Parcel's
--public-urloption - All asset paths are absolute URLs pointing to the correct subdirectory
- ✅ Automatic PR Comments: Posts a comment on PRs with the preview URL
- ✅ Branch Sanitization: Safely handles branch names with special characters
- ✅ Incremental Deployments: Each commit creates a new deployment with a unique SHA
- ✅ Job Summaries: Provides deployment URL in GitHub Actions summary
- ✅ gh-pages Auto-Init: Creates the gh-pages branch if it doesn't exist
- Open a pull request
- Wait for the workflow to complete
- Click the preview URL in the automated comment
- Each new commit will update the deployment (with a new SHA in the path)
- Push commits to any branch (except
main) - Check the workflow run for the deployment URL in the summary
- Access your preview at:
https://<owner>.github.io/<repo>/branch/<branch-name>-<sha>/
The workflow needs the following permissions:
contents: write- To push to the gh-pages branchpull-requests: write- To comment on pull requestspages: read- To fetch the GitHub Pages URL
- Install root dependencies and build the library
- Install example app dependencies
- Clean previous builds
- Generate API documentation
- Build example app with Parcel using custom
--public-url - Deploy to gh-pages branch in the appropriate subdirectory
Edit the "Determine deployment path" step in .github/workflows/deploy-preview.yml:
- name: Determine deployment path
id: deployment-path
run: |
# Modify DEPLOY_DIR and BASE_HREF variables hereThe build uses Parcel with the following options:
--no-optimize: Faster builds, easier debugging--public-url: Dynamic base URL for assets
To modify, edit the "Build example with base href" step.
- Ensure GitHub Pages is enabled for the repository
- Check that the gh-pages branch exists
- Verify the deployment path in the workflow logs
- Check the browser console for failed requests
- Verify the base href is correct in the deployed HTML
- Ensure all asset paths are absolute URLs
- Check repository permissions
- Verify the
GITHUB_TOKENhas write access to contents