name: 自动部署
# 当有改动推送到master分支时,启动Action
on:
  push:
    branches:
      - main
      #2020年10月后github新建仓库默认分支改为main,注意更改
  release:
    types:
      - published

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: 检查分支
        uses: actions/checkout@v2
        with:
          ref: main

      - name: 安装 Node
        uses: actions/setup-node@v1
        with:
          node-version: '16.x'

      - name: 安装 Hexo
        run: |
          export TZ='Asia/Shanghai'
          npm install hexo-cli -g

      - name: 缓存 Hexo
        uses: actions/cache@v1
        id: cache
        with:
          path: node_modules
          key: ${{runner.OS}}-${{hashFiles('**/package-lock.json')}}

      - name: 安装依赖
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
          npm install gulp
                   
          npm install gulp-cli -g #全局安装gulp
          npm install --save
          
      - name: 缓存 Suka
        uses: actions/cache@v1
        id: suka
        with:
          path: themes/suka/node_modules
          key: ${{runner.OS}}-${{hashFiles('**/themes/suka/package-lock.json')}}
          
          
      - name: 安装依赖suka
        if: steps.suka.outputs.cache-hit != 'true'
        run: |
          
          cd themes/suka
          npm i --production
          
          
          
      - name: 连接密钥
        run: |
          mkdir -p ~/.ssh
          echo "$SSH_DEPLOY_KEY" | tr -d '\r' > ~/.ssh/id_rsa
          chmod 600 ~/.ssh/id_rsa
          ssh-keyscan -H 'github.com' >> ~/.ssh/known_hosts
        env:
          SSH_DEPLOY_KEY: ${{ secrets.HEXO_DEPLOY_PRI }}

      - name: Prepare git env
        run: |
          git config --global user.email 1833505972@qq.com
          git config --global user.name huntersxy
      
      - name: Deploy Blog
        run: | 
          hexo generate -d -f 
最后修改:2025 年 06 月 05 日
如果觉得我的文章对你有用,请随意赞赏