-
Notifications
You must be signed in to change notification settings - Fork 8
199 lines (175 loc) · 6.46 KB
/
tests.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# yamllint disable rule:line-length
---
name: Tests
# yamllint disable-line rule:truthy
on:
workflow_dispatch:
pull_request:
types: [opened]
push:
jobs:
Unit-Tests:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.22.3
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Test & Coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
go test -coverprofile c.out -coverpkg ./... ./...
./cc-test-reporter format-coverage -o codeclimate.json --prefix $(go list -m)
- name: Upload Coverage Result Artifact
uses: actions/upload-artifact@v4
with:
name: codeclimate-unit
path: codeclimate.json
retention-days: 1
- uses: actions/setup-python@v2
- name: Run pre commit linting
uses: pre-commit/[email protected]
PostgreSQL-Integration-Tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_DB: safetyculture_exporter_db
POSTGRES_USER: safetyculture_exporter
POSTGRES_PASSWORD: safetyculture_exporter
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.22.3
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Test & Coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
TEST_DB_DIALECT: postgres
TEST_DB_CONN_STRING: "postgresql://safetyculture_exporter:safetyculture_exporter@localhost:5432/safetyculture_exporter_db"
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
go test -coverprofile c.out -coverpkg ./... ./... -tags=sql
./cc-test-reporter format-coverage -o codeclimate.json --prefix $(go list -m)
- name: Upload Coverage Result Artifact
uses: actions/upload-artifact@v4
with:
name: codeclimate-intg-postgres
path: codeclimate.json
retention-days: 1
MySQL-8-Integration-Tests:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: safetyculture_exporter
MYSQL_DATABASE: safetyculture_exporter_db
MYSQL_USER: safetyculture_exporter
MYSQL_PASSWORD: safetyculture_exporter
options: >-
--health-cmd "mysqladmin ping -h localhost"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.22.3
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Test & Coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
TEST_DB_DIALECT: mysql
TEST_DB_CONN_STRING: "root:safetyculture_exporter@tcp(localhost:3306)/safetyculture_exporter_db?charset=utf8mb4&parseTime=True&loc=Local"
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
go test -coverprofile c.out -coverpkg ./... ./... -tags=sql
./cc-test-reporter format-coverage -o codeclimate.json --prefix $(go list -m)
- name: Upload Coverage Result Artifact
uses: actions/upload-artifact@v4
with:
name: codeclimate-mysql-8
path: codeclimate.json
retention-days: 1
SQL-Server-Integration-Tests:
runs-on: ubuntu-latest
services:
sqlserver:
image: mcr.microsoft.com/mssql/server
env:
SA_PASSWORD: "SafetyCultureExporter12345"
ACCEPT_EULA: "Y"
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P SafetyCultureExporter12345 -Q \"SELECT 1\" || exit 1"
--health-interval 10s
--health-timeout 10s
--health-retries 20
ports:
- 1433:1433
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.22.3
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Test & Coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
TEST_DB_DIALECT: sqlserver
TEST_DB_CONN_STRING: "sqlserver://sa:SafetyCultureExporter12345@localhost:1433?database=master"
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
go test -coverprofile c.out -coverpkg ./... ./... -tags=sql
./cc-test-reporter format-coverage -o codeclimate.json --prefix $(go list -m)
- name: Upload Coverage Result Artifact
uses: actions/upload-artifact@v4
with:
name: codeclimate-intg-sql-server
path: codeclimate.json
retention-days: 1
Upload-Coverage:
runs-on: ubuntu-latest
needs:
- Unit-Tests
- PostgreSQL-Integration-Tests
- MySQL-8-Integration-Tests
- SQL-Server-Integration-Tests
steps:
- name: Download all coverage results
uses: actions/download-artifact@v4
- name: Upload Coverage to Code Climate
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter sum-coverage */codeclimate.json -p 4 -o codeclimate.total.json
./cc-test-reporter upload-coverage -i codeclimate.total.json