https://docs.github.com/cn/actions
在 GitHub Actions 的仓库中自动化、自定义和执行软件开发工作流程。 您可以发现、创建和共享操作以执行您喜欢的任何作业(包括 CI/CD),并将操作合并到完全自定义的工作流程中。
uses: actions/checkout@v2
这一行的默认配置,使用是获取当前 $GITHUB_WORKSPACE 下的仓库文件
- 在您的仓库中,创建 .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 部署密钥
使用以下命令生成部署密钥。
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’

128:
name: Pageson:push:branches:- master # default branchjobs:pages:runs-on: ubuntu-latest # 定运行所需要的虚拟机环境permissions:contents: writesteps:- uses: actions/checkout@v2- name: Use Node.js 16.xuses: actions/setup-node@v2with:node-version: '16.14.1'# - run: node -v # 查看node版本号# 缓存依赖项: https://docs.github.com/cn/actions/using-workflows/caching-dependencies-to-speed-up-workflows- name: Cache NPM dependenciesuses: actions/cache@v2with:# npm cache files are stored in `~/.npm` on Linux/macOSpath: ~/.npm# path: node_moduleskey: ${{ runner.OS }}-npm-cacherestore-keys: |${{ runner.OS }}-npm-cache# 查看路径 : /home/runner/work/blog/blog# - name: Look Path# run: pwd# 查看文件- name: Look Dir Listrun: ls# 第一次或者依赖发生变化的时候执行 Install Dependencies,其它构建的时候不需要这一步- name: Install Dependenciesrun: npm install- name: Look Dir Listrun: ls- name: clean theme cacherun: git rm -f --cached themes/tenacity# 安装主题- name: Install Themerun: git submodule add https://github.com/all-smile/tenacity.git themes/tenacity- name: Cleanrun: npm run clean- name: Buildrun: npm run build- name: Deployuses: peaceiris/actions-gh-pages@v3with:deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}user_name: xiaouser_email: allblue95@126.comcommit_message: ${{ github.event.head_commit.message }}full_commit_message: ${{ github.event.head_commit.message }}github_token: ${{ secrets.GITHUB_TOKEN }}# GITHUB_TOKEN不是个人访问令牌,GitHub Actions 运行器会自动创建一个GITHUB_TOKEN密钥以在您的工作流程中进行身份验证。因此,您无需任何配置即可立即开始部署publish_dir: ./publicallow_empty_commit: true # 允许空提交# Use the output from the `deploy` step(use for test action)- name: Get the outputrun: |echo "${{ steps.deploy.outputs.notify }}"
