deploy.yml
                        
                             · 1.5 KiB · YAML
                        
                    
                    
                      
                        Sin formato
                      
                    
                      
                    
                        
                          
                        
                    
                    
                
                
                
            name: 自动部署
on:
  push:
    branches:
      - main 
  release:
    types:
      - published
  workflow_dispatch:
env:
  TZ: Asia/Shanghai
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: 检查分支
      uses: actions/checkout@v3
      with:
        ref: main
    - name: 缓存项目 npm 包
      id: cache-node-modules
      uses: actions/cache@v3
      with:
        path: node_modules
        key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }}
        restore-keys: |
          ${{ runner.os }}-nodeModules-
    - name: 安装 Node
      uses: actions/setup-node@v3
      with:
        node-version: "20.x"
    - name: 安装 Hexo
      run: |
        npm install hexo-cli --global
    - name: 安装依赖
      if: steps.cache-node-modules.outputs.cache-hit != 'true'
      run: |
        npm install
    - name: 清理文件树
      run: |
        npm run clean
    - name: 生成静态文件并压缩
      run: |
        npm run build
    - name: 部署
      run: |
        cd ./public
        git init
        git config user.name "${{ github.actor }}"
        git config user.email "${{ github.actor }}@users.noreply.github.com"
        git add .
        git commit -m "${{ github.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]"
        git push --force --quiet "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" master:page
                | 1 | name: 自动部署 | 
| 2 | |
| 3 | on: | 
| 4 | push: | 
| 5 | branches: | 
| 6 | - main | 
| 7 | |
| 8 | release: | 
| 9 | types: | 
| 10 | - published | 
| 11 | |
| 12 | workflow_dispatch: | 
| 13 | |
| 14 | env: | 
| 15 | TZ: Asia/Shanghai | 
| 16 | |
| 17 | jobs: | 
| 18 | deploy: | 
| 19 | runs-on: ubuntu-latest | 
| 20 | steps: | 
| 21 | - name: 检查分支 | 
| 22 | uses: actions/checkout@v3 | 
| 23 | with: | 
| 24 | ref: main | 
| 25 | |
| 26 | - name: 缓存项目 npm 包 | 
| 27 | id: cache-node-modules | 
| 28 | uses: actions/cache@v3 | 
| 29 | with: | 
| 30 | path: node_modules | 
| 31 | key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} | 
| 32 | restore-keys: | | 
| 33 | ${{ runner.os }}-nodeModules- | 
| 34 | |
| 35 | - name: 安装 Node | 
| 36 | uses: actions/setup-node@v3 | 
| 37 | with: | 
| 38 | node-version: "20.x" | 
| 39 | |
| 40 | - name: 安装 Hexo | 
| 41 | run: | | 
| 42 | npm install hexo-cli --global | 
| 43 | |
| 44 | - name: 安装依赖 | 
| 45 | if: steps.cache-node-modules.outputs.cache-hit != 'true' | 
| 46 | run: | | 
| 47 | npm install | 
| 48 | |
| 49 | - name: 清理文件树 | 
| 50 | run: | | 
| 51 | npm run clean | 
| 52 | |
| 53 | - name: 生成静态文件并压缩 | 
| 54 | run: | | 
| 55 | npm run build | 
| 56 | |
| 57 | - name: 部署 | 
| 58 | run: | | 
| 59 | cd ./public | 
| 60 | git init | 
| 61 | git config user.name "${{ github.actor }}" | 
| 62 | git config user.email "${{ github.actor }}@users.noreply.github.com" | 
| 63 | git add . | 
| 64 | git commit -m "${{ github.event.head_commit.message }}··[$(date +"%Z %Y-%m-%d %A %H:%M:%S")]" | 
| 65 | git push --force --quiet "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" master:page | 
| 66 |