Operations 7 min read

Automating Hugo Blog Deployment with GitHub Actions and Gitee Mirror

This guide explains how to version‑control Hugo blog posts on GitHub, set up a GitHub Actions workflow that builds and publishes the static site, and mirror the generated pages to Gitee for faster access, covering branch strategy, CI/CD steps, and required code snippets.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Automating Hugo Blog Deployment with GitHub Actions and Gitee Mirror

To keep blog articles under version control, a GitHub repository is created to store the Hugo source files on the main branch while a separate pages-git branch holds the compiled static HTML.

Repository and Branch Setup

The repository uses Hugo with Markdown content and a chosen theme. The main branch contains the source, and the pages-git branch is dedicated to the generated public directory.

GitHub Actions CI/CD Workflow

A workflow triggers on pushes to main . The essential configuration is:

name: github pages
on:
  push:
    branches: [ main ]

The job checks out the code, deletes the previous pages-git branch, and runs Hugo to build the site:

jobs:
  deploy:
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
        with:
          submodules: true
          fetch-depth: 0
      - name: Delete branch
        uses: dawidd6/action-delete-branch@v3
        with:
          github_token: ${{ secrets.GIT_TOKEN }}
          branches: "pages-git"

Next, Hugo is installed and the site is built:

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

- name: Build
  run: |
    hugo --minify
    ls public
    tar zcf ${version}-public.tar.gz public
    ls

After building, all files except the public directory are removed, the generated files are moved to the root, and the changes are committed to the pages-git branch:

- name: commit
  run: |
    rm -fr archetypes content demo static themes .DS_Store 1.1.0-public.tar.gz README.md config.toml
    mv public/* ./
    sleep 3
    ls -l
    rm -fr public
    git config --global user.email [email protected]
    git config --global user.name cccc
    git add .
    git commit -m "update" -a

Finally, the workflow pushes the pages-git branch:

- name: Push changes
  uses: ad-m/github-push-action@master
  with:
    github_token: ${{ secrets.GIT_TOKEN }}
    branch: "pages-git"

Mirroring to Gitee

Because GitHub Pages can be slow in some regions, the pages-git branch is mirrored to a Gitee repository using the repository‑mirroring action:

- name: get code
  uses: actions/checkout@v2
  with:
    submodules: true
    fetch-depth: 0
    ref: "pages-git"
- name: Mirror to gitee
  uses: pixta-dev/repository-mirroring-action@v1
  with:
    target_repo_url: [email protected]:devopsgo/devopsgo.git
    ssh_private_key: ${{ secrets.GIT_PRIVATE_KEY }}

After mirroring, Gitee Pages is triggered to deploy the static site, which can be accessed at devopsgo.gitee.io .

Workflow Usage

Authors write Markdown files locally, preview with hugo serve , commit to main , and the GitHub Actions pipeline automatically builds and publishes the site to both GitHub Pages and Gitee Pages.

The complete workflow enables seamless CI/CD for a Hugo blog, providing fast domestic access via Gitee while maintaining the original GitHub repository.

CI/CDDevOpsGiteeGitHub Actionshugostatic site
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.