每12小时更新一次reference #287
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: 每12小时更新一次reference | |
| on: | |
| schedule: | |
| - cron: '0 */12 * * *' | |
| workflow_dispatch: | |
| env: | |
| TZ: Asia/Shanghai | |
| SERVER_IP: 118.31.114.118 | |
| DEPLOY_PATH: /opt/1panel/www/sites/reference/index | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 🚜 拉取最新代码 | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: 'main' | |
| repository: 'jaywcjlove/reference' | |
| - name: ♻️ 编译静态文件 | |
| run: | | |
| echo -e 'REF_URL=https://ref.hanauta.icu\nREF_LABEL=网站首页' > .env | |
| npm install | |
| npm run build | |
| - name: 📊 检查文件大小 | |
| run: du -sh dist | |
| - name: 📦 压缩构建文件 | |
| run: | | |
| TIMESTAMP=$(date +%Y%m%d%H%M%S) | |
| tar -czf dist-$TIMESTAMP.tar.gz -C dist . | |
| echo "压缩完成,文件大小:" | |
| du -sh dist-$TIMESTAMP.tar.gz | |
| - name: 🚀 上传压缩包到服务器 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ env.SERVER_IP }} | |
| username: root | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| port: 22 | |
| source: "dist-*.tar.gz" | |
| target: "/tmp/" | |
| rm: true | |
| - name: 🛠️ 服务器端解压部署 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ env.SERVER_IP }} | |
| username: root | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| port: 22 | |
| script: | | |
| LATEST_TAR=$(ls -t /tmp/dist-*.tar.gz | head -1) | |
| echo "备份当前版本..." | |
| BACKUP_DIR="/opt/1panel/www/sites/reference/backups/$(date +%Y%m%d%H%M%S)" | |
| mkdir -p "$BACKUP_DIR" | |
| cp -r ${{ env.DEPLOY_PATH }} "$BACKUP_DIR" | |
| echo "解压新版本: $LATEST_TAR" | |
| tar -xzf "$LATEST_TAR" -C ${{ env.DEPLOY_PATH }} --strip-components=0 | |
| echo "清理临时文件..." | |
| rm -f "$LATEST_TAR" | |
| chown -R www-data:www-data ${{ env.DEPLOY_PATH }} | |
| chmod -R 755 ${{ env.DEPLOY_PATH }} | |
| echo "✅ 部署完成!" | |
| echo "备份位置: $BACKUP_DIR" |