forked from highlight/highlight
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (136 loc) · 6.16 KB
/
backend.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Backend
on:
push:
branches: ['main']
pull_request:
types: [opened, synchronize]
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
code-setup:
runs-on: codebuild-highlight-github-actions-runner-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'backend/go.mod'
cache-dependency-path: 'backend/go.sum'
code-quality-check:
needs: code-setup
runs-on: codebuild-highlight-github-actions-runner-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'backend/go.mod'
cache-dependency-path: 'backend/go.sum'
- name: Format
run: if [ "$(gofmt -l -d ./backend | wc -l)" -gt 0 ]; then gofmt -l -d ./backend && exit 1; fi
- name: Check for GORM Debug
run: if [ "$(grep --exclude-dir migrations -rE 'DB.[\s\n]*Debug\(\)' ./backend | wc -l)" -gt 0 ]; then grep --exclude-dir migrations -rE 'DB.[\s\n]*Debug\(\)' ./backend && exit 1; fi
- name: Check for os.Getenv
run: if [ "$(grep --exclude-dir migrations -rE 'os\.Getenv\(' ./backend | wc -l)" -gt 0 ]; then grep --exclude-dir migrations -rE 'os\.Getenv\(' ./backend && exit 1; fi
- name: Check for os.LookupEnv
run: if [ "$(grep --exclude-dir migrations -rE 'os\.LookupEnv\(' ./backend | wc -l)" -gt 0 ]; then grep --exclude-dir migrations -rE 'os\.LookupEnv\(' ./backend && exit 1; fi
- name: Check for GORM usage without context
run: if [ "$(grep --exclude="*_test.go" --exclude-dir={integrations,jobs,lambda-functions,migrations,model,oauth,retryables,zapier} -rEI '(?i:db)\.(Where|Model|Raw|Create|Update|Preload)' ./backend | grep -v 'WithContext' | wc -l)" -gt 0 ]; then grep --exclude="*_test.go" --exclude-dir={integrations,jobs,lambda-functions,migrations,model,oauth,retryables,zapier} -rEI '(?i:db)\.(Where|Model|Raw|Create|Update|Preload)' ./backend | grep -v 'WithContext' && exit 1; fi
- name: Check for logrus without context
run: if [ "$(grep --exclude-dir migrations --exclude main.go --exclude recovery.go --exclude logging.go -rE '\s+log\.(Debug|Info|Warn|Error|Fatal)' ./backend | grep -v 'WithContext' | grep -v 'Level' | wc -l)" -gt 0 ]; then grep --exclude-dir migrations --exclude main.go --exclude recovery.go --exclude logging.go -rE '\s+log\.(Debug|Info|Warn|Error|Fatal)' ./backend | grep -v 'WithContext' | grep -v 'Level' && exit 1; fi
- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
args: -v --config ./.golangci.yml
working-directory: backend
version: latest
make-check:
needs: [code-setup]
runs-on: codebuild-highlight-github-actions-runner-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'backend/go.mod'
cache-dependency-path: 'backend/go.sum'
- name: copy backend
run: |
mkdir tmp
cp -a backend/. tmp/
- name: Make private graph
run: |
cd backend/
make private-gen
- name: Make public graph
run: |
cd backend/
make public-gen
- name: Diff Check
run: |
diff -r backend/ tmp/
build:
needs: code-quality-check
runs-on: codebuild-highlight-github-actions-runner-${{ github.run_id }}-${{ github.run_attempt }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'backend/go.mod'
cache-dependency-path: 'backend/go.sum'
- name: Build binary
run: cd backend/ && go build .
test:
needs: code-quality-check
runs-on: codebuild-highlight-github-actions-runner-${{ github.run_id }}-${{ github.run_attempt }}
services:
postgres:
image: ankane/pgvector
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
clickhouse:
image: clickhouse/clickhouse-server
ports:
- 9000:9000
redis:
image: redis
ports:
- 6379:6379
env:
CLICKHOUSE_ADDRESS: 'localhost:9000'
CLICKHOUSE_DATABASE: 'default'
CLICKHOUSE_TEST_DATABASE: 'test'
CLICKHOUSE_USERNAME: 'default'
CLICKHOUSE_PASSWORD: ''
PSQL_HOST: 'localhost'
PSQL_DOCKER_HOST: 'postgres'
PSQL_PORT: '5432'
PSQL_USER: 'postgres'
PSQL_DB: 'postgres'
PSQL_PASSWORD: 'postgres'
ENVIRONMENT: 'test'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'backend/go.mod'
cache-dependency-path: 'backend/go.sum'
- name: Run tests
run: cd backend && go test -p 1 ./... -v
- name: Run fuzz tests
run: cd backend && make fuzz