一、安装 Deploy keys and Secrets

针对的是存放 Hexo 源文件和网站文件分开存放的场景。

1、 运行以下终端命令,将电子邮件替换为与您的GitHub帐户相连的电子邮件。

ssh-keygen -t rsa -C “username@example.com

2、在网站文件仓库添加public key。进入Settings > Deploy Keys找到这个选项,可以随意命名公钥,但是需要给它写访问权。

3、在Hexo源文件仓库添加private key。进入Settings > Secrets中添加一个名叫DEPLOY_KEY的Secret。

二、Actions脚本

  name: Deploy

  on: [push]

  jobs:
    build:
      runs-on: ubuntu-latest
      name: A job to deploy blog.
      steps:
      - name: Checkout
        uses: actions/checkout@v1
        with:
          submodules: true # Checkout private submodules(themes or something else).
      
      # Caching dependencies to speed up workflows. (GitHub will remove any cache entries that have not been accessed in over 7 days.)
      - name: Cache node modules
        uses: actions/cache@v1
        id: cache
        with:
          path: node_modules
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
      - name: Install Dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: npm install
      
      # Deploy hexo blog website.
      - name: Deploy
        id: deploy
        uses: sma11black/hexo-action@v1.0.0
        with:
          deploy_key: ${{ secrets.DEPLOY_KEY }}
          user_name: your github username
          user_email: your github useremail
      # Use the output from the `deploy` step(use for test action)
      - name: Get the output
        run: |
          echo "${{ steps.deploy.outputs.notify }}"