68
Github Action for Gatsby Publish
The gatsby template includes scripting to deploy from whereever you cloned your code. It works just fine and is reliable when everything is set up on my machine. The package.json includes the deploy script:
"scripts": {
...
"deploy": "gatsby build --prefix-paths && gh-pages -d public"
},
However, there are 2 drawbacks for my workflow (and my goal to start writing more):
I was using a Github Action for my Jekyll site, prior to moving to Gatsby, and that worked when I pushed to branch and kickoff the publish action. This action was a bit more involved as I was using Azure for a host and it required a few more configuration hurdles to set it up.
For my current site, I thought it has to be pretty simple - push to main branch, trigger an action, copy to gh-pages branch and that's that. Turns out, that is that and I was able to get it working pretty fast.
I documented my steps in case I need to go back and change anything - e.g. I would like to update the siteMetadata.version in the gatsby-config.js file at some point. Here are the steps
name: Gatsby Publish
on:
push:
branches:
main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: enriikke/gatsby-gh-pages-action@v2
with:
access-token: ${{ secrets.ACCESS_TOKEN }}
deploy-branch: gh-pages
Create a personal access token (PAT), select the repo permission.
Create a Secret in the repo: ACCESS_TOKEN and use the new PAT token (note the workflow YAML file specifies the ACCESS_TOKEN parameter).
Build should kick in and go green
Profit?
And lo and behold, my site is passing (hopefully this shows it's passing):
68