⚠️ This post links to an external website. ⚠️
GitHub Pages offers a free way to host static websites, usually at a single URL per repository. However, it presents challenges when trying to preview pull requests (PRs). Instead of relying on third-party services for PR previews, I discovered a workaround by hosting them within the main GitHub Pages site under subdirectories named after the PR numbers.
When a PR is opened, a GitHub Actions workflow automates the deployment of the site to a URL like
https://<username>.github.io/<repository>/previews/pr-123/. This method allows for quick previews, albeit with caveats such as managing relative asset paths and updating therobots.txtfile to prevent indexing. I implemented two workflows: one for deploying PR previews upon opening or updating a PR and another for deploying the main site when changes are merged. This approach streamlines my process without relying on external services.
continue reading onblog.danskingdom.com
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.