-
Notifications
You must be signed in to change notification settings - Fork 0
44 lines (36 loc) · 1.19 KB
/
tgbot.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
name: Build and Deploy
on:
push:
branches:
- master # 仅在推送到主分支时触发
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Initialize Go modules
run: go mod tidy
- name: Build the project
run: go build -o chatbot
- name: Securely copy the binary to the server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
REMOTE_PATH: /root/tgbot/chatbot
run: |
echo "${SSH_PRIVATE_KEY}" > private_key
chmod 600 private_key
scp -i private_key -o StrictHostKeyChecking=no chatbot ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PATH}
- name: Restart the service on the server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
run: |
ssh -i private_key -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} "systemctl restart tgbot"