Skip to content

Commit

Permalink
Cherry-pick to 7.x: ci: improve linting speed (#22103) (#22221)
Browse files Browse the repository at this point in the history
* ci: improve linting speed (#22103)

* ci: improve linting speed

* fix: use multiple agents for the matrix

* fix: add python-env

* fix: set make folder parameter

* feat: move k8s check and dev-tools to their own stages

* fix: lint in a single stage is faster

* fix: suggested changes

* chore:change triggers

* chore: update for packetbeat
# Conflicts:
#	x-pack/packetbeat/Jenkinsfile.yml

* Apply suggestions from code review

Co-authored-by: cachedout <mike.place@elastic.co>

Co-authored-by: cachedout <mike.place@elastic.co>
  • Loading branch information
kuisathaverat and cachedout authored Nov 3, 2020
1 parent 75662cc commit 49ae5e9
Show file tree
Hide file tree
Showing 22 changed files with 161 additions and 9 deletions.
8 changes: 5 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ pipeline {
GOFLAGS = '-mod=readonly'
}
steps {
withGithubNotify(context: 'Lint') {
withBeatsEnv(archive: false, id: 'lint') {
withGithubNotify(context: "Lint") {
withBeatsEnv(archive: false, id: "lint") {
dumpVariables()
cmd(label: 'make check', script: 'make check')
cmd(label: "make check-python", script: "make check-python")
cmd(label: "make check-go", script: "make check-go")
cmd(label: "Check for changes", script: "make check-no-changes")
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ projects:
- "x-pack/libbeat"
- "x-pack/metricbeat"
- "x-pack/winlogbeat"
- "dev-tools"
##- "x-pack/heartbeat" It's not yet in the 1.0 pipeline.
##- "x-pack/journalbeat" It's not yet in the 1.0 pipeline.
##- "x-pack/packetbeat" It's not yet in the 1.0 pipeline.
Expand Down Expand Up @@ -45,4 +46,4 @@ disabled:
labels: ## Skip the GitHub Pull Request builds if any of the given GitHub labels match with the assigned labels in the PR.
- skip-ci
## TODO: This will allow to configure what to do based on the PR configuration
draft: true ## Skip the GitHub Pull Request builds with Draft PRs.
draft: true ## Skip the GitHub Pull Request builds with Draft PRs.
25 changes: 20 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,35 @@ clean: mage

## check : TBD.
.PHONY: check
check: python-env
check:
@$(foreach var,$(PROJECTS) dev-tools $(PROJECTS_XPACK_MAGE),$(MAKE) -C $(var) check || exit 1;)
@$(FIND) -name *.py -name *.py -not -path "*/build/*" -exec $(PYTHON_ENV)/bin/autopep8 -d --max-line-length 120 {} \; | (! grep . -q) || (echo "Code differs from autopep8's style" && false)
@$(FIND) -name *.py -not -path "*/build/*" | xargs $(PYTHON_ENV)/bin/pylint --py3k -E || (echo "Code is not compatible with Python 3" && false)
$(MAKE) check-python
# check if vendor folder does not exists
[ ! -d vendor ]
@# Validate that all updates were committed
# Validate that all updates were committed
@$(MAKE) update
@$(MAKE) check-headers
go mod tidy
@$(MAKE) check-go
@$(MAKE) check-no-changes

## check-go : Check there is no changes in Go modules.
.PHONY: check-go
check-go:
@go mod tidy

## check-no-changes : Check there is no local changes.
.PHONY: check-no-changes
check-no-changes:
@git diff | cat
@git update-index --refresh
@git diff-index --exit-code HEAD --

## check-python : Python Linting.
.PHONY: check-python
check-python: python-env
@$(FIND) -name *.py -name *.py -not -path "*/build/*" -exec $(PYTHON_ENV)/bin/autopep8 -d --max-line-length 120 {} \; | (! grep . -q) || (echo "Code differs from autopep8's style" && false)
@$(FIND) -name *.py -not -path "*/build/*" | xargs $(PYTHON_ENV)/bin/pylint --py3k -E || (echo "Code is not compatible with Python 3" && false)

## check-headers : Check the license headers.
.PHONY: check-headers
check-headers: mage
Expand Down
5 changes: 5 additions & 0 deletions auditbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C auditbeat check;
make -C auditbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
3 changes: 3 additions & 0 deletions deploy/kubernetes/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ when:
branches: true ## for all the branches
changeset: ## when PR contains any of those entries in the changeset
- "^deploy/kubernetes/.*"
- "^libbeat/docs/version.asciidoc"
comments: ## when PR comment contains any of those entries
- "/test deploy/kubernetes"
labels: ## when PR labels matches any of those entries
Expand All @@ -11,5 +12,7 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
lint:
make: "make -C deploy/kubernetes all"
k8sTest:
k8sTest: "v1.18.2,v1.17.2,v1.16.4,v1.15.7,v1.14.10"
16 changes: 16 additions & 0 deletions dev-tools/Jenkinsfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
when:
branches: true ## for all the branches
changeset: ## when PR contains any of those entries in the changeset
- "^dev-tools/.*"
- "^libbeat/scripts/Makefile"
comments: ## when PR comment contains any of those entries
- "/test dev-tools"
labels: ## when PR labels matches any of those entries
- "dev-tools"
parameters: ## when parameter was selected in the UI.
- "dev-tools"
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
lint:
make: "make -C dev-tools check"
5 changes: 5 additions & 0 deletions filebeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C filebeat check;
make -C filebeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions heartbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C heartbeat check;
make -C heartbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions journalbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C journalbeat check;
make -C journalbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions libbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C libbeat check;
make -C libbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C metricbeat check;
make -C metricbeat update;
make check-no-changes;
unitTest:
mage: "mage build unitTest"
goIntegTest:
Expand Down
5 changes: 5 additions & 0 deletions packetbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C packetbeat check;
make -C packetbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions winlogbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C winlogbeat check;
make -C winlogbeat update;
make check-no-changes;
crosscompile:
make: "make -C winlogbeat crosscompile"
windows:
Expand Down
5 changes: 5 additions & 0 deletions x-pack/auditbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/auditbeat check;
make -C x-pack/auditbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions x-pack/dockerlogbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/dockerlogbeat check;
make -C x-pack/dockerlogbeat update;
make check-no-changes;
build:
mage: "mage build test"
withModule: true ## run the ITs only if the changeset affects a specific module.
5 changes: 5 additions & 0 deletions x-pack/elastic-agent/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/elastic-agent check;
make -C x-pack/elastic-agent update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions x-pack/filebeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/filebeat check;
make -C x-pack/filebeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions x-pack/functionbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/functionbeat check;
make -C x-pack/functionbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions x-pack/libbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/libbeat check;
make -C x-pack/libbeat update;
make check-no-changes;
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
Expand Down
5 changes: 5 additions & 0 deletions x-pack/metricbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/metricbeat check;
make -C x-pack/metricbeat update;
make check-no-changes;
build:
cloud: "mage build test"
withModule: true ## run the ITs only if the changeset affects a specific module.
Expand Down
33 changes: 33 additions & 0 deletions x-pack/packetbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,39 @@ when:
tags: true ## for all the tags
platform: "linux && ubuntu-18" ## default label for all the stages
stages:
Lint:
mage: |
mage check;
mage update;
make: "make check-no-changes"
arm:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
- "arm"
when: ## Override the top-level when.
comments:
- "/test x-pack/packetbeat for arm"
labels:
- "arm"
parameters:
- "armTest"
branches: true ## for all the branches
tags: true ## for all the tags
build:
mage: "mage build test"
macos:
mage: "mage build unitTest"
platforms: ## override default label in this specific stage.
- "macosx"
when: ## Override the top-level when.
comments:
- "/test x-pack/packetbeat for macos"
labels:
- "macOS"
parameters:
- "macosTest"
branches: true ## for all the branches
tags: true
windows:
mage: "mage build unitTest"
withModule: true
Expand Down
7 changes: 7 additions & 0 deletions x-pack/winlogbeat/Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ when:
tags: true ## for all the tags
platform: "windows-2019" ## default label for all the stages
stages:
Lint:
make: |
make -C x-pack/winlogbeat check;
make -C x-pack/winlogbeat update;
make check-no-changes;
platforms: ## override default labels in this specific stage.
- "linux && ubuntu-18"
build:
mage: "mage build unitTest"
withModule: true
Expand Down

0 comments on commit 49ae5e9

Please sign in to comment.