添加FTP清理步骤并优化部署流程 #61
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Hexo Deploy | |
| on: | |
| push: | |
| branches: | |
| - main # 触发条件,当 main 分支有 push 事件时触发 | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest # 运行环境 | |
| steps: | |
| - name: Checkout Source | |
| uses: actions/checkout@v2 # 检出代码 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: '20' # 选择 Node.js 版本 | |
| - name: Install Dependencies | |
| run: npm install # 安装 Hexo 依赖 | |
| - name: Hexo Generate | |
| run: npm run build # 构建 Hexo 静态文件 | |
| - name: Set Git information # 设置git信息 | |
| run: | | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| - name: Switch baranch # 切换分支 | |
| run: | | |
| git checkout -b gh-pages | |
| - name: Clear barauch files # 清除当前分支内容 | |
| run: git rm -rf . | |
| - name: Copy files # 复制生成的静态文件到gh-Pages分支 | |
| run: cp -r ./public/* . | |
| - name: Clear unuseful files # 清除无用文件 | |
| run: | | |
| rm -rf ./public | |
| rm -rf ./node_modules | |
| - name: Deploy to gh-pages Branch | |
| run: | | |
| # 添加所有文件到 git | |
| git add . | |
| # 提交更改 | |
| git commit -m "Update gh-pages branch with latest build" | |
| # 推送到远程 HTML 分支 | |
| git push origin gh-pages --force | |
| - name: Clear Server | |
| uses: StephanThierry/ftp-delete-action@v2.1 | |
| with: | |
| host: ${{ secrets.FTP_HOST }} | |
| user: ${{ secrets.FTP_USERNAME }} | |
| password: ${{ secrets.FTP_PASSWORD }} | |
| remoteDirectories: /wwwroot/ | |
| - name: Deploy to FTP Server | |
| uses: SamKirkland/FTP-Deploy-Action@v4.3.4 | |
| with: | |
| server: ${{ secrets.FTP_HOST }} # FTP 服务器地址 | |
| username: ${{ secrets.FTP_USERNAME }} # FTP 用户名 | |
| password: ${{ secrets.FTP_PASSWORD }} # FTP 密码 | |
| local-dir: ./ | |
| server-dir: /wwwroot/ |