|
| 1 | +# GitHub Pages Preview Deployments |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## How it works |
| 6 | + |
| 7 | +### Triggering Events |
| 8 | +- **Pull Requests**: Triggers on `opened`, `synchronize`, and `reopened` events |
| 9 | +- **Branch Pushes**: Triggers on pushes to any branch except `main` (which has its own deployment workflow) |
| 10 | + |
| 11 | +### Deployment Paths |
| 12 | + |
| 13 | +The workflow deploys to the `gh-pages` branch using the following path structure: |
| 14 | + |
| 15 | +- **Pull Requests**: `pr/<pr-number>-<short-sha>/` |
| 16 | + - Example: `pr/42-abc1234/` |
| 17 | + |
| 18 | +- **Branches**: `branch/<safe-branch-name>-<short-sha>/` |
| 19 | + - Example: `branch/feature_new-ui-a7b8c9d/` |
| 20 | + |
| 21 | +### Base URL Configuration |
| 22 | + |
| 23 | +The workflow automatically: |
| 24 | +1. Fetches the GitHub Pages URL using the `gh` CLI |
| 25 | +2. Falls back to `https://<owner>.github.io/<repo>` if Pages isn't configured |
| 26 | +3. Builds the examples app with the correct base href using Parcel's `--public-url` option |
| 27 | +4. All asset paths are absolute URLs pointing to the correct subdirectory |
| 28 | + |
| 29 | +### Features |
| 30 | + |
| 31 | +- ✅ **Automatic PR Comments**: Posts a comment on PRs with the preview URL |
| 32 | +- ✅ **Branch Sanitization**: Safely handles branch names with special characters |
| 33 | +- ✅ **Incremental Deployments**: Each commit creates a new deployment with a unique SHA |
| 34 | +- ✅ **Job Summaries**: Provides deployment URL in GitHub Actions summary |
| 35 | +- ✅ **gh-pages Auto-Init**: Creates the gh-pages branch if it doesn't exist |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +### For Pull Requests |
| 40 | +1. Open a pull request |
| 41 | +2. Wait for the workflow to complete |
| 42 | +3. Click the preview URL in the automated comment |
| 43 | +4. Each new commit will update the deployment (with a new SHA in the path) |
| 44 | + |
| 45 | +### For Branch Pushes |
| 46 | +1. Push commits to any branch (except `main`) |
| 47 | +2. Check the workflow run for the deployment URL in the summary |
| 48 | +3. Access your preview at: `https://<owner>.github.io/<repo>/branch/<branch-name>-<sha>/` |
| 49 | + |
| 50 | +## Permissions Required |
| 51 | + |
| 52 | +The workflow needs the following permissions: |
| 53 | +- `contents: write` - To push to the gh-pages branch |
| 54 | +- `pull-requests: write` - To comment on pull requests |
| 55 | +- `pages: read` - To fetch the GitHub Pages URL |
| 56 | + |
| 57 | +## Build Process |
| 58 | + |
| 59 | +1. Install root dependencies and build the library |
| 60 | +2. Install example app dependencies |
| 61 | +3. Clean previous builds |
| 62 | +4. Generate API documentation |
| 63 | +5. Build example app with Parcel using custom `--public-url` |
| 64 | +6. Deploy to gh-pages branch in the appropriate subdirectory |
| 65 | + |
| 66 | +## Customization |
| 67 | + |
| 68 | +### Changing the Deployment Path Format |
| 69 | + |
| 70 | +Edit the "Determine deployment path" step in `.github/workflows/deploy-preview.yml`: |
| 71 | + |
| 72 | +```yaml |
| 73 | +- name: Determine deployment path |
| 74 | + id: deployment-path |
| 75 | + run: | |
| 76 | + # Modify DEPLOY_DIR and BASE_HREF variables here |
| 77 | +``` |
| 78 | +
|
| 79 | +### Changing Build Configuration |
| 80 | +
|
| 81 | +The build uses Parcel with the following options: |
| 82 | +- `--no-optimize`: Faster builds, easier debugging |
| 83 | +- `--public-url`: Dynamic base URL for assets |
| 84 | + |
| 85 | +To modify, edit the "Build example with base href" step. |
| 86 | + |
| 87 | +## Troubleshooting |
| 88 | + |
| 89 | +### Preview URL returns 404 |
| 90 | +- Ensure GitHub Pages is enabled for the repository |
| 91 | +- Check that the gh-pages branch exists |
| 92 | +- Verify the deployment path in the workflow logs |
| 93 | + |
| 94 | +### Assets not loading |
| 95 | +- Check the browser console for failed requests |
| 96 | +- Verify the base href is correct in the deployed HTML |
| 97 | +- Ensure all asset paths are absolute URLs |
| 98 | + |
| 99 | +### Workflow fails to push |
| 100 | +- Check repository permissions |
| 101 | +- Verify the `GITHUB_TOKEN` has write access to contents |
0 commit comments