-
Notifications
You must be signed in to change notification settings - Fork 248
/
main.go
240 lines (230 loc) · 5.32 KB
/
main.go
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// Copyright 2021-present The Atlas Authors. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package main
import (
"bytes"
"embed"
_ "embed"
"flag"
"fmt"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"text/template"
)
type (
// Step defines a step to run.
Step struct {
Name string
Action string
With []string
}
// Credentials is used to pull images from a private registry.
Credentials struct {
Username string
Password string
}
// Job defines an integration job to run.
Job struct {
Version string // version to test (passed to go test as flag which database dialect/version)
Image string // name of service
Credentials *Credentials // credentials to pull the image
Regex string // run regex
Env []string // env of service
Ports []string // port mappings
Volumes []string // volume mappings
Options []string // other options
Steps []Step // extra steps to run
}
)
var (
//go:embed *.tmpl
tplFS embed.FS
tpl = template.Must(template.ParseFS(tplFS, "*.tmpl"))
mysqlOptions = []string{
`--health-cmd "mysqladmin ping -ppass"`,
`--health-interval 10s`,
`--health-start-period 10s`,
`--health-timeout 5s`,
`--health-retries 10`,
}
mysqlEnv = []string{
"MYSQL_DATABASE: test",
"MYSQL_ROOT_PASSWORD: pass",
}
pgOptions = []string{
"--health-cmd pg_isready",
"--health-interval 10s",
"--health-timeout 5s",
"--health-retries 5",
}
pgEnv = []string{
"POSTGRES_DB: test",
"POSTGRES_PASSWORD: pass",
}
jobs = []Job{
{
Version: "mysql56",
Image: "mysql:5.6.35",
Regex: "MySQL",
Env: mysqlEnv,
Ports: []string{"3306:3306"},
Options: mysqlOptions,
},
{
Version: "mysql57",
Image: "mysql:5.7.26",
Regex: "MySQL",
Env: mysqlEnv,
Ports: []string{"3307:3306"},
Options: mysqlOptions,
},
{
Version: "mysql8",
Image: "mysql:8",
Regex: "MySQL",
Env: mysqlEnv,
Ports: []string{"3308:3306"},
Options: mysqlOptions,
},
{
Version: "maria107",
Image: "mariadb:10.7",
Regex: "MySQL",
Env: mysqlEnv,
Ports: []string{"4306:3306"},
Options: mysqlOptions,
},
{
Version: "maria102",
Image: "mariadb:10.2.32",
Regex: "MySQL",
Env: mysqlEnv,
Ports: []string{"4307:3306"},
Options: mysqlOptions,
},
{
Version: "maria103",
Image: "mariadb:10.3.13",
Regex: "MySQL",
Env: mysqlEnv,
Ports: []string{"4308:3306"},
Options: mysqlOptions,
},
{
Version: "postgres-ext-postgis",
Image: "postgis/postgis:latest",
Regex: "Postgres",
Env: pgEnv,
Ports: []string{"5429:5432"},
Options: pgOptions,
},
{
Version: "postgres10",
Image: "postgres:10",
Regex: "Postgres",
Env: pgEnv,
Ports: []string{"5430:5432"},
Options: pgOptions,
},
{
Version: "postgres11",
Image: "postgres:11",
Regex: "Postgres",
Env: pgEnv,
Ports: []string{"5431:5432"},
Options: pgOptions,
},
{
Version: "postgres12",
Image: "postgres:12.3",
Regex: "Postgres",
Env: pgEnv,
Ports: []string{"5432:5432"},
Options: pgOptions,
},
{
Version: "postgres13",
Image: "postgres:13.1",
Regex: "Postgres",
Env: pgEnv,
Ports: []string{"5433:5432"},
Options: pgOptions,
},
{
Version: "postgres14",
Image: "postgres:14",
Regex: "Postgres",
Env: pgEnv,
Ports: []string{"5434:5432"},
Options: pgOptions,
},
{
Version: "postgres15",
Image: "postgres:15",
Regex: "Postgres",
Env: pgEnv,
Ports: []string{"5435:5432"},
Options: pgOptions,
},
{
Version: "sqlite",
Regex: "SQLite.*",
},
}
)
type (
goVersions []string
concurrency struct {
group string
cancel bool
}
)
var data = struct {
Jobs []Job
Flavor, Tags, Runner, Suffix string
GoVersions goVersions
Concurrency concurrency
}{
Concurrency: concurrency{
group: "${{ github.workflow }}-${{ github.head_ref || github.run_id }}",
cancel: true,
},
}
func main() {
flag.StringVar(&data.Flavor, "flavor", "", "")
flag.StringVar(&data.Tags, "tags", "", "")
flag.StringVar(&data.Runner, "runner", "ubuntu-latest", "")
flag.StringVar(&data.Suffix, "suffix", "", "")
flag.Parse()
for _, n := range []string{"dialect", "go", "revisions"} {
var (
buf bytes.Buffer
g = data.Concurrency.group
)
if n == "dialect" {
// Dialect jobs are running after go jobs, putting them in the same concurrency group crates deadlock.
data.Concurrency.group = fmt.Sprintf("%s-dialect", g)
}
if err := tpl.ExecuteTemplate(&buf, fmt.Sprintf("ci_%s.tmpl", n), data); err != nil {
log.Fatalln(err)
}
data.Concurrency.group = g
err := os.WriteFile(filepath.Clean(fmt.Sprintf("../../.github/workflows/ci-%s_%s.yaml", n, data.Suffix)), buf.Bytes(), 0600)
if err != nil {
log.Fatalln(err)
}
}
}
func (v goVersions) String() (s string) {
for i := range v {
v[i] = strconv.Quote(v[i])
}
return fmt.Sprintf("[ %s ]", strings.Join(v, ", "))
}
func (c concurrency) String() (s string) {
return fmt.Sprintf("concurrency:\n group: %s\n cancel-in-progress: %t", c.group, c.cancel)
}