Skip to content

Commit 2567f82

Browse files
committed
add deploying
1 parent 730627f commit 2567f82

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,25 @@ jobs:
5656
uses: softprops/action-gh-release@v2
5757
with:
5858
files: csdmpro.tar.gz
59+
60+
deploy:
61+
name: Deploy csdmpro
62+
needs: build
63+
runs-on: ubuntu-latest
64+
65+
steps:
66+
- name: Checkout code
67+
uses: actions/checkout@v3
68+
69+
- name: Set up SSH key
70+
run: |
71+
mkdir -p ~/.ssh
72+
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
73+
chmod 600 ~/.ssh/id_ed25519
74+
ssh-keyscan cs.thekhanj.ir >> ~/.ssh/known_hosts
75+
76+
- name: Deploy using custom script
77+
env:
78+
API_TOKEN: ${{ secrets.API_TOKEN }}
79+
TAG: ${{ github.ref_name }}
80+
run: ./ci/deploy

ci/deploy

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env sh
2+
3+
if [ -z "$API_TOKEN" ]; then
4+
echo "API_TOKEN not provided"
5+
exit 1
6+
fi
7+
8+
scp ./csdmpro.tar.gz root@cs.thekhanj.ir:/tmp &&
9+
exit 1
10+
11+
ssh root@cs.thekhanj.ir "bash -s" <<-EOF
12+
cd /tmp
13+
tar xzvf csdmpro.tar.gz || exit 1
14+
cp csdmpro /usr/bin
15+
16+
cat >/etc/systemd/system/csdmpro.service <<-FART
17+
[Unit]
18+
Description=CSDMPRO Telegram Bot Daemon
19+
After=network.target
20+
Wants=network.target
21+
22+
[Service]
23+
Type=simple
24+
Environment="API_TOKEN=$API_TOKEN"
25+
ExecStart=/usr/bin/csdmpro
26+
Restart=always
27+
RestartSec=2s
28+
User=root
29+
Group=root
30+
31+
[Install]
32+
WantedBy=multi-user.target
33+
FART
34+
35+
36+
systemctl daemon-reload &&
37+
systemctl enable csdmpro &&
38+
systemctl restart csdmpro
39+
EOF
40+
41+
if [ "$?" -ne 0 ]; then
42+
echo 'ssh: deployment failed'
43+
exit 1
44+
fi

0 commit comments

Comments
 (0)