https://docs.github.com/cn/actions
在 GitHub Actions 的仓库中自动化、自定义和执行软件开发工作流程。 您可以发现、创建和共享操作以执行您喜欢的任何作业(包括 CI/CD),并将操作合并到完全自定义的工作流程中。

uses: actions/checkout@v2
这一行的默认配置,使用是获取当前 $GITHUB_WORKSPACE 下的仓库文件

  1. 在您的仓库中,创建 .github/workflows/ 目录来存储工作流程文件。

Hexo配置GitHub Actions

https://github.com/peaceiris/actions-gh-pages#readme

支持的令牌

支持三个令牌。

令牌 私人仓库 公开仓库 协议 设置
github_token ✅️ ✅️ HTTPS 不必要
deploy_key ✅️ ✅️ SSH 必要的
personal_token ✅️ ✅️ HTTPS 必要的

注意:GITHUB_TOKEN不是个人访问令牌,GitHub Actions 运行器会自动创建一个GITHUB_TOKEN密钥以在您的工作流程中进行身份验证。因此,您无需任何配置即可立即开始部署

支持的平台

所有 Actions 运行器:支持 Linux (Ubuntu)、macOS 和 Windows。

连续运行 github_token deploy_key personal_token
ubuntu-20.04 ✅️ ✅️ ✅️
ubuntu-18.04 ✅️ ✅️ ✅️
macos-最新 ✅️ ✅️ ✅️
windows-最新 ✅️ (2) ✅️

具体操作

⭐️设置 SSH 私钥deploy_key

创建 SSH 部署密钥

使用以下命令生成部署密钥。

  1. ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""

您将获得 2 个文件:

  • gh-pages.pub是公钥
  • gh-pages是私钥

接下来,转到博客源码存储库设置

  • 转到Deploy Keys并使用Allow write access添加您的公钥 gh-pages.pub
  • 转到Actions secrets并将您的私钥 gh-pages 添加为 ACTIONS_DEPLOY_KEY

valid inputs:
‘deploy_key’, ‘github_token’, ‘personal_token’, ‘publish_branch’, ‘publish_dir’, ‘destination_dir’, ‘external_repository’, ‘allow_empty_commit’, ‘keep_files’, ‘force_orphan’, ‘user_name’, ‘user_email’, ‘commit_message’, ‘full_commit_message’, ‘tag_name’, ‘tag_message’, ‘enable_jekyll’, ‘disable_nojekyll’, ‘cname’, ‘exclude_assets’

757f8999c9ead46b1b8d0525fe36b58.jpg
128:
edf36419413540e72ce96c727f2c403.jpg

  1. name: Pages
  2. on:
  3. push:
  4. branches:
  5. - master # default branch
  6. jobs:
  7. pages:
  8. runs-on: ubuntu-latest # 定运行所需要的虚拟机环境
  9. permissions:
  10. contents: write
  11. steps:
  12. - uses: actions/checkout@v2
  13. - name: Use Node.js 16.x
  14. uses: actions/setup-node@v2
  15. with:
  16. node-version: '16.14.1'
  17. # - run: node -v # 查看node版本号
  18. # 缓存依赖项: https://docs.github.com/cn/actions/using-workflows/caching-dependencies-to-speed-up-workflows
  19. - name: Cache NPM dependencies
  20. uses: actions/cache@v2
  21. with:
  22. # npm cache files are stored in `~/.npm` on Linux/macOS
  23. path: ~/.npm
  24. # path: node_modules
  25. key: ${{ runner.OS }}-npm-cache
  26. restore-keys: |
  27. ${{ runner.OS }}-npm-cache
  28. # 查看路径 : /home/runner/work/blog/blog
  29. # - name: Look Path
  30. # run: pwd
  31. # 查看文件
  32. - name: Look Dir List
  33. run: ls
  34. # 第一次或者依赖发生变化的时候执行 Install Dependencies,其它构建的时候不需要这一步
  35. - name: Install Dependencies
  36. run: npm install
  37. - name: Look Dir List
  38. run: ls
  39. - name: clean theme cache
  40. run: git rm -f --cached themes/tenacity
  41. # 安装主题
  42. - name: Install Theme
  43. run: git submodule add https://github.com/all-smile/tenacity.git themes/tenacity
  44. - name: Clean
  45. run: npm run clean
  46. - name: Build
  47. run: npm run build
  48. - name: Deploy
  49. uses: peaceiris/actions-gh-pages@v3
  50. with:
  51. deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
  52. user_name: xiao
  53. user_email: allblue95@126.com
  54. commit_message: ${{ github.event.head_commit.message }}
  55. full_commit_message: ${{ github.event.head_commit.message }}
  56. github_token: ${{ secrets.GITHUB_TOKEN }}
  57. # GITHUB_TOKEN不是个人访问令牌,GitHub Actions 运行器会自动创建一个GITHUB_TOKEN密钥以在您的工作流程中进行身份验证。因此,您无需任何配置即可立即开始部署
  58. publish_dir: ./public
  59. allow_empty_commit: true # 允许空提交
  60. # Use the output from the `deploy` step(use for test action)
  61. - name: Get the output
  62. run: |
  63. echo "${{ steps.deploy.outputs.notify }}"