GitHub Pages provides hosting for static files by serving a branch (e.g. gh-pages) of the respective repository. GitHub Actions can be used to automate deployments, avoiding the hassle of having to update that branch manually when the main branch (typically master) changes.
The idea of using other people’s actions made me slightly uncomfortable, due to mild security concerns (handing full repo access to some unknown party) and the complexity of excessive abstraction (who wants to read documentation when they can write code instead…. ). So I set out to automate this myself – thinking it should be straightforward:
Here we run
./bin/build (a placeholder for
npm start or similar) to
generate build artifacts in the
dist directory and then commit them to the
gh-pages branch. The script relies on various
We can make GitHub Actions execute that script (
creating a workflow description (e.g.
Note that we pass in
GITHUB_TOKEN, which is used in the script’s repo URI to
provide read/write access.
However, turns out that repo updates using
do not trigger GitHub Pages builds.
(Which was not at all obvious… )
So we need to
generate a personal access token, add it
to respective repo’s
(via Settings → Secrets; named
DEPLOY_TOKEN here) and use that instead of
With those adjustments, our automated repo updates finally result in GitHub Pages being published as well.
PS: In my case, the repo in question is a Node-based
application, so the workflow file includes a few