git 生成ssh key_Github Actions自动生成Hugo站点并部署

使用hugo建立建立个人网站可以参考https://hugotheme.cn/post/hugo-useage/

使用github pages来部署个人网站可以参考https://unixetc.com/post/create-a-free-blog-with-jekyll-and-github-page/

下面将会介绍如何通过Github Actions来将以上两个操作关联在一起并自动化完成!

45506ac700554b94bf534ee6a5235afa

建立Repositories

建立一个unixetc/ghsource.git属性为私有(private)的用来放置Hugo源码,然后再建一个unixetc/unixetc.gihub.io.git属性为公有(public)并设置Github Pages服务。

设置Deploy keys与Secrets

使用ssh-keygen命令来生成私钥与公钥。

$ ssh-keygen.exe -t rsa -b 4096 -C "alairs@live.cn"  #邮箱自定义Generating public/private rsa key pair.Enter file in which to save the key (/c/Users/alair/.ssh/id_rsa):   #存放目录,可自定义Created directory '/c/Users/alair/.ssh'.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /c/Users/alair/.ssh/id_rsa  #私钥Your public key has been saved in /c/Users/alair/.ssh/id_rsa.pub  #公钥 The key fingerprint is:SHA256:ZiNPDGtAKC6MA alairs@live.cnThe key's randomart image is:+---[RSA 4096]----+|      ..  +o.    ||     .  .  o..   ||  .   +  .... .  ||o+ o o =  .o .   ||+EO o = S . .    ||o  B . % + .     || .o .oB *        || ...++ B         || ... .. o        |+----[SHA256]-----+

在unixetc/unixetc.gihub.io.git的设置中将公钥内容添加至Deploy keys,名称自定义,并勾选allow write access

a1578aa9914a4720a0ad4ab5ba356bc7

在unixetc/hgsource.git的设置中将私钥内容添加至Secrets,命名为ACTIONSDEPLOYKEY,这个后面要用到。

bf39149be34341a8a28c22adb16b1955

设置Github Actions

为unixetc/hgsource.git设置Github Actions

658942690ed543958091db118e15d211

在新建的hgsource/.github/workfows/main.yml中填入以下内容:

name: Auto Build and Deploy  #actions名称,可自定义on:  push:    branches:      - masterjobs:  build-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 Hugo Site        run: hugo --minify        #生成站点      - name: Deploy to GitHub pages        uses: peaceiris/actions-gh-pages@v3        with:          deploy_key: ${{ secrets.ACTIONSDEPLOYKEY }} # 同上面私钥(Private Key)变量名          external_repository: unixetc/unixetc.github.io # Github Pages远程地址          publish_dir: "./public" #推送目录          keep_files: false # 删除已存在文件          publish_branch: master  # 推送          commit_message: ${{ github.event.head_commit.message }}

完成后保存即可。

自动生成并部署

将unixetc/ghsource.git Clone下来。

$git clone https://github.com/unixetc/hgsource.git

参考Hugo安装使用实例生成站点。

$git add .$git commit -m "update"$ git pushEnumerating objects: 360, done.Counting objects: 100% (360/360), done.Delta compression using up to 4 threadsCompressing objects: 100% (355/355), done.Writing objects: 100% (360/360), 3.09 MiB | 1.13 MiB/s, done.Total 360 (delta 3), reused 0 (delta 0), pack-reused 0remote: Resolving deltas: 100% (3/3), done.To https://github.com/unixetc/hgsource.git * [new branch]      master -> master

Push完后,即可触发Github Actions,生成后的站点可以通过https://unixetc.com查看。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值