上次将blog迁移到hugo之后部署在github pages上,源码放在master分支,编译后的静态文件放在blog分支,使用deplo.sh进行自动化部署,但是还有一个小问题,github pages的访问速度太慢了,因此我将使用github action将整个流程简化,github只托管源文件,每当有commit触发action,自动将编译后的静态文件上传到腾讯云。

原deploy.sh部署脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
hugo
cd public
echo heeeepin.com > CNAME
echo "# robots.txt
User-agent: Googlebot
Disallow:
User-agent: *
Disallow: /
Sitemap: Sitemap: https://heeeepin.com/sitemap.xml" > robots.txt
git add .
git commit -m "update"
git pull origin blog
git push origin master:blog
cd ..

新的github action编排

 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# This is a basic workflow to help you get started with Actions

name: Hugo Auto Tencent Cloud Base

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: macOS-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      - name: Install Brew
        run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    
      - name: Downlaod Hugo.rb
        run: wget https://raw.githubusercontent.com/Homebrew/homebrew-core/77788671577e53b2ccc31483f0988d5f5166d2b0/Formula/hugo.rb
        
      - name: Install Hugo
        run: brew install hugo.rb
      
      - name: Build Hugo
        run: hugo
        
      - name: Add Robots.txt
        run: |
          cd public
          echo "# robots.txt" > robots.txt
          echo "User-agent: Googlebot" >> robots.txt
          echo "Disallow: /page/*" >> robots.txt
          echo "User-agent: *" >> robots.txt
          echo "Disallow: /" >> robots.txt
          echo "Sitemap: https://heeeepin.com/sitemap.xml" >> robots.txt
          cd ..
    
      - name: Deploy static to Tencent CloudBase
        id: deployStatic
        uses: TencentCloudBase/cloudbase-action@v1.1.1
        with:
          secretId: ${{ secrets.SECRET_ID }}
          secretKey: ${{ secrets.SECRET_KEY }}
          envId: ${{ secrets.ENV_ID }}
          staticSrcPath: public
      
      - uses: actions/upload-artifact@v2
        with:
          name: Public Files
          path: public/
      
      - name: Done
        run: echo Done