6
6
// for easy modification of some parameters.
7
7
package workflow
8
8
9
+ import " list "
10
+
9
11
on : _ | * [" push " , " pull_request " ]
10
12
name : _ | * " Test "
11
13
jobs : test : {
@@ -14,34 +16,35 @@ jobs: test: {
14
16
platform : _ | * [ " \(p )-latest " for p in Platforms ]
15
17
}
16
18
" runs-on " : " ${{ matrix.platform }} "
17
- steps : [{
19
+ steps : list . FlattenN ( [{
18
20
name : " Install Go "
19
21
uses : " actions/setup-go@v1 "
20
22
with : " go-version " : " ${{ matrix.go-version }} "
21
- }, {
23
+ },
24
+ // {
25
+ // name: "Module cache"
26
+ // uses: "actions/cache@v1"
27
+ // with: {
28
+ // path: "~/go/pkg/mod"
29
+ // key: "${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}"
30
+ // "restore-keys": "${{ runner.os }}-go-"
31
+ // }
32
+ // },
33
+ {
22
34
name : " Checkout code "
23
35
uses : " actions/checkout@v1 "
24
- }, _ | * {
36
+ },
37
+ // Include setup steps for any services that require them,
38
+ [ServiceConfig [name ].SetupStep for name , enabled in Services if enabled && ServiceConfig [name ].SetupStep != null ],
39
+ _ | * {
25
40
name : " Test "
26
41
run : RunTest
27
- }]
42
+ }], 1 )
28
43
}
29
44
30
45
// Include all named services.
31
- for name in Services {
32
- jobs : test : services : " \(name ) " : ServiceConfig [name ]
33
- }
34
-
35
- jobs : test : services : kafka ?: _ | * {
36
- image : " confluentinc/cp-kafka:latest "
37
- env : {
38
- KAFKA_BROKER_ID : " 1 "
39
- KAFKA_ZOOKEEPER_CONNECT : " zookeeper:2181 "
40
- KAFKA_ADVERTISED_LISTENERS : " PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 "
41
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP : " PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT "
42
- KAFKA_INTER_BROKER_LISTENER_NAME : " PLAINTEXT "
43
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR : " 1 "
44
- }
46
+ for name , enabled in Services if enabled {
47
+ jobs : test : services : " \(name ) " : ServiceConfig [name ].Service
45
48
}
46
49
47
50
// Platforms configures what platforms to run the tests on.
@@ -57,33 +60,76 @@ RunTest :: *"go test ./..." | string
57
60
// Service configures which services to make available.
58
61
// The configuration the service with name N is taken from
59
62
// ServiceConfig[N]
60
- Services :: [... string ]
63
+ Services :: [_ ]: bool
61
64
62
65
// ServiceConfig holds the default configuration for services that
63
66
// can be started by naming them in Services.
64
- ServiceConfig :: [_ ]: _
67
+ ServiceConfig :: [_ ]: {
68
+ // Service holds the contents of `jobs: test: services: "\(serviceName)"`
69
+ " Service " : Service
70
+
71
+ // SetupStep optionally holds a step to run to set up the service
72
+ // before the main workflow action is run (for example to wait
73
+ // for the service to become ready).
74
+ SetupStep : JobStep | * null
75
+ }
76
+
77
+ // Kafka requires zookeeper too.
78
+ if Services [" kafka " ] != _|_ {
79
+ Services :: zookeeper : true
80
+ }
65
81
66
82
ServiceConfig :: kafka : {
67
- image : " confluentinc/cp-kafka:latest "
68
- env : {
69
- KAFKA_BROKER_ID : " 1 "
70
- KAFKA_ZOOKEEPER_CONNECT : " zookeeper:2181 "
71
- KAFKA_ADVERTISED_LISTENERS : " PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 "
72
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP : " PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT "
73
- KAFKA_INTER_BROKER_LISTENER_NAME : " PLAINTEXT "
74
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR : " 1 "
83
+ Service : {
84
+ image : " confluentinc/cp-kafka:latest "
85
+ ports : [" 9092:9092 " ]
86
+ env : {
87
+ KAFKA_BROKER_ID : " 1 "
88
+ KAFKA_ZOOKEEPER_CONNECT : " zookeeper:2181 "
89
+ KAFKA_ADVERTISED_LISTENERS : " PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092 "
90
+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP : " PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT "
91
+ KAFKA_INTER_BROKER_LISTENER_NAME : " PLAINTEXT "
92
+ KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR : " 1 "
93
+ }
94
+ }
95
+ SetupStep : {
96
+ name : " Wait for Kafka "
97
+ " timeout-minutes " : 1
98
+ shell : " bash "
99
+ run : #"""
100
+ netstat -a || true
101
+ waitfor() {
102
+ while ! nc -v -z $1 $2
103
+ do sleep 1
104
+ done
105
+ }
106
+ waitfor localhost 9092
107
+ waitfor localhost 2181
108
+
109
+ """#
110
+ }
111
+ }
112
+
113
+ ServiceConfig :: zookeeper : {
114
+ Service : {
115
+ image : " confluentinc/cp-zookeeper:latest "
116
+ ports : [" 2181:2181 " ]
117
+ env : {
118
+ ZOOKEEPER_CLIENT_PORT : " 2181 "
119
+ ZOOKEEPER_TICK_TIME : " 2000 "
120
+ }
75
121
}
76
122
}
77
123
78
- ServiceConfig :: postgres : {
79
- env : {
80
- POSTGRES_DB : " postgres "
81
- POSTGRES_PASSWORD : " postgres "
82
- POSTGRES_USER : " postgres "
124
+ ServiceConfig :: postgres : _ | * {
125
+ Service : {
126
+ image : " postgres:10.8 "
127
+ ports : [" 5432:5432 " ]
128
+ env : {
129
+ POSTGRES_DB : " postgres "
130
+ POSTGRES_PASSWORD : " postgres "
131
+ POSTGRES_USER : " postgres "
132
+ }
133
+ options : " --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 "
83
134
}
84
- image : " postgres:10.8 "
85
- options : " --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 "
86
- ports : [
87
- " 5432:5432 " ,
88
- ]
89
135
}
0 commit comments