name: auto deploy

on:
  workflow_dispatch:
  push:
env:
  BING_TOKEN: ${{ secrets.BING_APIKEY }} 
  BAIDU_TOKEN: ${{ secrets.BAIDU_TOKEN }}

jobs:
  build:
    runs-on: ubuntu-latest # 运行环境为最新版 Ubuntu
    name: auto deploy
    steps:
    # 1. 获取源码
    - name: Checkout
      uses: actions/checkout@v3 # 使用 actions/checkout@v3
      with: # 条件
        submodules: true # Checkout private submodules(themes or something else). 当有子模块时切换分支？
    # 2. 配置环境
    - name: Setup Node.js 16.10.0
      uses: actions/setup-node@master
      with:
        node-version: "16.10.0"
        
        
        
        
    # 3. 生成静态文件
    - name: Generate Public Files
      run: |
        npm i
        npm install hexo-cli -g
        npm i hexo-web-push-notification --save
        npm install node-fetch@2.6.0 -s
        hexo clean && hexo generate
        npm install node-fetch@2.6.0 -s
        npm install js-md5 -s
        node update.js


    # 4. 部署到 GitHub 仓库（可选）
    - name: Deploy to GitHub Pages
      uses: peaceiris/actions-gh-pages@v3
      with:
        deploy_key: ${{ secrets.DEPLOY_KEY }}
        publish_branch: main
        publish_dir: ./public
        external_repository: Bytelv/Myblog
        exclude_assets: '.github'
        commit_message: ${{ github.event.head_commit.message }}
        user_name: 'github-actions[bot]'
        user_email: 'github-actions[bot]@users.noreply.github.com'
        

        

    
    
 #   - name: 部署
  #    uses: burnett01/rsync-deployments@6.0.0
   #   with:
    #    switches: -avzh
     #   path: public/
     #   remote_path: /opt/1panel/apps/openresty/openresty/www/sites/blog.lvbyte.top/index
     #   remote_host: 154.9.228.139
     #   remote_port: 22
     #   remote_user: root
     #   remote_key: ${{ secrets.SERVER_SSH_KEY }}
    
    
        
    - name: npm publish
      uses: JS-DevTools/npm-publish@v1
      with:
        token: ${{ secrets.NPM }}
        
    

