Skip to content

Commit 9876b78

Browse files
committed
[ci] Favor direct mage invocation on CI (elastic#19960)
This changes Jenkins and Travis to directly invoke mage where possible instead of going through make. Some of the remaining make don't yet have a mage equivalant (mainly crosscompile). For Packetbeat this add Jenkins stages to test on darwin and Windows. There were a few fixes I had to make related to these changes: - Add some mage target dependencies to ensure fields and dashboards are ready when tests use them. - Swap the order of the Go imports for dev-tools/mage/targets/integtest and unittest so that unit tests run before integ tests when running the 'mage test' target. - chown the shared Python venv that is in the root of the repo after Dockerized integ tests exit to ensure there are no permissions issues caused by root owned files. - I found a few Python string encoding issues that caused tests failures. I thought we fixed these during the Python 3 conversion, but something here exposed a few that we didn't address. One thing of note that I did not correct. Journalbeat has system tests but they are not executed. The existing/old Makefile has SYSTEM_TESTS=false so they are not executed. So when I switched it to mage I left it as 'mage goUnitTest' to avoid the Python when failed when I tried it. (cherry picked from commit 4a1f800)
1 parent 87f596b commit 9876b78

File tree

14 files changed

+248
-72
lines changed

14 files changed

+248
-72
lines changed

.ci/scripts/travis_has_changes.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -exuo pipefail
3+
4+
# Changes on these files will trigger all builds.
5+
COMMON_DIRLIST="dev-tools .travis.yml testing .ci"
6+
7+
# Commit range to check for. For example master...<PR branch>
8+
RANGE=$TRAVIS_COMMIT_RANGE
9+
DIRLIST="$@ $COMMON_DIRLIST"
10+
11+
# Find modified files in range and filter out docs only changes.
12+
CHANGED_FILES=$(git diff --name-only $RANGE | grep -v '.asciidoc')
13+
14+
beginswith() { case $2 in "$1"*) true;; *) false;; esac }
15+
16+
for path in $DIRLIST; do
17+
for changed in $CHANGED_FILES; do
18+
if beginswith $path $changed; then
19+
exit 0 # found a match -> continue testing
20+
fi
21+
done
22+
done
23+
24+
echo "NOT testing required. Modified files: $CHANGED_FILES"
25+
exit 1

.travis.yml

+136-33
Original file line numberDiff line numberDiff line change
@@ -37,193 +37,287 @@ jobs:
3737

3838
# Filebeat
3939
- os: linux
40-
env: TARGETS="-C filebeat testsuite"
40+
before_install: .ci/scripts/travis_has_changes.sh filebeat libbeat || travis_terminate 0
41+
env:
42+
- PROJECT=filebeat
43+
- MAGE='build test'
4144
go: $TRAVIS_GO_VERSION
4245
stage: test
4346
- os: osx
44-
env: TARGETS="TEST_ENVIRONMENT=0 -C filebeat testsuite"
47+
before_install: .ci/scripts/travis_has_changes.sh filebeat libbeat || travis_terminate 0
48+
env:
49+
- PROJECT=filebeat
50+
- MAGE='build unitTest'
4551
go: $TRAVIS_GO_VERSION
4652
stage: test
4753
- os: linux
48-
env: TARGETS="-C x-pack/filebeat testsuite"
54+
before_install: .ci/scripts/travis_has_changes.sh x-pack/filebeat filebeat libbeat || travis_terminate 0
55+
env:
56+
- PROJECT=x-pack/filebeat
57+
- MAGE='build test'
4958
go: $(GO_VERSION)
5059
stage: test
5160

5261
# Heartbeat
5362
- os: linux
54-
env: TARGETS="-C heartbeat testsuite"
63+
before_install: .ci/scripts/travis_has_changes.sh heartbeat libbeat || travis_terminate 0
64+
env:
65+
- PROJECT=heartbeat
66+
- MAGE='build test'
5567
go: $TRAVIS_GO_VERSION
5668
stage: test
5769
- os: osx
58-
env: TARGETS="TEST_ENVIRONMENT=0 -C heartbeat testsuite"
70+
before_install: .ci/scripts/travis_has_changes.sh heartbeat libbeat || travis_terminate 0
71+
env:
72+
- PROJECT=heartbeat
73+
- MAGE='build unitTest'
5974
go: $TRAVIS_GO_VERSION
6075
stage: test
6176

6277
# Auditbeat
6378
- os: linux
64-
env: TARGETS="-C auditbeat testsuite"
79+
before_install: .ci/scripts/travis_has_changes.sh auditbeat libbeat || travis_terminate 0
80+
env:
81+
- PROJECT=auditbeat
82+
- MAGE='build test'
6583
go: $TRAVIS_GO_VERSION
6684
stage: test
6785
- os: osx
68-
env: TARGETS="TEST_ENVIRONMENT=0 -C auditbeat testsuite"
86+
before_install: .ci/scripts/travis_has_changes.sh auditbeat libbeat || travis_terminate 0
87+
env:
88+
- PROJECT=auditbeat
89+
- MAGE='build unitTest'
6990
go: $TRAVIS_GO_VERSION
7091
stage: test
7192
- os: linux
93+
before_install: .ci/scripts/travis_has_changes.sh auditbeat libbeat || travis_terminate 0
7294
env: TARGETS="-C auditbeat crosscompile"
7395
go: $TRAVIS_GO_VERSION
7496
stage: test
7597
- os: linux
76-
env: TARGETS="-C x-pack/auditbeat testsuite"
98+
before_install: .ci/scripts/travis_has_changes.sh x-pack/auditbeat auditbeat libbeat || travis_terminate 0
99+
env:
100+
- PROJECT=x-pack/auditbeat
101+
- MAGE='build test'
102+
go: $TRAVIS_GO_VERSION
103+
stage: test
104+
- os: osx
105+
before_install: .ci/scripts/travis_has_changes.sh x-pack/auditbeat auditbeat libbeat || travis_terminate 0
106+
env:
107+
- PROJECT=x-pack/auditbeat
108+
- MAGE='build unitTest'
77109
go: $TRAVIS_GO_VERSION
78110
stage: test
79111

80112
# Libbeat
81113
- os: linux
82-
env: TARGETS="-C libbeat testsuite"
114+
before_install: .ci/scripts/travis_has_changes.sh libbeat || travis_terminate 0
115+
env:
116+
- PROJECT=libbeat
117+
- MAGE='build test'
118+
# The libbeat tests are so verbose that they exceed the maximum allowed log length of Travis CI.
119+
- MAGEFILE_VERBOSE=false
83120
go: $TRAVIS_GO_VERSION
84121
stage: test
85122
- os: linux
123+
before_install: .ci/scripts/travis_has_changes.sh libbeat || travis_terminate 0
86124
env: TARGETS="-C libbeat crosscompile"
87125
go: $TRAVIS_GO_VERSION
88126
stage: test
89127
- os: linux
128+
before_install: .ci/scripts/travis_has_changes.sh libbeat || travis_terminate 0
90129
env: STRESS_TEST_OPTIONS="-timeout=20m -race -v -parallel 1" TARGETS="-C libbeat stress-tests"
91130
go: $TRAVIS_GO_VERSION
92131
stage: test
93132
- os: linux
94-
env: TARGETS="-C x-pack/libbeat testsuite"
133+
before_install: .ci/scripts/travis_has_changes.sh x-pack/libbeat libbeat || travis_terminate 0
134+
env:
135+
- PROJECT=x-pack/libbeat
136+
- MAGE='build test'
95137
go: $TRAVIS_GO_VERSION
96138
stage: test
97139

98140
# Metricbeat
99141
- os: linux
100-
env: TARGETS="-C metricbeat unit-tests"
142+
before_install: .ci/scripts/travis_has_changes.sh metricbeat libbeat || travis_terminate 0
143+
env:
144+
- PROJECT=metricbeat
145+
- MAGE='build unitTest'
101146
go: $TRAVIS_GO_VERSION
102147
stage: test
103148
- os: linux
104149
before_install: .ci/scripts/travis_has_changes.sh metricbeat libbeat || travis_terminate 0
105-
install:
150+
install:
106151
- .ci/scripts/install-kind.sh
107152
- .ci/scripts/install-kubectl.sh
108153
env:
109-
- TARGETS="-C metricbeat integration-tests"
110154
- K8S_VERSION=v1.17.2
111155
- KIND_VERSION=v0.7.0
156+
- PROJECT=metricbeat
157+
- MAGE='goIntegTest'
112158
go: $TRAVIS_GO_VERSION
113159
stage: test
114160
- os: linux
115-
env: TARGETS="-C metricbeat system-tests"
161+
before_install: .ci/scripts/travis_has_changes.sh metricbeat libbeat || travis_terminate 0
162+
env:
163+
- PROJECT=metricbeat
164+
- MAGE='pythonIntegTest'
116165
go: $TRAVIS_GO_VERSION
117166
stage: test
118167
- os: osx
119-
env: TARGETS="-C metricbeat testsuite"
168+
before_install: .ci/scripts/travis_has_changes.sh metricbeat libbeat || travis_terminate 0
169+
env:
170+
- PROJECT=metricbeat
171+
- MAGE='build unitTest'
120172
go: $TRAVIS_GO_VERSION
121173
stage: test
122174
- os: linux
175+
before_install: .ci/scripts/travis_has_changes.sh metricbeat libbeat || travis_terminate 0
123176
env: TARGETS="-C metricbeat crosscompile"
124177
go: $TRAVIS_GO_VERSION
125178
stage: test
126179
- os: linux
127-
env: TARGETS="-C x-pack/metricbeat unit-tests"
180+
before_install: .ci/scripts/travis_has_changes.sh x-pack/metricbeat metricbeat libbeat || travis_terminate 0
181+
env:
182+
- PROJECT=x-pack/metricbeat
183+
- MAGE='build unitTest'
128184
go: $TRAVIS_GO_VERSION
129185
stage: test
130186
- os: linux
131-
env: TARGETS="-C x-pack/metricbeat integration-tests"
187+
before_install: .ci/scripts/travis_has_changes.sh x-pack/metricbeat metricbeat libbeat || travis_terminate 0
188+
env:
189+
- PROJECT=x-pack/metricbeat
190+
- MAGE='goIntegTest'
132191
go: $TRAVIS_GO_VERSION
133192
stage: test
134193
- os: linux
135-
env: TARGETS="-C x-pack/metricbeat system-tests"
194+
before_install: .ci/scripts/travis_has_changes.sh x-pack/metricbeat metricbeat libbeat || travis_terminate 0
195+
env:
196+
- PROJECT=x-pack/metricbeat
197+
- MAGE='pythonIntegTest'
136198
go: $TRAVIS_GO_VERSION
137199
stage: test
138200
- os: osx
139-
env: TARGETS="-C x-pack/metricbeat testsuite"
201+
before_install: .ci/scripts/travis_has_changes.sh metricbeat libbeat || travis_terminate 0
202+
env:
203+
- PROJECT=x-pack/metricbeat
204+
- MAGE='build unitTest'
140205
go: $TRAVIS_GO_VERSION
141206
stage: test
142207

143208
# Packetbeat
144209
- os: linux
145-
env: TARGETS="-C packetbeat testsuite"
210+
before_install: .ci/scripts/travis_has_changes.sh packetbeat libbeat || travis_terminate 0
211+
env:
212+
- PROJECT=packetbeat
213+
- MAGE='build test'
146214
go: $TRAVIS_GO_VERSION
147215
stage: test
148216

149217
# Winlogbeat
150218
- os: linux
219+
before_install: .ci/scripts/travis_has_changes.sh winlogbeat libbeat || travis_terminate 0
151220
env: TARGETS="-C winlogbeat crosscompile"
152221
go: $TRAVIS_GO_VERSION
153222
stage: test
154223

155224
# Functionbeat
156225
- os: linux
157-
env: TARGETS="-C x-pack/functionbeat testsuite"
226+
before_install: .ci/scripts/travis_has_changes.sh x-pack/functionbeat libbeat || travis_terminate 0
227+
env:
228+
- PROJECT=x-pack/functionbeat
229+
- MAGE='build test'
158230
go: $TRAVIS_GO_VERSION
159231
stage: test
160232
- os: osx
161-
env: TARGETS="TEST_ENVIRONMENT=0 -C x-pack/functionbeat testsuite"
233+
before_install: .ci/scripts/travis_has_changes.sh x-pack/functionbeat libbeat || travis_terminate 0
234+
env:
235+
- PROJECT=x-pack/functionbeat
236+
- MAGE='build unitTest'
162237
go: $TRAVIS_GO_VERSION
163238
stage: test
164239
- os: linux
165240
before_install: .ci/scripts/travis_has_changes.sh x-pack/functionbeat libbeat || travis_terminate 0
166-
env: TARGETS="-C x-pack/functionbeat test-gcp-functions"
241+
env:
242+
- PROJECT=x-pack/functionbeat
243+
- MAGE='testGCPFunctions'
167244
go: 1.13.1
168245
stage: test
169246

170247
# Docker Log Driver
171248
- os: linux
172-
env: TARGETS="-C x-pack/dockerlogbeat testsuite"
249+
before_install: .ci/scripts/travis_has_changes.sh x-pack/dockerlogbeat libbeat || travis_terminate 0
250+
env:
251+
- PROJECT=x-pack/dockerlogbeat
252+
- MAGE='build test'
173253
go: $TRAVIS_GO_VERSION
174254
stage: test
175255

176256
# Journalbeat
177257
- os: linux
178-
env: TARGETS="-C journalbeat testsuite"
258+
before_install: .ci/scripts/travis_has_changes.sh journalbeat libbeat || travis_terminate 0
259+
env:
260+
- PROJECT=journalbeat
261+
- MAGE='build goUnitTest'
179262
go: $TRAVIS_GO_VERSION
180263
stage: test
181264

182265
# Agent
183266
- os: linux
184267
before_install: .ci/scripts/travis_has_changes.sh x-pack/elastic-agent libbeat || travis_terminate 0
185-
env: TARGETS="-C x-pack/elastic-agent testsuite"
268+
env:
269+
- PROJECT=x-pack/elastic-agent
270+
- MAGE='build test'
186271
go: $TRAVIS_GO_VERSION
187272
stage: test
188273
- os: osx
189274
before_install: .ci/scripts/travis_has_changes.sh x-pack/elastic-agent libbeat || travis_terminate 0
190-
env: TARGETS="TEST_ENVIRONMENT=0 -C x-pack/elastic-agent testsuite"
275+
env:
276+
- PROJECT=x-pack/elastic-agent
277+
- MAGE='build unitTest'
191278
go: $TRAVIS_GO_VERSION
192279
stage: test
193280

194281
# Generators
195282
- os: linux
283+
before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0
196284
env: TARGETS="-C generator/_templates/metricbeat test test-package"
197285
go: $TRAVIS_GO_VERSION
198286
stage: test
199287
- os: linux
288+
before_install: .ci/scripts/travis_has_changes.sh generator libbeat || travis_terminate 0
200289
env: TARGETS="-C generator/_templates/beat test test-package"
201290
go: $TRAVIS_GO_VERSION
202291
stage: test
203292

204293
- os: osx
294+
before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0
205295
env: TARGETS="-C generator/_templates/metricbeat test"
206296
go: $TRAVIS_GO_VERSION
207297
stage: test
208298
- os: osx
299+
before_install: .ci/scripts/travis_has_changes.sh generator libbeat || travis_terminate 0
209300
env: TARGETS="-C generator/_templates/beat test"
210301
go: $TRAVIS_GO_VERSION
211302
stage: test
212303

213304
# Kubernetes
214305
- os: linux
306+
before_install: .ci/scripts/travis_has_changes.sh deploy/kubernetes metricbeat filebeat libbeat || travis_terminate 0
215307
install: deploy/kubernetes/.travis/setup.sh
216308
env:
217309
- TARGETS="-C deploy/kubernetes test"
218310
- TRAVIS_K8S_VERSION=v1.9.4
219311
stage: test
220312
- os: linux
313+
before_install: .ci/scripts/travis_has_changes.sh deploy/kubernetes metricbeat filebeat libbeat || travis_terminate 0
221314
install: deploy/kubernetes/.travis/setup.sh
222315
env:
223316
- TARGETS="-C deploy/kubernetes test"
224317
- TRAVIS_K8S_VERSION=v1.10.0
225318
stage: test
226319
- os: linux
320+
before_install: .ci/scripts/travis_has_changes.sh deploy/kubernetes metricbeat filebeat libbeat || travis_terminate 0
227321
dist: xenial
228322
install: deploy/kubernetes/.travis/setup.sh
229323
env:
@@ -267,7 +361,12 @@ addons:
267361
- python3.6
268362
- python3.6-venv
269363

270-
before_install:
364+
365+
366+
# Skips installations step
367+
install: true
368+
369+
before_script:
271370
- if [ x$TRAVIS_DIST = xtrusty ]; then sudo ln -sf python3.6 /usr/bin/python3; fi
272371
- python --version
273372
- python3 --version
@@ -279,17 +378,21 @@ before_install:
279378
- chmod +x docker-compose
280379
- sudo mv docker-compose /usr/local/bin
281380
- if [ $TRAVIS_OS_NAME = osx ]; then pip install virtualenv==16.7.9; fi
282-
283-
284-
# Skips installations step
285-
install: true
381+
- make mage
286382

287383
script:
288384
# Replacement for travis_wait which doesn't print output in real time.
289385
# Default Travis timeout is 10min, so this workaround prints timestamps every 9min to reset the counter.
290386
# Using seconds (540s = 9min) instead of minutes for shell compatibility reasons.
291387
- while sleep 540; do echo "=====[ ${SECONDS} seconds still running ]====="; done &
292-
- make $TARGETS
388+
- if [[ -n "$MAGE" ]]; then
389+
echo ">> mage $MAGE from $PROJECT";
390+
cd "$PROJECT";
391+
mage $MAGE;
392+
else
393+
echo ">> make $TARGETS";
394+
make $TARGETS;
395+
fi
293396
- kill %1
294397

295398
notifications:

0 commit comments

Comments
 (0)