Files
V2_micropython/.gitea/workflows/deploy.yaml
jeremygan2021 3a4c2788f2
All checks were successful
Deploy WebSocket Server / deploy (push) Successful in 4s
action
2026-03-04 20:39:52 +08:00

61 lines
2.2 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 WebSocket Server
on:
push:
branches:
- master # 或者是 master请根据您的分支名称修改
jobs:
deploy:
runs-on: ubuntu # 或者您的 Gitea runner 标签1
steps:
- name: Check Secrets
env:
HOST: ${{ secrets.SERVER_HOST }}
USERNAME: ${{ secrets.SERVER_USERNAME }}
PASSWORD: ${{ secrets.SERVER_PASSWORD }}
run: |
if [ -z "$HOST" ]; then echo "Error: SERVER_HOST is not set!"; exit 1; fi
if [ -z "$USERNAME" ]; then echo "Error: SERVER_USERNAME is not set!"; exit 1; fi
if [ -z "$PASSWORD" ]; then echo "Error: SERVER_PASSWORD is not set!"; exit 1; fi
echo "Secrets are correctly loaded."
- name: Install SSH Tools
run: |
if command -v apk &> /dev/null; then
apk add --no-cache openssh-client sshpass
elif command -v apt-get &> /dev/null; then
apt-get update -y && apt-get install -y sshpass openssh-client
else
echo "Unknown package manager. Checking if sshpass is already installed..."
fi
if ! command -v sshpass &> /dev/null; then echo "Error: sshpass not found and installation failed."; exit 1; fi
- name: Deploy via SSH
env:
SSHPASS: ${{ secrets.SERVER_PASSWORD }}
run: |
sshpass -e ssh -o StrictHostKeyChecking=no -p 22 ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }} << 'EOF'
set -e
echo "📂 Entering project directory..."
cd /root/V2_micropython/
echo "⬇️ Pulling latest code..."
git pull
echo "📂 Entering websocket_server directory..."
cd websocket_server
echo "🔄 Restarting Docker services..."
if docker compose version &> /dev/null; then
docker compose down
docker compose up -d
docker compose ps
else
docker-compose down
docker-compose up -d
docker-compose ps
fi
echo "✅ Deployment Success!"
EOF