嘛…结果兜兜转转还是回到Action来了…最近经历的事情真多啊,这里依然是我的私人小空间ww
总而言之先把该有的内容写好!
步骤
1. 创建仓库Repo
- 私人库A,设置为Private,这就是工程博客仓库
- 公开库B,设置为Public,用于Github Pages发布(你有Github Pro可以在private状态下发布)
2. 设置公私钥
执行命令获得一对ssh-key:
ssh-keygen -t rsa -b 4096 -C "hexo-deploy" -f hexo_deploy_key填写全部默认enter就行
此时你的根目录应该拥有
hexo-deploy_key以及hexo-deploy_key.pub设置公钥
- 进入Github公开库B(通常为博客的xxx.github.io),
settings→Deploy keys→Add deploy key - 填写
hexo_deploy_key.pub中的内容(title项随意) - 记得勾选
Allow write access
- 进入Github公开库B(通常为博客的xxx.github.io),
设置私钥
- 进入Github私人库A,
settings→Secrets and variables→New repository secret - 填写
hexo_deploy_key的内容(Name项随意)
- 进入Github私人库A,
3. 配置Github Action
创建文件
.github/workflows/deploy.yml(若文件夹缺失则创建补全)填写以下内容:
name: Hexo Deploy on: push: branches: - main # 或者是 master,取决于你的默认分支名 jobs: build: runs-on: ubuntu-latest steps: - name: Checkout source uses: actions/checkout@v3 with: # 如果你的主题是作为 git submodule 存在的,需要开启这个 # 具体取决于你的主题文件夹内是否存在.git文件夹,推荐删掉.git后false掉,以免莫名其妙的特性 submodules: false - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: "24" # Node版本,目前24是LTS cache: "npm" - name: Install dependencies run: npm install - name: Build Hexo run: npx hexo generate - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: deploy_key: ${{ secrets.HEXO_DEPLOY_PRI }} # 这里对应你在私有仓库设置的 Secret 名字 external_repository: username/username.github.io # 修改为你接收静态页面的公有仓库: 用户名/仓库名 publish_branch: main # 公开库B的branch,取决于你是main还是master publish_dir: ./public # 将./public文件夹推送过去,一般不用管 commit_message: ${{ github.event.head_commit.message }} user_name: "github-actions[bot]" user_email: "github-actions[bot]@users.noreply.github.com"接下来随便
hexo new一个Pages什么的,用git推送过去就可以享受自动更新了!
后记
结果也确实有段时间没碰博客了嘛……(其实很久很久…)
总而言之我回来诈尸一下,未来或许会有点oc内容呢?谁知道呢