-
Notifications
You must be signed in to change notification settings - Fork 7
126 lines (113 loc) · 3.87 KB
/
build.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Build and deploy
on:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout submodules
run: git submodule update --init --force --recursive --remote
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
override: true
toolchain: stable
- name: Install Protoc
uses: arduino/setup-protoc@v1
# Restore cache
- name: Restore cargo packages
uses: actions/cache@v3
env:
cache-name: cache-cargo-registry
with:
path: "~/.cargo/"
key: ${{ runner.os }}-build-${{ env.cache-name }}
restore-keys: ${{ runner.os }}-build-${{ env.cache-name }}
- name: Restore build product
uses: actions/cache@v3
env:
cache-name: cache-build-product
with:
path: "./target/"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./Cargo.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-
# Build
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --all-features
push:
needs: build
runs-on: ubuntu-latest
if: |
github.ref == 'refs/heads/master' &&
github.repository == 'SIT-kite/kite-server'
steps:
- name: Restore build product
uses: actions/cache@v3
env:
cache-name: cache-build-product
with:
path: "./target/"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./Cargo.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-
- name: Strip binary file
run: |
strip -s target/release/loader
ls target/release -lh | grep 'loader$' | awk '{print "Binary size is", $5, "after strip" }'
cp target/release/loader kite-server-v3
- name: Copy file via SSH
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SERVER_HOST }}
port: ${{ secrets.SERVER_PORT }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_SECRET }}
source: kite-server-v3
target: ${{ secrets.DEPLOY_PATH }}/kite-server-v3.tmp
- name: Deploy & Restart via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
port: ${{ secrets.SERVER_PORT }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_SECRET }}
# User home is the deployment path.
script: |
cp ./kite-server-v3 ./kite-server-v3.bak
systemctl --user stop kite3.service
mv ./kite-server-v3.tmp/kite-server-v3 kite-server-v3
systemctl --user start kite3.service
rm -rf ./kite-server-v3.tmp
notification:
runs-on: ubuntu-latest
needs: [ push ]
if: |
github.event_name != 'pull_request' &&
github.repository == 'SIT-kite/kite-server' &&
always()
steps:
- uses: technote-space/workflow-conclusion-action@v2
- uses: nelonoel/branch-name@v1.0.1
- uses: benjlevesque/short-sha@v2.1
id: short-sha
with: { length: 7 }
- name: 🤖 Build Result Notification
uses: appleboy/telegram-action@v0.1.1
with:
to: ${{ secrets.CHANNEL_CHAT_ID }}
token: ${{ secrets.BOT_TOKEN }}
format: markdown
message: |
The result to 🎉the deployment of kite-server (*${{ env.BRANCH_NAME }}*): *${{ env.WORKFLOW_CONCLUSION }}*
By *${{ github.actor }}*. Commit message:
*${{ github.event.head_commit.message }}*