Huy's Notes
Automate your static blog deployment with Github Page

Automate your static blog deployment with Github Page

Previously, I have a Gatsby blog managed in a private repository named huytd/blog, and everytime I write something, I had to run the gatsby build command and push everything in the public folder (Gatsby's default output folder) into a public Github Pages repository named huytd/

I want to setup a Github Action to automate this workflow, so all I need to do is just write and push. Or when I use some online markdown editor like, I can just forget about pushing stuff too.

The idea of the workflow would be:

  1. Checkout the private huytd/blog repository into tho root folder
  2. Checkout the public huytd/ repository into /public folder
  3. Run gatsby build in the root folder
  4. Commit and push the changes in public folder to the public repository

Here's the full workflow:

name: Gatsby Publish

      - master

    runs-on: ubuntu-latest
      - uses: actions/[email protected]
      - uses: actions/[email protected]
          repository: 'huytd/'
          token: ${{ secrets.ACCESS_TOKEN }}
          path: 'public'
      - name: Setting up
        run: |
         npm install
         npm run build
      - name: Push to Github Pages
        run: |
         cd public
         git config github-actions
         git config [email protected]
         git add .
         git commit -m "generated"
         git push

Referred in

If you think this note resonated, be it positive or negative, please feel free to send me an email and we can talk.