Files
photography/.gitea/workflows/deploy-frontend.yml
xujiang 6a33450923 feat: add Gitea workflow for frontend deployment
- Add automated deployment workflow for frontend directory changes
- Support password authentication with sshpass
- Deploy to /data/photography directory on server
- Configure Caddy server reload after deployment
- Include build, type check, and lint steps
2025-07-08 18:51:25 +08:00

76 lines
2.4 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

name: Deploy Frontend
on:
push:
branches: [ main ]
paths: [ 'frontend/**' ]
pull_request:
branches: [ main ]
paths: [ 'frontend/**' ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Install dependencies
run: |
cd frontend
bun install
- name: Run type check
run: |
cd frontend
bun run type-check
- name: Run lint
run: |
cd frontend
bun run lint
- name: Build project
run: |
cd frontend
bun run build
- name: Deploy to VPS
run: |
# 安装 SSH 客户端、rsync 和 sshpass
sudo apt-get update && sudo apt-get install -y openssh-client rsync sshpass
# 设置 SSH 选项以禁用主机密钥检查(用于密码认证)
export SSHPASS=${{ secrets.ALIYUN_PWD }}
# 测试 SSH 连接
sshpass -e ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "echo 'SSH 连接成功'"
# 在服务器上创建部署目录 (如果不存在)
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "mkdir -p /data/photography"
# 上传构建文件到服务器(使用密码认证)
sshpass -e rsync -avz --delete --progress -e "ssh -o StrictHostKeyChecking=no" frontend/out/ ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }}:/data/photography/
# 设置文件权限
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "chmod -R 755 /data/photography"
# 重新加载 Caddy 配置 (可选,根据你的服务器配置)
sshpass -e ssh -o StrictHostKeyChecking=no ${{ secrets.ALIYUN_USER_NAME }}@${{ secrets.ALIYUN_IP }} "sudo systemctl reload caddy || echo 'Caddy 重启跳过'"
echo "✅ 部署完成访问地址http://${{ secrets.ALIYUN_IP }}"
- name: Notify success
if: success()
run: |
echo "✅ 前端项目部署成功!"
- name: Notify failure
if: failure()
run: |
echo "❌ 前端项目部署失败!"