-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (86 loc) · 2.85 KB
/
Copy pathci.yml
File metadata and controls
101 lines (86 loc) · 2.85 KB
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
name: ci
on:
push:
branches: [main, staging]
pull_request:
branches: [main, staging]
jobs:
ci:
# On pull_request events, skip if the head branch is staging or main —
# those branches already run CI via the push trigger, so this would be a duplicate.
if: |
github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
github.head_ref != 'staging' &&
github.head_ref != 'main')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: vet
run: go vet ./...
- name: install golangci-lint
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
- name: golangci-lint
run: golangci-lint run ./...
- name: govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: build
run: go build ./cmd/api
- name: test
run: go test ./...
deploy-staging:
needs: ci
if: github.ref == 'refs/heads/staging' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Copy source to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
source: "."
target: /opt/numex/api-src-staging
rm: false
- name: Rebuild and restart staging container
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
docker compose -f /opt/numex/deploy/docker-compose.yml build numex-api-staging
docker compose -f /opt/numex/deploy/docker-compose.yml up -d numex-api-staging
docker image prune -f
deploy-prod:
needs: ci
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Copy source to server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
source: "."
target: /opt/numex/api-src-prod
rm: false
- name: Rebuild and restart prod container
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
docker compose -f /opt/numex/deploy/docker-compose.yml build numex-api-prod
docker compose -f /opt/numex/deploy/docker-compose.yml up -d numex-api-prod
docker image prune -f