How to Build Blog(deploy)

Build hugo Static blog (Deployment)

1. Ready

2. Create repository and environments

  • ‘Create a new repository’ in GitHub

    • name:yourusername.github.com
  • Create Token

    • usr-setting-Develop Settings-Personal access tokens
    • set Expiration never
    • checkrepo and workflow
  • Link Token to repository

    • Open repository - setting - Actions secrets and variables
    • New secrets. name: TOKEN

3. Create a workflow

  • Create ‘.github/workflows/hugo_de.yaml ‘in sequence inside the your-blog-site directory
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
name: deploy

# 代码提交到main分支时触发github action
on:
  push:
    branches:
      - dev

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
        - name: Checkout
          uses: actions/checkout@v4
          with:
              fetch-depth: 0

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

        - name: Build Web
          run: hugo -D

        - name: Deploy Web
          uses: peaceiris/actions-gh-pages@v4
          with:
              PERSONAL_TOKEN: ${{ secrets.TOKEN }} #The TOKEN is the name you just created in the library, as you fill it in.
              EXTERNAL_REPOSITORY: your-username/your-repository-name
              PUBLISH_BRANCH: main
              PUBLISH_DIR: ./public
              commit_message: auto deploy

This automator publishes your locally undeployed files to the dev branch, and the Action is automatically deployed to the main branch

4. Deploy to GitHub

  • In the home directory, type:
1
2
3
4
5
6
git init
git add .
git commit -m "update"
git branch -M dev
git remote add origin https://github.com/your-username/your-repository-name.git
git push -u origin dev
  • Set GitHub Page
    • repository-setting-general-Default branch:main
    • repository-setting-page-Deploy from a branch:main
Licensed under CC BY-NC-SA 4.0