使用Github Actions部署静态网站
介绍
是由Go语言实现的静态网站生成器。简单、易用、高效、易扩展、快速部署。
是一个CI / CD工具,用于自动化GitHub中的测试,构建和部署过程。
步骤
1:创建GitHub仓库
创建创建GitHub仓库并命名为。
2:安装HUGO并创建项目
在Window 10上安装HUGO需要在官方仓库的页面下载最新版本HUGO的编译文件到本地并配置环境变量。
# 创建项目
hugo new .github.io
# 安装主题
git clone --depth 1 --recursive https://github.com/gohugoio/hugoThemes.git themes
# 本地运行
hugo server -D
3:将HUGO项目推送至GitHub仓库
# 初始化仓库
git init
# 将全部文件添加到暂存区
git add *
# 提交暂存区代码
git commit -m "创建HUGO项目"
# 创建主分支
git branch -M main
# 配置远程Github仓库
git remote add origin https://github.com//.github.io.git
# 推送代码到远程Github仓库
git push -u origin main
4:创建GitHub的token
5:将token添加到Github仓库密钥配置中
在仓库的->页面创建创库密钥并把token粘贴到value中。
6:创建GitHub Action配置文件
在仓库创建配置文件。
name: HUGO
on: push
jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Update theme
run: git submodule update --init --recursive
- name: Setup hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "0.64.0"
- name: Build
run: hugo --minify
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.ACTIONS_DEPLOY_KEY }}
external_repository: /.github.io
publish_dir: ./public
user_name:
user_email:
publish_branch: gh-pages