简单记录,步骤潦草
示例
1. .gitignore
根路径 .gitignore 内容
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | .DS_Store#/Thumbs.db
 /db.json
 *.log
 node_modules/
 public/
 .deploy*/
 .deploy_git/
 .deploy_git*/
 .idea
 themes/butterfly/.git
 
 | 
2. workflows
根路径 .github/workflows/autodeploy.yml 内容
| 12
 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
 64
 65
 66
 67
 68
 69
 70
 
 | name: Auto deploy
 on:
 workflow_dispatch:
 push:
 branches:
 - main
 
 jobs:
 deploy:
 runs-on: ubuntu-latest
 steps:
 - name: 检查分支
 uses: actions/checkout@v2
 with:
 ref: main
 
 - uses: szenius/set-timezone@v1.0
 with:
 timezoneLinux: "Asia/Shanghai"
 
 - name: 安装 Node
 uses: actions/setup-node@v1
 with:
 node-version: "18.x"
 
 - name: 安装 Hexo
 run: |
 export TZ='Asia/Shanghai'
 npm install hexo-cli -g
 
 - name: 缓存 Hexo
 uses: actions/cache@v4
 id: cache
 with:
 path: node_modules
 key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}
 
 - name: 安装依赖
 if: steps.cache.outputs.cache-hit != 'true'
 run: |
 npm install gulp-cli -g #全局安装gulp
 npm install --save
 
 - name: Generate static file
 run: |
 hexo clean ; hexo generate ; gulp
 
 - name: 推送百度 url
 run: |
 hexo deploy
 
 - name: Deploy static file
 run: |
 cd ./public
 git init
 git config --global user.email 'github-actions[bot]@users.noreply.github.com'
 git config --global user.name 'github-actions[bot]'
 git add .
 git commit -m "$(date +'%Y/%m/%d')"
 git push --force --quiet "https://mycpen:${{ secrets.GH_TOKEN }}@github.com/mycpen/blog.git" master:main
 
 - name: Delete workflow runs
 uses: Mattraks/delete-workflow-runs@v2
 with:
 token: ${{ secrets.GH_TOKEN }}
 repository: ${{ github.repository }}
 retain_days: 30
 keep_minimum_runs: 6
 
 
 | 
Actions Secrets 变量含义
3. 插件
hexo-baidu-url-submit:https://github.com/huiwang/hexo-baidu-url-submit
根路径 _config.yml 配置文件
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 
 | 
 deploy:
 - type: baidu_url_submitter
 
 
 
 baidu_url_submit:
 count: 1000
 host: blog.xxx.com
 token: xxxxxx
 path: baidu_urls.txt
 
 | 
参考
- Akilar | 使用Github Action实现全自动部署 
- 安知鱼 | hexo博客工作流CI(一键部署的快乐) 
- CCKNBC | 工作流示例 
- https://github.com/Mattraks/delete-workflow-runs 
- https://github.com/dmego/home.github.io/blob/gh-pages/.github/workflows/auto-bing.yml