-
Notifications
You must be signed in to change notification settings - Fork 1
53 lines (44 loc) · 1.29 KB
/
production-workflow.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
name: "Production Build"
on:
push:
branches: [ "main" ]
pull_request:
types: [opened, synchronize, reopened]
branches: [ "main" ]
workflow_dispatch:
jobs:
Build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Install dependencies
run: go get -v ./...
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
Deploy:
name: Deploy to server
runs-on: ubuntu-latest
needs: [Build]
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
steps:
- name: Deploy to server
env:
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOST_NAME: ${{ secrets.HOST_NAME }}
USER_NAME: ${{ secrets.USER_NAME }}
APP_DIR: ${{ secrets.APP_DIR }}
SERVICE_NAME: ${{ secrets.SERVICE_NAME }}
run:
echo "$PRIVATE_KEY" > private_key &&
chmod 400 private_key &&
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOST_NAME} "
cd ${APP_DIR} &&
sudo systemctl stop ${SERVICE_NAME} &&
git pull &&
sudo systemctl start ${SERVICE_NAME} "