'Deploying Hugo onto staging website from feature branch
I was wondering whether there are folks out there who have found a proper solution for the following... We have a Hugo static website for which the code resides in a git repository. When making changes to the website, we create a pull request which kicks off a build which in turn deploys the code from the build onto a staging environment (Azure storage account linked to a CDN).
This works fine, but has one major limitation: the staging account always reflects only the pull request which was created the latest. So when two people are working on changes, on the last updated PR is deployed to the staging account as it will overwrite changes made in other feature branches.
Now of course this in itself is not necessarily something that is caused by Hugo or Azure or git. But it does require a solution which is fit for this particular scenario. One thing I considered is to deploy onto the storage account with another level of subfolders including the feature branch name. But I'm not sure how you would be able to get that into your config.toml where the $web container is specified. Maybe Hugo has some trick for this scenario but I haven't found it yet. So any good ideas on this are welcome.
Solution 1:[1]
I have done this for my personal website using GitHub Actions. I have the workflow build the site with a different base URL, something like:
hugo --baseURL https://demo.bbaovanc.com/pull_request/[ID]
where [ID]
is the pull request number, defined by the ${{ github.event.number }}
variable, which works in GitHub Actions. Then I upload it to my server under the correct directory for it to be accessible at that URL. I also have a different workflow which automatically deletes the preview when the pull request is closed or merged.
Hopefully this helps, although I don't know how you could get the pull request number (or feature branch name) if you're using something else (Azure?) instead of GitHub Actions to build the site.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | bbaovanc |