hexo设置

deploy:
  - type: git
    repo: https://<访问令牌>@<静态博客仓库地址>
    branch: main
    message: Site updated {{ now('YYYY-MM-DD HH:mm:ss') }}
  - type: shell
    # 私钥上传到仓库,如何获得私钥位置请看Github Actions设置
    command: 'scp -i <私钥> -r <本地目录> <用户名>@<主机地址>:<远程目录>'

Github Actions设置

name: Hexo deploy

on:
  push:
    branches:
      - main # 分支名
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18.13.0 # nodejs版本
      # 私钥上传仓库,查看Github Actions输出的原始日志查看私钥位置
      # - name: Get private key location
      #   run: |
      #     echo: "=======Private key location======="
      #     find / -name <私钥文件名>
      #     echo: "=================================="

      - name: Setting git
        env:
          PRIVATE_KEY: ${{secrets.PRIVATE_KEY}}
        run: |
          mkdir -p ~/.ssh/
          echo "$PRIVATE_KEY" > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          chmod 600 <私钥>
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          ssh-keyscan <主机地址> >> ~/.ssh/known_hosts
          git config --global user.name <名字>
          git config --global user.email <邮箱>
      - name: Hexo install
        run: |
          npm i -g hexo-cli
          npm install hexo-deployer-git --save
          npm install hexo-deployer-shell --save
          npm i
      - name: Hexo deploy
        run: |
          hexo clean
          hexo generate
          hexo deploy