File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Deploy Blog
2+
3+ on :
4+ push :
5+ branches : main
6+
7+ jobs :
8+ deploy :
9+ runs-on : ubuntu-latest
10+ steps :
11+ - name : Checkout code
12+ uses : actions/checkout@v4
13+
14+ - name : Connect server to deploy blog
15+ uses : appleboy/ssh-action@master
16+ with :
17+ host : ${{ secrets.SSH_HOST }}
18+ username : ${{ secrets.SSH_USER }}
19+ key : ${{ secrets.SSH_PRIVATE_KEY }}
20+ # 无缓存时,构建大约需要 10min+,8 次拉取重试约 8min+
21+ command_timeout : 30m
22+ script : |
23+ cd ${{ secrets.BLOG_PATH_REMOTE }}
24+ MAX_RETRIES=8
25+ RETRY_COUNT=0
26+
27+ while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
28+ echo "▶️ Attempt $((RETRY_COUNT+1))/$MAX_RETRIES: Pulling code..."
29+ if git pull origin main; then
30+ echo "✅ Git pull succeeded"
31+ docker stop blog || true
32+ docker rm blog || true
33+ docker rmi nextjs || true
34+ docker build -t nextjs .
35+ docker compose up -d
36+ exit 0
37+ else
38+ echo "❌ Git pull failed (attempt $((RETRY_COUNT+1))/$MAX_RETRIES)"
39+ ((RETRY_COUNT++))
40+ sleep 5
41+ fi
42+ done
43+
44+ echo "🛑 Error: Failed to pull code after $MAX_RETRIES attempts"
45+ exit 1
File renamed without changes.
You can’t perform that action at this time.
0 commit comments