File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -13,13 +13,14 @@ jobs:
1313 - name : Checkout code
1414 uses : actions/checkout@v4
1515
16- - name : Run Script on Remote Server
16+ - name : ssh connect server
1717 uses : appleboy/ssh-action@master
1818 with :
1919 host : ${{ secrets.SSH_HOST }} # ip address
2020 username : ${{ secrets.SSH_USER }} # server username
2121 key : ${{ secrets.SSH_PRIVATE_KEY }} # server ssh private key
2222 script : |
23+ BLOG_PATH_REMOTE=${{ secrets.BLOG_PATH_REMOTE }}
2324 cd $BLOG_PATH_REMOTE
2425
2526 MAX_RETRIES=8
4142 exit 1 # throw error
4243 fi
4344 EOF
45+
46+ - name : Run Script to Push serve
47+ env :
48+ SSH_PRIVATE_KEY : ${{ secrets.SSH_PRIVATE_KEY }}
49+ SSH_HOST : ${{ secrets.SSH_HOST }}
50+ SSH_USER : ${{ secrets.SSH_USER }}
51+ BLOG_PATH_REMOTE : ${{ secrets.BLOG_PATH_REMOTE }}
52+ run : |
53+ ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
54+ ssh $SSH_USER@$SSH_HOST << EOF
55+ cd $BLOG_PATH_REMOTE
56+
57+ MAX_RETRIES=8
58+ RETRY_COUNT=0
59+
60+ while [ \$RETRY_COUNT -lt \$MAX_RETRIES ]; do
61+ if git pull origin main; then
62+ break # pull succesful exit
63+ else
64+ echo "Git pull failed, retrying (\$((RETRY_COUNT + 1)) of \$MAX_RETRIES)..."
65+ ((RETRY_COUNT++))
66+ sleep 5
67+ fi
68+ done
69+
70+ # check if retry count exceeded
71+ if [ \$RETRY_COUNT -eq \$MAX_RETRIES ]; then
72+ echo "Failed to pull code after \$MAX_RETRIES attempts. Exiting."
73+ exit 1 # throw error
74+ fi
75+ EOF
You can’t perform that action at this time.
0 commit comments