Skip to content

Commit ca3bbb9

Browse files
committed
chore: add github action workflow
1 parent e5d0fe3 commit ca3bbb9

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Push to Server
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: ssh connect server
17+
uses: appleboy/ssh-action@master
18+
with:
19+
host: ${{ secrets.SSH_HOST }} # ip address
20+
username: ${{ secrets.SSH_USER }} # server username
21+
key: ${{ secrets.SSH_PRIVATE_KEY }} # server ssh private key
22+
23+
- name: Run Script to Push serve
24+
env:
25+
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
26+
SSH_HOST: ${{ secrets.SSH_HOST }}
27+
SSH_USER: ${{ secrets.SSH_USER }}
28+
BLOG_PATH_REMOTE: ${{ secrets.BLOG_PATH_REMOTE }}
29+
APP_NAME: docsify-blog
30+
run: |
31+
mkdir -p ~/.ssh
32+
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
33+
chmod 600 ~/.ssh/id_rsa
34+
ssh-keyscan $SSH_HOST >> ~/.ssh/known_hosts
35+
ssh $SSH_USER@$SSH_HOST << EOF
36+
cd $BLOG_PATH_REMOTE
37+
38+
MAX_RETRIES=8
39+
RETRY_COUNT=0
40+
41+
while [ \$RETRY_COUNT -lt \$MAX_RETRIES ]; do
42+
if git pull origin doc; then
43+
break # pull succesful exit
44+
else
45+
echo "Git pull failed, retrying (\$((RETRY_COUNT + 1)) of \$MAX_RETRIES)..."
46+
((RETRY_COUNT++))
47+
sleep 5
48+
fi
49+
done
50+
51+
# check if retry count exceeded
52+
if [ \$RETRY_COUNT -eq \$MAX_RETRIES ]; then
53+
echo "Failed to pull code after \$MAX_RETRIES attempts. Exiting."
54+
exit 1 # throw error
55+
fi
56+
EOF

0 commit comments

Comments
 (0)