Automatic System Switchover

Use GitHub Actions to automatically deploy your Hugo blog to GitHub Pages and Gitee.

Background Introduction

Yesterday while updating the blog, I discovered that the travis service was unavailable. Upon checking the travis webpage, I noticed the progress was stuck during source code retrieval, and a flash of insight occurred – I thought about GitHub’s previously launched action service.

Due to being busy at the time and also needing to apply for access to use action, it has now officially gone live. With some free weekend time, I decided to try out a new toy?

Official documentation can be found by entering the website yourself; this article won’t provide further reprints. If you’ve used Kubernetes before, you’ll find that the action YAML file configuration is very similar.

Regarding introductory tutorials or Chinese introduction materials, I recommend searching for 阮一峰’s blog. There are two articles – the first introduces the basic syntax, and the second provides a practical case study.

#### Content

Required Knowledge Points
- GitHub Secrets
- Action Syntax
Core jobs use existing components to complete, pushing to domestic Gitee uses command implementation, this command part is quite brutal, all are forced pushes, inherited from the logic used with Travis.

```yaml
name: github pages and gitee pages

on:
  push:
    branches:
      - hugo

jobs:
  deploy:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: 'latest'
          extended: true

      - name: Build Github and Gitee ## Single step can only write one run command
        run: hugo -b "https://www.xiangtianlong.com/" -d "github_public" && hugo -b "https://www.xiangtianlong.com/" -d "gitee_public" && ls

      - name: Deploy Github
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.BLOG_TOKEN }}
          publish_dir: ./github_public
          publish_branch: master
          cname: xiangtianlong.com

      - name: Deploy Gitee
        run: cd ./gitee_public && git init && git config user.name "TianlongXiang" && git config user.email "tianlongxiang51@gmail.com" && git add . && git commit -m "Update TianlongXiang's Blog" && git push --force "https://xiangtianlong:${{ secrets.GITEE_PASSWORD }}@gitee.com/xiangtianlong/xiangtianlong.git" master:master

#### Epilogue

Based on the actions provided by the official market, currently there are quite a few supported playstyles. After building a Docker image, it’s no longer dependent on services offered by Docker Hub. 

Reviewing the Hugo issues, using GitHub Actions to automatically deploy Git Pages results in the final published website needing to be on the master branch. If deployed from another branch, the settings interface will prompt an error indicating that the deployed webpage has syntax problems.

This is simply because Hugo’s source files are located on the master branch, and GitHub treats it as the Jelly blog's source code for detection, unable to check and resolve any errors resulting in the error message. 

The solution is straightforward: move Hugo source files to another branch and publish static files to the master branch.
A financial IT programmer's tinkering and daily life musings
Built with Hugo
Theme Stack designed by Jimmy