Software Engineer | Ziff Davis | Cochin

How I Automatically Deploying This Blog?

Published July 1, 2022 🕐 2 Mins

This is a kinda sequel to My Blog Set up. So before explaining the current setup. I know you guys are curious about knowing about the previous setup. Before, my setup was like, I set up my blog’s build folder as a git submodule. so after completing writing my blog I manually take a build and push both repos (blog repo and build repo) to GitHub and then manually create merge requisites there and merge to master. This was like boring for me. and recently when got time I had some research on automatically deploying Hugo sites on GitHub pages and I found these two action plugins

So I created a GitHub workflow based on this plugin like this

name: Build and deploy

      - master # Set a branch name to trigger deployment

    runs-on: ubuntu-20.04
      contents: write
      group: ${{ github.workflow }}-${{ github.ref }}
      - uses: actions/checkout@v3
          submodules: true # Fetch Hugo themes (true OR recursive)
          fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
          hugo-version: "0.89.0"

      - name: Build
        run: hugo

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        # If you're changing the branch from main,
        # also change the `main` in `refs/heads/main`
        # below accordingly.
        if: ${{ github.ref == 'refs/heads/master' }}
          personal_token: ${{ secrets.PERSONAL_TOKEN }}
          external_repository: prinzpiuz/
          publish_dir: ./public
          publish_branch: master
          commit_message: ${{ github.event.head_commit.message }}

It’s very pretty straightforward, even though let me explain this very simple for newbies

  • I am telling action to run only when there is a push event to master
  • Then I am using checkout action to pull the latest code including submodules(this will ensure the latest changes in Hugo themes too)
  • Then I am using Hugo’s action I shared above to build my blog
  • Then I am using an action push build code into my repo using Github personal access token with a custom commit message

So whenever I create a merge request and merge it into master, deployment will automatically happen. Thanks to GitHub actions 👏🏼…