-
Notifications
You must be signed in to change notification settings - Fork 11
/
.drone.yml
193 lines (179 loc) · 4.82 KB
/
.drone.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
kind: pipeline
type: docker
name: default
trigger:
event:
- push
- tag
services:
- name: vault
image: vault:1.5.3
ports:
- 8200
environment:
VAULT_DEV_ROOT_TOKEN_ID: "root-token"
- name: mysql
image: mysql:8
ports:
- 3306
environment:
MYSQL_DATABASE: "kaigara_opendax_uat"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
- name: postgres
image: postgres:13.3-alpine
ports:
- 5432
command:
- postgres
- -c
- wal_level=logical
- -N 500
environment:
POSTGRES_DB: kaigara_opendax_uat
POSTGRES_USER: postgres
POSTGRES_PASSWORD: changeme
steps:
- name: Wait for services
image: jwilder/dockerize
pull: if-not-exists
commands:
- dockerize -wait tcp://postgres:5432 -wait tcp://mysql:3306 -wait tcp://vault:8200 -timeout 2m
- name: Enable Vault Transit
image: vault:1.5.3
environment:
VAULT_ADDR: "http://vault:8200"
VAULT_TOKEN: "root-token"
commands:
- vault secrets enable transit
- name: Restore lint cache
pull: if-not-exists
image: drillster/drone-volume-cache
volumes:
- name: golint-cache
path: /golint-cache
settings:
restore: true
mount:
- .cache/golangci-lint
when:
branch:
exclude:
- "master"
- "*stable"
- name: Go lint
image: golangci/golangci-lint:v1.49-alpine
environment:
GOLANGCI_LINT_CACHE: "/drone/src/.cache/golangci-lint"
commands:
- golangci-lint cache status
- golangci-lint run --timeout 3m0s
when:
branch:
exclude:
- "master"
- "*stable"
- name: Rebuild lint cache
pull: if-not-exists
image: drillster/drone-volume-cache
volumes:
- name: golint-cache
path: /golint-cache
settings:
rebuild: true
mount:
- .cache/golangci-lint
when:
branch:
exclude:
- "master"
- "*stable"
- name: Go test
image: golang:1.18
environment:
GO111MODULE: "on"
COVER_OUT: cover.out
KAIGARA_VAULT_ADDR: "http://vault:8200"
KAIGARA_VAULT_TOKEN: "root-token"
KAIGARA_DATABASE_HOST: "postgres"
commands:
- |
counter=0
for gpath in $(find $PWD -name go.mod); do cd $(dirname $gpath);
for dir in $(go list ./...); do
tmpcover=cover$counter
go clean -testcache
go test $dir --cover -coverprofile $tmpcover
cat $tmpcover >> $COVER_OUT
counter=$(( counter + 1 ))
done
done
- name: Bump and tag
image: golang:1.18
environment:
GITHUB_API_KEY:
from_secret: github_api_key
GITHUB_API_USER:
from_secret: github_api_user
commands:
- go install github.com/guilhem/bump@v0.2.1
- git remote add authenticated-origin https://$GITHUB_API_USER:$GITHUB_API_KEY@github.com/$DRONE_REPO
- git fetch --tags authenticated-origin
- bump patch --allow-dirty
- git push authenticated-origin --tags
when:
event:
- push
branch:
- master
- name: Go Coverage master
image: golang:1.18
environment: &envs
GO111MODULE: "on"
COVER_OUT: cover.out
ANALYTICS_DATABASE_HOST: pg.opendax.app
ANALYTICS_DATABASE_PORT: 30432
ANALYTICS_DATABASE_USERNAME: postgres
ANALYTICS_DATABASE_USERNAME: coverage_analytics
ANALYTICS_DATABASE_PASSWORD:
from_secret: pgpass_coverage
ANALYTICS_DATABASE_NAME: coverage_analytics
ANALYTICS_COMPONENT: kaigara
commands: &cmds
- apt-get update
- apt-get install -y p7zip-full
- |
curl -s -L "https://github.com/boumenot/gocover-cobertura/releases/download/v1.1.0/gocover-cobertura.linux.x64.7z" -o ./gocover-cobertura.7z
curl -s -L https://github.com/openware/go-coverage/releases/download/v1.0.0-alpha/go-coverage -o ./go-coverage
7z x ./gocover-cobertura.7z
chmod +x ./gocover-cobertura
chmod +x ./go-coverage
- ./gocover-cobertura < $COVER_OUT > coverage.xml
- ./go-coverage coverage.xml
when:
event:
- push
branch:
- master
- name: Go coverage tag
image: golang:1.18
environment:
<<: *envs
commands: *cmds
when:
event:
- tag
- name: Build and publish
image: golang:1.18
environment:
GO111MODULE: on
GITHUB_API_KEY:
from_secret: github_api_key
commands:
- echo $DRONE_TAG | grep -v / || exit 78 # Skip if submodule is tagged
- go mod download
- KAIGARA_VERSION=${DRONE_TAG} make build
- go install github.com/tcnksm/ghr@v0.15.0
- ghr -t $GITHUB_API_KEY -u ${DRONE_REPO_NAMESPACE} -r ${DRONE_REPO_NAME} -c ${DRONE_COMMIT} -delete ${DRONE_TAG} ./bin
when:
event:
- tag